Filippo Giunchedi has uploaded a new change for review. https://gerrit.wikimedia.org/r/254144
Change subject: swiftrepl: add main() ...................................................................... swiftrepl: add main() move main code into its own function, this allows for example swiftrepl to be installed as a command line script. Also move globals at the top of the file and remove unneeded 'global' (NOBJECT is never written to) Change-Id: I66a04cef126fec3919fdbd1468c0c750ce2b9ef9 --- M swiftrepl/swiftrepl.py 1 file changed, 18 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/software refs/changes/44/254144/1 diff --git a/swiftrepl/swiftrepl.py b/swiftrepl/swiftrepl.py index bde35d8..bed573e 100644 --- a/swiftrepl/swiftrepl.py +++ b/swiftrepl/swiftrepl.py @@ -24,10 +24,13 @@ copy_headers = re.compile(r'^X-Content-Duration$', flags=re.IGNORECASE) -NOBJECT=1000 +NOBJECT = 1000 +PER_PAGE = 10000 src = {} dst = {} +options = None +containers = [] class WorkingConnectionPool(cloudfiles.connection.ConnectionPool): def __init__(self, username=None, api_key=None, **kwargs): @@ -164,8 +167,6 @@ dstobj._etag = hdr[1] def replicate_object(srcobj, dstobj, srcconnpool, dstconnpool): - global use_varnish - # Replace the connections srcobj.container.conn = srcconnpool.get() dstobj.container.conn = dstconnpool.get() @@ -236,6 +237,10 @@ pct = lambda x, y: y != 0 and int(float(x) / y * 100) or 0 print ("VARNISH: %d/%d (%d%%)" % (self.hits, self.count, pct(self.hits, self.count))) +# FIXME initialize +replicate_object.count = 0 +replicate_object.hits = 0 + def get_container_objects(container, limit, marker, connpool): @@ -281,7 +286,6 @@ print "Created container", name def sync_container(srccontainer, srcconnpool, dstconnpool): - global NOBJECT last = '' hits, processed, gets = 0, 0, 0 @@ -298,6 +302,7 @@ dstconn = None dstobjects = None + limit = PER_PAGE while True: srcobjects = get_container_objects(srccontainer, limit=NOBJECT, marker=last, connpool=srcconnpool) @@ -354,7 +359,6 @@ print "FINISHED:", srccontainer.name def sync_deletes_slow(srccontainer, srcconnpool, dstconnpool): - global NOBJECT dstconn = dstconnpool.get() try: @@ -405,7 +409,6 @@ srccontainer.conn = None def sync_deletes(srccontainer, srcconnpool, dstconnpool): - global NOBJECT dstconn = dstconnpool.get() try: @@ -503,9 +506,8 @@ return src, dst -if __name__ == '__main__': - replicate_object.count = 0 - replicate_object.hits = 0 +def main(): + global options, containers, src, dst parser = argparse.ArgumentParser() parser.add_argument('--config', dest='config', default='swiftrepl.conf') @@ -524,16 +526,14 @@ srcconn = srcconnpool.get() - containers=[] - limit=10000 - last='' + last = '' while True: - page = srcconn.get_all_containers(limit=limit, marker=last) + page = srcconn.get_all_containers(limit=PER_PAGE, marker=last) if len(page) == 0: break last = page[-1].name.encode("utf-8") containers.extend(page) - if len(page) < limit: + if len(page) < PER_PAGE: break containerlist = [container for container in containers @@ -554,3 +554,7 @@ if thread is threading.currentThread(): continue thread.join() + + +if __name__ == '__main__': + sys.exit(main()) -- To view, visit https://gerrit.wikimedia.org/r/254144 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I66a04cef126fec3919fdbd1468c0c750ce2b9ef9 Gerrit-PatchSet: 1 Gerrit-Project: operations/software Gerrit-Branch: master Gerrit-Owner: Filippo Giunchedi <fgiunch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits