ArielGlenn has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/306228

Change subject: convert options and flags into dict for easier handling
......................................................................

convert options and flags into dict for easier handling

Change-Id: Iddf27b04a3e293345a1bd8b829c6a19955e70dd6
---
M xmldumps-backup/dumpscheduler.py
1 file changed, 31 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/dumps 
refs/changes/28/306228/1

diff --git a/xmldumps-backup/dumpscheduler.py b/xmldumps-backup/dumpscheduler.py
index c2cda43..6e21af5 100644
--- a/xmldumps-backup/dumpscheduler.py
+++ b/xmldumps-backup/dumpscheduler.py
@@ -662,18 +662,30 @@
     sys.exit(1)
 
 
+def get_defaults():
+    '''
+    set up and return defaults for options
+    '''
+    opts = {}
+
+    opts['cache'] = "running_cache.txt"
+    opts['email_from'] = "root"
+
+    for flag in ['restore', 'rerun']:
+        opts[flag] = False
+
+    for option in ['slots', 'mailhost', 'formatvars']:
+        opts[option] = None
+
+    return opts
+
+
 def main():
     'main entry point, does all the work'
 
     command_file = None
-    cache = "running_cache.txt"
-    slots = None
+    opts = get_defaults()
     working_dir = None
-    mailhost = None
-    email_from = "root"
-    formatvars = None
-    restore = False
-    rerun = False
     verbose = False
     debug = False
 
@@ -690,25 +702,25 @@
         if opt in ["-c", "--commands"]:
             command_file = val
         elif opt in ["-C", "--cache"]:
-            cache = val
+            opts['cache'] = val
         elif opt in ["-d", "--directory"]:
             working_dir = val
         elif opt in ["-e", "--email"]:
-            email_from = val
+            opts['email_from'] = val
         elif opt in ["-s", "--slots"]:
             if not val.isdigit():
                 usage("slots option requires a number")
-            slots = int(val)
+            opts['slots'] = int(val)
         elif opt in ["-r", "--restore"]:
-            restore = True
+            opts['restore'] = True
         elif opt in ["-R", "--rerun"]:
-            rerun = True
+            opts['rerun'] = True
         elif opt in ["-f", "--formatvars"]:
-            formatvars = val
+            opts['formatvars'] = val
         elif opt in ["-v", "--verbose"]:
             verbose = True
         elif opt in ["-m", "--mailhost"]:
-            mailhost = val
+            opts['mailhost'] = val
         elif opt in ["-d", "--debug"]:
             debug = val
         elif opt in ["-h", "--help"]:
@@ -719,7 +731,7 @@
     if len(remainder) > 0:
         usage("Unknown option(s) specified: <%s>" % remainder[0])
 
-    if slots is None:
+    if opts['slots'] is None:
         usage("The mandatory slots option was not specified")
 
     if command_file is not None:
@@ -742,11 +754,11 @@
     my_id = scheduler_setup()
 
     plugables = {}
-    plugables['allocator'] = ResourceAllocator(slots)
-    plugables['cacher'] = Cacher(cache, my_id, restore, rerun)
+    plugables['allocator'] = ResourceAllocator(opts['slots'])
+    plugables['cacher'] = Cacher(opts['cache'], my_id, opts['restore'], 
opts['rerun'])
     plugables['checker'] = CommandChecker(my_id)
-    plugables['mailer'] = Mailer(mailhost, email_from)
-    scheduler = Scheduler(plugables, formatvars, my_id)
+    plugables['mailer'] = Mailer(opts['mailhost'], opts['email_from'])
+    scheduler = Scheduler(plugables, opts['formatvars'], my_id)
     scheduler.run(commands_in)
 
 

-- 
To view, visit https://gerrit.wikimedia.org/r/306228
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iddf27b04a3e293345a1bd8b829c6a19955e70dd6
Gerrit-PatchSet: 1
Gerrit-Project: operations/dumps
Gerrit-Branch: master
Gerrit-Owner: ArielGlenn <ar...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to