From 7162f6854f7a39f6fde2dde28109ba4b230e521e Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 2 May 2007 02:01:59 +0000 Subject: [PATCH] Give the Python client the ability to download whole sets of campaigns... ...selected by a regular-expression name argument. --- utils/python/campaign_client.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/utils/python/campaign_client.py b/utils/python/campaign_client.py index 3744a021f1d..4d055451ae5 100755 --- a/utils/python/campaign_client.py +++ b/utils/python/campaign_client.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # encoding: utf8 -import socket, struct, sys, wmldata, glob, os.path, shutil, threading +import socket, struct, sys, wmldata, glob, os.path, shutil, threading, re # First port listed will bw used as default. portmap = (("15003", "1.3.x"), ("15004", "1.2.x")) @@ -396,7 +396,8 @@ if __name__ == "__main__": optionparser.add_option("-P", "--password", help = "password to use") optionparser.add_option("-d", "--download", - help = "download the named campaign " + + help = "download the named campaign; " + + "name may be a Python regexp matched against all campaign names " + "(specify the path where to put it with -c, " + "current directory will be used by default)") optionparser.add_option("-u", "--upload", @@ -451,16 +452,28 @@ if __name__ == "__main__": sys.stderr.write("Could not connect.\n") elif options.download: cs = CampaignServer(address) - mythread = cs.get_campaign_async(options.download) + if re.escape(options.download).replace("\\_", "_") == options.download: + fetchlist = [options.download] + else: + fetchlist = [] + data = cs.list_campaigns() + if data: + campaigns = data.get_or_create_sub("campaigns") + for campaign in campaigns.get_all("campaign"): + name = campaign.get_text_val("name", "?") + if re.search(options.download, name): + fetchlist.append(name) + for name in fetchlist: + mythread = cs.get_campaign_async(name) - while not mythread.event.isSet(): - mythread.event.wait(1) - print "%d/%d" % (cs.counter, cs.length) + while not mythread.event.isSet(): + mythread.event.wait(1) + print "%s: %d/%d" % (name, cs.counter, cs.length) - print "Unpacking data.." - cs.unpackdir(mythread.data, options.campaigns_dir) - for message in mythread.data.find_all("message", "error"): - print message.get_text_val("message") + print "Unpacking %s..." % name + cs.unpackdir(mythread.data, options.campaigns_dir) + for message in mythread.data.find_all("message", "error"): + print message.get_text_val("message") elif options.remove: cs = CampaignServer(address) data = cs.delete_campaign(options.remove, options.password)