r80017 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80016‎ | r80017 | r80018 >
Date:16:29, 11 January 2011
Author:ariel
Status:deferred
Tags:
Comment:
enable separate config file for: monitor, monitor.py, worker, worker.py
Modified paths:
  • /branches/ariel/xmldumps-backup/WikiDump.py (modified) (history)
  • /branches/ariel/xmldumps-backup/monitor (modified) (history)
  • /branches/ariel/xmldumps-backup/monitor.py (modified) (history)
  • /branches/ariel/xmldumps-backup/worker (modified) (history)
  • /branches/ariel/xmldumps-backup/worker.py (modified) (history)

Diff [purge]

Index: branches/ariel/xmldumps-backup/worker.py
@@ -1959,7 +1959,9 @@
19601960 if message:
19611961 print message
19621962 print "Usage: python worker.py [options] [wikidbname]"
1963 - print "Options: --date, --checkpoint, --job, --force, --noprefetch, --nospawn"
 1963+ print "Options: --configfile, --date, --checkpoint, --job, --force, --noprefetch, --nospawn"
 1964+ print "--configfile: Specify an alternative configuration file to read."
 1965+ print " Default config file name: wikidump.conf"
19641966 print "--date: Rerun dump of a given date (probably unwise)"
19651967 print "--checkpoint: Run just the specified step (deprecated)"
19661968 print "--job: Run just the specified step or set of steps; for the list,"
@@ -1978,10 +1980,9 @@
19791981
19801982 if __name__ == "__main__":
19811983 try:
1982 - config = WikiDump.Config()
1983 -
19841984 date = None
19851985 checkpoint = None
 1986+ configFile = False
19861987 forceLock = False
19871988 prefetch = True
19881989 spawn = True
@@ -1989,7 +1990,7 @@
19901991
19911992 try:
19921993 (options, remainder) = getopt.gnu_getopt(sys.argv[1:], "",
1993 - ['date=', 'checkpoint=', 'job=', 'force', 'noprefetch', 'nospawn'])
 1994+ ['date=', 'checkpoint=', 'job=', 'configfile=', 'force', 'noprefetch', 'nospawn'])
19941995 except:
19951996 usage("Unknown option specified")
19961997
@@ -1998,6 +1999,8 @@
19992000 date = val
20002001 elif opt == "--checkpoint":
20012002 checkpoint = val
 2003+ elif opt == "--configfile":
 2004+ configFile = val
20022005 elif opt == "--force":
20032006 forceLock = True
20042007 elif opt == "--noprefetch":
@@ -2012,6 +2015,12 @@
20132016 if (jobRequested and forceLock):
20142017 usage("--force cannot be used with --job option")
20152018
 2019+ # allow alternate config file
 2020+ if (configFile):
 2021+ config = WikiDump.Config(configFile)
 2022+ else:
 2023+ config = WikiDump.Config()
 2024+
20162025 if len(remainder) > 0:
20172026 wiki = WikiDump.Wiki(config, remainder[0])
20182027 # if we are doing one piece only of the dump, we don't try to grab a lock.
Index: branches/ariel/xmldumps-backup/worker
@@ -2,8 +2,16 @@
33
44 WIKIDUMP_BASE=`dirname "$0"`
55
 6+if [ ! -z "$1" ]; then
 7+ configFile="$1"
 8+fi
 9+
610 while true; do
 11+ if [ ! -z "$configFile" ]; then
 12+ python $WIKIDUMP_BASE/worker.py "--configfile" "$configFile"
 13+ else
714 python $WIKIDUMP_BASE/worker.py
8 - echo "sleeping"
9 - sleep 30
 15+ fi
 16+ echo "sleeping"
 17+ sleep 30
1018 done
Index: branches/ariel/xmldumps-backup/monitor.py
@@ -1,9 +1,14 @@
22 # Wiki dump-generation monitor
33
44 import os
 5+import sys
56 import WikiDump
67
7 -config = WikiDump.Config()
 8+# can specify name of alternate config file
 9+if (sys.argv[1]):
 10+ config = WikiDump.Config(sys.argv[1])
 11+else:
 12+ config = WikiDump.Config()
813
914 def generateIndex():
1015 running = False
Index: branches/ariel/xmldumps-backup/WikiDump.py
@@ -80,10 +80,12 @@
8181 return dbs
8282
8383 class Config(object):
84 - def __init__(self):
 84+ def __init__(self, configFile=False):
8585 home = os.path.dirname(sys.argv[0])
 86+ if (not configFile):
 87+ configFile = "wikidump.conf"
8688 files = [
87 - os.path.join(home, "wikidump.conf"),
 89+ os.path.join(home,configFile),
8890 "/etc/wikidump.conf",
8991 os.path.join(os.getenv("HOME"), ".wikidump.conf")]
9092 defaults = {
@@ -142,8 +144,17 @@
143145 conf = ConfigParser.SafeConfigParser(defaults)
144146 conf.read(files)
145147
146 - self.dbList = dbList(conf.get("wiki", "dblist"))
147 - self.skipDbList = dbList(conf.get("wiki", "skipdblist"))
 148+ try:
 149+ self.dbList = dbList(conf.get("wiki", "dblist"))
 150+ except ConfigParser.NoSectionError:
 151+ print "The mandatory configuration section 'wiki' was not defined."
 152+ print "Either the section was ommitted or none of the files in the list"
 153+ print "%s exists. Giving up." % files
 154+ raise
 155+ try:
 156+ self.skipDbList = dbList(conf.get("wiki", "skipdblist"))
 157+ except ConfigParser.NoSectionError:
 158+ self.skipDbList = []
148159 self.dbList = list(set(self.dbList) - set(self.skipDbList))
149160
150161 self.privateList = dbList(conf.get("wiki", "privatelist"))
Index: branches/ariel/xmldumps-backup/monitor
@@ -2,10 +2,16 @@
33
44 WIKIDUMP_BASE=`dirname "$0"`
55
 6+if [ ! -z "$1" ]; then
 7+ configFile="$1"
 8+else
 9+ configFile=""
 10+fi
 11+
612 while true; do
713 echo ""
814 echo "Sweeping!"
9 - python $WIKIDUMP_BASE/monitor.py
 15+ python $WIKIDUMP_BASE/monitor.py "$configFile"
1016 echo "sleeping"
1117 sleep 15
1218 done

Status & tagging log