Re: Re: Executing a python script while it is running

2009-06-16 Thread hobesh

Hey Dave,

Thanks for the helpful responses.

Option 2 is what you get by default. Naturally it depends on what the  
application is using to launch the batch file, but the most common cases  
will launch a separate process.


The app ended up delaying starting the second batch file until it finished  
the first. I had the app trigger an infinite loop on completion, and sent  
two files through at the same time. The second file finished seconds after  
the first, but the batch file didn't trigger until I closed the first one.


For option 4, you could just have the batch file launch a script that  
moves the file locally into a standard place, then the all-day-long  
(background) script will actually do the slow move on any file it spots  
in the special directory. If you need more information, you could add  
also create a text file that identifies the other parameters to go with  
the file. In any case, the background script would poll the directory for  
work to do, do it, then check again. Any time the poll fails, just sleep  
for 30 seconds or so.


I just tried a simple test with this basic outline, and it seemed to work  
fine. I had the app write a batch file and throw that batch file into the  
special directory. The background script grabbed the batch files and ran  
them in order of time created.


Still not sure what the best option is. I'm not sure what will happen if I  
just let the app regulate itself, so I may go with option 4.


Thanks again!
-- 
http://mail.python.org/mailman/listinfo/python-list


automating python programs

2008-07-21 Thread Zach Hobesh
Hi,

I'm trying to figure out how to run a python program on a schedule, maybe
every half an hour...  Is this possible?

Thanks!

-Zach
--
http://mail.python.org/mailman/listinfo/python-list

Running python scripts in a VB program

2008-07-28 Thread Zach Hobesh
Does anyone have any clue on how to embed python scripts in a visual basic
windows app?

Additionally, does anybody else feel like Visual Basic is ridiculously
confusing?

Any help is appreciated.

Thanks,

-Zach
--
http://mail.python.org/mailman/listinfo/python-list

Shared script

2008-08-01 Thread Zach Hobesh
I wrote a script that several different people on different machines need to
run on a regular basis.  When I first wrote it, it was in crisis mode, I got
something out that was quick and dirty, very bare bones.  Recently I had
some more time, so I pushed most of the functions that the script uses into
a module, because I use those functions on a pretty regular basis.

My problem is this:

The module is on MY machine in MY Python25 folder.  I like it there, because
like I said, I use the functions within it on a pretty regular basis.
However, the other people who need to run the original script don't have the
module.  My quick fix was to throw the module into the shared folder, which
works, but means everytime I have to update the module I have to update 2
different files, the one in my Python25 folder and the one in the shared
network folder.  Is there a better way to do this, short of asking everybody
else to put the module in thir Python 25 folder (which would mean me
e-mailing them to update the module, and then assuming that they did) ?!?

Thanks,

Zach
--
http://mail.python.org/mailman/listinfo/python-list

Executing a python script while it is running

2009-06-16 Thread Zach Hobesh
Hi everybody,

Here's my situation:

I have a batch file that calls a python script.

This batch file is triggered by an outside application when the
application completes a task.  The problem is that while the batch
file (and pythons script) is running, the application will complete
the next task, and try to call the batch file again (while it is
already running)

Hopefully that's not too confusing.

I'm not sure what direction to go with this, any help or nudges in the
RIGHT direction would be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing a python script while it is running

2009-06-16 Thread Zach Hobesh
> A lot more information would be useful.  What version of Python, and what
> operating system environment?  Exactly what would you like to happen when
> the batch file is invoked a second time?

I'm running Python 2.6.2 on Windows.  I'm passing filenames to the
batch files and I need all filenames to be processed.  I can't have
any fails.  I'm working on logging any fails I do have so that I can
maybe batch process at the end of the day.

>  2) let them both run as separate processes

This sounds like a good option, but I'm not totally sure on how to go
about this?

>  4) queue something to be processed when the first run finishes

I had the same idea, but I believe it would involve having another
python script run all day long, which wouldn't necessarily be a bad
thing, but I'd like to explore other options as well.

> What provisions does this existing application have for long-running batch
> files?  Seems the synchronization ought to happen there.  Do you have any
> constraints on how long your script might take, worst case?  What if the
> application finishes its tasks at a faster average rate than your script can
> process them?

The batch file is moving large video files.  Duration probably ranges
from 10 sec to 45 mins.  On average, the application takes longer to
process the files than it does the batch file/python script takes to
copy them, but I'm concerned about the occasional time that the
application finishes a small file right after finishing a large file.

Thanks for your response!

-Zach
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Executing a python script while it is running

2009-06-16 Thread Zach Hobesh
On Tue, Jun 16, 2009 at 6:37 PM, Chris Rebert wrote:
> On Tue, Jun 16, 2009 at 6:21 PM,  wrote:
>> Hey Dave,
>>
>> Thanks for the helpful responses.
>>
>>> Option 2 is what you get by default.  Naturally it depends on what the
>>> application  is using to launch the batch file, but the most common cases
>>> will launch a separate process.
>>
>> The app ended up delaying starting the second batch file until it finished
>> the first. I had the app trigger an infinite loop on completion, and sent
>> two files through at the same time. The second file finished seconds after
>> the first, but the batch file didn't trigger until I closed the first one.
>
> Are you sure you aren't unknowingly having the app wait on the first
> batch file process until it terminates? How exactly are you launching
> the batch files?
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com

Hey Chris,

I actually think that's what's happening, which is fine in my case
(for now anyway) as I just need them all to complete, we don't need
them running at the same time.  I'm using a job management system, and
they have the option of triggering a command line after completing a
job.

A better/safer solution might be spawning another job and re-inserting
to the jms queue.

Thanks again,

Zach
-- 
http://mail.python.org/mailman/listinfo/python-list


Config files with different types

2009-07-02 Thread Zach Hobesh
Hi all,

I've written a function that reads a specifically formatted text file
and spits out a dictionary.  Here's an example:

config.txt:

Destination = C:/Destination
Overwrite = True


Here's my function that takes 1 argument (text file)

the_file = open(textfile,'r')
linelist = the_file.read().split('\n')
the_file.close()
configs = {}
for line in linelist:
   try:
  key,value = line.split('=')
  key.strip()
  value.strip()
  key.lower()
  value.lower()
  configs[key] = value

   except ValueError:
  break

so I call this on my config file, and then I can refer back to any
config in my script like this:

shutil.move(your_file,configs['destination'])

which I like because it's very clear and readable.

So this works great for simple text config files.  Here's how I want
to improve it:

I want to be able to look at the value and determine what type it
SHOULD be.  Right now, configs['overwrite'] = 'true' (a string) when
it might be more useful as a boolean.  Is there a quick way to do
this?  I'd also like to able to read '1' as an in, '1.0' as a float,
etc...

I remember once I saw a script that took a string and tried int(),
float() wrapped in a try except, but I was wondering if there was a
more direct way.

Thanks in advance,

Zach
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Config files with different types

2009-07-03 Thread Zach Hobesh
yaml looks pretty interesting.  Also, I wouldn't have to change much,
I would still use the same function, and still output a dict.

Thanks!

-Zach

On Thu, Jul 2, 2009 at 11:55 PM, Javier Collado wrote:
> Hello,
>
> Have you considered using something that is already developed?
>
> You could take a look at this presentation for an overview of what's 
> available:
> http://us.pycon.org/2009/conference/schedule/event/5/
>
> Anyway, let me explain that, since I "discovered" it, my favourite
> format for configuration files is yaml (http://yaml.org/,
> http://pyyaml.org/). It's easy to read, easy to write, available in
> different programming languagues, etc. In addition to this, type
> conversion is already in place so I think it covers your requirement.
> For example:
>
> IIn [1]: import yaml
>
> In [2]: yaml.load("""name: person name
>   ...: age: 25
>   ...: is_programmer: true""")
> Out[2]: {'age': 25, 'is_programmer': True, 'name': 'person name'}
>
> Best regards,
>    Javier
>
> 2009/7/2 Zach Hobesh :
>> Hi all,
>>
>> I've written a function that reads a specifically formatted text file
>> and spits out a dictionary.  Here's an example:
>>
>> config.txt:
>>
>> Destination = C:/Destination
>> Overwrite = True
>>
>>
>> Here's my function that takes 1 argument (text file)
>>
>> the_file = open(textfile,'r')
>> linelist = the_file.read().split('\n')
>> the_file.close()
>> configs = {}
>> for line in linelist:
>>       try:
>>              key,value = line.split('=')
>>              key.strip()
>>              value.strip()
>>              key.lower()
>>              value.lower()
>>              configs[key] = value
>>
>>       except ValueError:
>>              break
>>
>> so I call this on my config file, and then I can refer back to any
>> config in my script like this:
>>
>> shutil.move(your_file,configs['destination'])
>>
>> which I like because it's very clear and readable.
>>
>> So this works great for simple text config files.  Here's how I want
>> to improve it:
>>
>> I want to be able to look at the value and determine what type it
>> SHOULD be.  Right now, configs['overwrite'] = 'true' (a string) when
>> it might be more useful as a boolean.  Is there a quick way to do
>> this?  I'd also like to able to read '1' as an in, '1.0' as a float,
>> etc...
>>
>> I remember once I saw a script that took a string and tried int(),
>> float() wrapped in a try except, but I was wondering if there was a
>> more direct way.
>>
>> Thanks in advance,
>>
>> Zach
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Mimicing an HTML form

2009-08-12 Thread Zach Hobesh
Hi all,
I'm having alot of trouble automating the submitting of form.  I have an
HTML page that works and it looks like this:









When I put valid values for the handling script an app ID, this page works.
 Now I'm trying to turn this same functionality into a script.  Here's my
code:

import urllib
import os
import urllib2

appID = *value here*
video = os.path.normpath(os.getcwd() + '/news.wmv')
title = 'News'
desc = 'Here is a sample News video'

uploader = *script here*

print "Encoding url..."
data = urllib.urlencode({"FileUploadedVideo": video,
 "hdnADCID" : appID,
 "txtTitle" : title,
 "txtDescription": desc})

user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }


print "Calling url..."
req = urllib2.Request(uploader, data, headers)

response = urllib2.urlopen(req)
s = response.read()
response.close()

print "Writing results..."
result = open('result.html','w')
result.write(s)
result.close()

Does anybody have any suggestions?  I keep on getting bad request, so I'm
assuming that the html page is passing something that my script is not.  Is
there some way to scrape the POST request from the html form?

Thanks,

Zach
-- 
http://mail.python.org/mailman/listinfo/python-list