Sunday, April 01, 2007

A file monitor

Well, lo and behold, it turns out I've implemented a very simple version of App #3, the file monitor. It's not very flexible -- if invoked from the command line with a source directory and a target directory, it will monitor the source directory and move anything and everything added to that directory into the target directory. It does no error checking. And it's too stupid to find the Desktop to monitor.

But it's a file monitor, and in the next couple of days I'll post a more complete version. The monitor thus far is just this:

<ui>
<frame id="main" title="File monitor 1">
<args id="main">
<arg field="source" default="."/>
<arg field="target" default=""/>
</args>
<html field="html"/>
<timer field="timer" state="off" interval="1000" cmd="look"/>
</frame>

<action id="initialize" lang="python">
if not [context]['target']:
: notify "You need to specify a target directory."
: exit

[context].list = set(os.listdir( [context]['source']))
[context]['timer'] = 'on'
</action>

<action id="look" lang="python">
oldlist = [context].list
[context].list = set(os.listdir ( [context]['source']))

for f in [context].list:
if not f in oldlist:
shutil.move (f, [context]['target'])
</action>
</ui>
To run this bad boy, you'll need the latest Pypop from SourceForge (v0.2) -- if you're still running 0.1, you'll run into some bugs I just fixed, and as I haven't done very good error handling, things will just fail silently and you won't know why. Eventually I need to put some error handling into that beast.

Anyway, this is just a taste. I've also written up a nice tutorial on Pypop which goes over some of the design considerations in the apps so far, but it's not uploaded yet (I still have to write some formatting scripts to turn it into proper HTML.) When I do that, I'll post here again, and hopefully sunny Ponce will keep me happy and productive.

0 Comments:

Post a Comment

<< Home