Ideas for creating processes

J

J

I'm working on a project and thought I'd ask for a suggestion on how
to proceed (I've got my own ideas, but I wanted to see if I was on the
right track)

For now, I've got this:

def main():
## get our list of directories to refresh
releases=sys.argv[1:]
if len(releases) < 1:
print "You need to provide at least one dir to update"
sys.exit()

## Lets figure out what there is to update
updateDirs = []
for rel in releases:
currentDir = os.path.join(homedir, rel)
for item in os.listdir(currentDir):
updateDirs += [os.path.join(homedir, rel, item)]

which returns a list of full pathnames to directories that need to be
updated (updates will be carried out by calling rsync or zsync
eventually)

The directory hierarchy looks like this:

/home/user/files
/home/user/files/version1
/home/user/files/version1/type1
/home/user/files/version1/type2
/home/user/files/version2
/home/user/files/version2/type1

and the list ends up looking like this:

['/home/user/files/version1/type1','/home/user/files/version1/type2','/home/user/files/version2/type1','/home/user/files/version2/type2']

the next thing I need to do is figure out how to update those.

the quick and dirty would be (as I'm imagining it at the moment):
for path in pathlist:
chdir into path
execute rsync or zsync

but that gets me moving into one dir, updating, then moving into another.

What I was wondering about though, is spawning off separate rsync
processes to run concurrently (each rsync will hit a different remote
dir for each local dir)

so I'm trying to figure out a good way to do this:

for path in pathlist:
kick off an individual rsync|zsync process to update path

wait for all child processes to end
exit program.

I've been looking at subprocess because at the moment, that's all I
really know...
But is there a better way of kicking off multiple simultaneous
processes so I can update all dirs at once instead of one at a time?

No, this isn't homework, it's something I'm working on to sync a
couple directories of ISO images to grab nightly builds
Yes, there are plenty of pre-made scripts out there, but I don't want
to even look at those because I figured this would be a good learning
experience, and I want to try to solve this as much on my own as I can
without just cut and pasting from someone elses program.

So, with that said, any ideas on the best way to proceed? I'm going
to start looking at ways to use subprocess to do this, or would there
be a better way (multi-threading maybe?)

Or am I even in the right ballpark?

Cheers
Jeff
 
M

Martin P. Hellwig

I'm working on a project and thought I'd ask for a suggestion on how
to proceed (I've got my own ideas, but I wanted to see if I was on the
right track)
<cut subprocess idea>
Well I can't speak with authority but I would go into similar lines,
especially since you want to call an external program in the end anyway.
Otherwise threading might have been an option.

Just make sure that all subprocesses are exited nicely before you are on
the end of your script ;-)
 
B

bobicanprogram

I'm working on a project and thought I'd ask for a suggestion on how
to proceed (I've got my own ideas, but I wanted to see if I was on the
right track)

For now, I've got this:

def main():
## get our list of directories to refresh
releases=sys.argv[1:]
if len(releases) < 1:
print "You need to provide at least one dir to update"
sys.exit()

## Lets figure out what there is to update
updateDirs = []
for rel in releases:
currentDir = os.path.join(homedir, rel)
for item in os.listdir(currentDir):
updateDirs += [os.path.join(homedir, rel, item)]

which returns a list of full pathnames to directories that need to be
updated (updates will be carried out by calling rsync or zsync
eventually)

The directory hierarchy looks like this:

/home/user/files
/home/user/files/version1
/home/user/files/version1/type1
/home/user/files/version1/type2
/home/user/files/version2
/home/user/files/version2/type1

and the list ends up looking like this:

['/home/user/files/version1/type1','/home/user/files/version1/type2','/home/user/files/version2/type1','/home/user/files/version2/type2']

the next thing I need to do is figure out how to update those.

the quick and dirty would be (as I'm imagining it at the moment):
for path in pathlist:
chdir into path
execute rsync or zsync

but that gets me moving into one dir, updating, then moving into another.

What I was wondering about though, is spawning off separate rsync
processes to run concurrently (each rsync will hit a different remote
dir for each local dir)

so I'm trying to figure out a good way to do this:

for path in pathlist:
kick off an individual rsync|zsync process to update path

wait for all child processes to end
exit program.

I've been looking at subprocess because at the moment, that's all I
really know...
But is there a better way of kicking off multiple simultaneous
processes so I can update all dirs at once instead of one at a time?

No, this isn't homework, it's something I'm working on to sync a
couple directories of ISO images to grab nightly builds
Yes, there are plenty of pre-made scripts out there, but I don't want
to even look at those because I figured this would be a good learning
experience, and I want to try to solve this as much on my own as I can
without just cut and pasting from someone elses program.

So, with that said, any ideas on the best way to proceed? I'm going
to start looking at ways to use subprocess to do this, or would there
be a better way (multi-threading maybe?)

Or am I even in the right ballpark?

Cheers
Jeff


You might be able to use the SIMPL toolkit for this one.
(http://www.icanprogram.com/06py/lesson1/lesson1.html)

You could wrap the rsync executable as a SIMPL receiver module and
then message to that from inside your Python script to kick it off and
synchronize actions.

bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top