r92230 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92229‎ | r92230 | r92231 >
Date:07:53, 15 July 2011
Author:ariel
Status:deferred
Tags:
Comment:
check for existence of various commands, exception if missing (thanks to reeve of irc for noticing the issue)
Modified paths:
  • /branches/ariel/xmldumps-backup/worker.py (modified) (history)

Diff [purge]

Index: branches/ariel/xmldumps-backup/worker.py
@@ -160,6 +160,8 @@
161161
162162 def defaultServer(self):
163163 # if this fails what do we do about it? Not a bleeping thing. *ugh* FIXME!!
 164+ if (not exists( self.config.php ) ):
 165+ raise BackupError("php command %s not found" % self.config.php);
164166 command = "%s -q %s/maintenance/getSlaveServer.php --wiki=%s --group=dump" % MiscUtils.shellEscape((
165167 self.config.php, self.config.wikiDir, self.dbName))
166168 return RunSimpleCommand.runAndReturn(command, self.errorCallback).strip()
@@ -169,6 +171,8 @@
170172
171173 def buildSqlCommand(self, query, pipeto = None):
172174 """Put together a command to execute an sql query to the server for this DB."""
 175+ if (not exists( self.config.mysql ) ):
 176+ raise BackupError("mysql command %s not found" % self.config.mysql);
173177 command = [ [ "/bin/echo", "%s" % query ],
174178 [ "%s" % self.config.mysql, "-h",
175179 "%s" % self.dbServer,
@@ -183,6 +187,8 @@
184188 def buildSqlDumpCommand(self, table, pipeto = None):
185189 """Put together a command to dump a table from the current DB with mysqldump
186190 and save to a gzipped sql file."""
 191+ if (not exists( self.config.mysqldump ) ):
 192+ raise BackupError("mysqldump command %s not found" % self.config.mysqldump);
187193 command = [ [ "%s" % self.config.mysqldump, "-h",
188194 "%s" % self.dbServer, "-u",
189195 "%s" % self.config.dbUser,
@@ -215,6 +221,8 @@
216222 def getDBTablePrefix(self):
217223 """Get the prefix for all tables for the specific wiki ($wgDBprefix)"""
218224 # FIXME later full path
 225+ if (not exists( self.config.php ) ):
 226+ raise BackupError("php command %s not found" % self.config.php);
219227 command = "echo 'print $wgDBprefix; ' | %s -q %s/maintenance/eval.php --wiki=%s" % MiscUtils.shellEscape((
220228 self.config.php, self.config.wikiDir, self.dbName))
221229 return RunSimpleCommand.runAndReturn(command, self.errorCallback).strip()
@@ -953,11 +961,15 @@
954962 # returns 0 on success, 1 on error
955963 def saveTable(self, table, outfile):
956964 """Dump a table from the current DB with mysqldump, save to a gzipped sql file."""
 965+ if (not exists( self.config.gzip ) ):
 966+ raise BackupError("gzip command %s not found" % self.config.gzip);
957967 commands = self.dbServerInfo.buildSqlDumpCommand(table, self.config.gzip)
958968 return self.saveCommand(commands, outfile)
959969
960970 def saveSql(self, query, outfile):
961971 """Pass some SQL commands to the server for this DB and save output to a gzipped file."""
 972+ if (not exists( self.config.gzip ) ):
 973+ raise BackupError("gzip command %s not found" % self.config.gzip);
962974 command = self.dbServerInfo.buildSqlCommand(query, self.config.gzip)
963975 return self.saveCommand(command, outfile)
964976
@@ -1354,8 +1366,14 @@
13551367 outputFilename = runner.dumpDir.publicPath(outputFileBasename)
13561368 chunkNum = 0
13571369 recombines = []
 1370+ if (not exists( runner.config.head ) ):
 1371+ raise BackupError("head command %s not found" % runner.config.head);
13581372 head = runner.config.head
 1373+ if (not exists( runner.config.tail ) ):
 1374+ raise BackupError("tail command %s not found" % runner.config.tail);
13591375 tail = runner.config.tail
 1376+ if (not exists( runner.config.grep ) ):
 1377+ raise BackupError("grep command %s not found" % runner.config.grep);
13601378 grep = runner.config.grep
13611379
13621380 # we assume the result is always going to be run in a subshell.
@@ -1486,6 +1504,8 @@
14871505 current = self.buildCurrentOutputFilename(runner, chunk)
14881506 articles = self.buildArticlesOutputFilename(runner, chunk)
14891507
 1508+ if (not exists( runner.config.php ) ):
 1509+ raise BackupError("php command %s not found" % runner.config.php);
14901510 command = [ "%s" % runner.config.php,
14911511 "-q", "%s/maintenance/dumpBackup.php" % runner.config.wikiDir,
14921512 "--wiki=%s" % runner.dbName,
@@ -1591,6 +1611,8 @@
15921612 if not len(inputFiles):
15931613 self.setStatus("failed")
15941614 raise BackupError("No input files for %s found" % self.name)
 1615+ if (not exists( runner.config.gzip ) ):
 1616+ raise BackupError("gzip command %s not found" % runner.config.gzip);
15951617 compressionCommand = runner.config.gzip
15961618 compressionCommand = "%s > " % runner.config.gzip
15971619 uncompressionCommand = [ "%s" % runner.config.gzip, "-dc" ]
@@ -1629,6 +1651,8 @@
16301652 def run(self, runner):
16311653 self.cleanupOldFiles(runner)
16321654 logging = self.buildOutputFilename(runner)
 1655+ if (not exists( runner.config.php ) ):
 1656+ raise BackupError("php command %s not found" % runner.config.php);
16331657 command = [ "%s" % runner.config.php,
16341658 "-q", "%s/maintenance/dumpBackup.php" % runner.config.wikiDir,
16351659 "--wiki=%s" % runner.dbName,
@@ -1676,6 +1700,8 @@
16771701 commands.append(series)
16781702 error = runner.runCommand(commands, callbackStderr=self.progressCallback, callbackStderrArg=runner)
16791703
 1704+ if (not exists( runner.config.checkforbz2footer ) ):
 1705+ raise BackupError("checkforbz2footer command %s not found" % runner.config.checkforbz2footer);
16801706 checkforbz2footer = "%s" % runner.config.checkforbz2footer
16811707 if exists(checkforbz2footer):
16821708 # check to see if any of the output files are truncated
@@ -1704,6 +1730,8 @@
17051731 def buildFilters(self, runner, chunk = 0):
17061732 """Construct the output filter options for dumpTextPass.php"""
17071733 xmlbz2 = self._path(runner, "bz2", chunk)
 1734+ if (not exists( runner.config.bzip2 ) ):
 1735+ raise BackupError("bzip2 command %s not found" % runner.config.bzip2);
17081736 if runner.config.bzip2[-6:] == "dbzip2":
17091737 bz2mode = "dbzip2"
17101738 else:
@@ -1748,6 +1776,8 @@
17491777 else:
17501778 spawn = None
17511779
 1780+ if (not exists( runner.config.php ) ):
 1781+ raise BackupError("php command %s not found" % runner.config.php);
17521782 dumpCommand = [ "%s" % runner.config.php,
17531783 "-q", "%s/maintenance/dumpTextPass.php" % runner.config.wikiDir,
17541784 "--wiki=%s" % runner.dbName,
@@ -1770,9 +1800,13 @@
17711801 return self._pageID[fileName]
17721802 pageID = None
17731803 pipeline = []
 1804+ if (not exists( runner.config.bzip2 ) ):
 1805+ raise BackupError("bzip2 command %s not found" % runner.config.bzip2);
17741806 uncompressionCommand = [ "%s" % runner.config.bzip2, "-dc", fileName ]
17751807 pipeline.append(uncompressionCommand)
17761808 # warning: we figure any header (<siteinfo>...</siteinfo>) is going to be less than 2000 lines!
 1809+ if (not exists( runner.config.head ) ):
 1810+ raise BackupError("head command %s not found" % runner.config.head);
17771811 head = runner.config.head
17781812 headEsc = MiscUtils.shellEscape(head)
17791813 pipeline.append([ head, "-2000"])
@@ -2006,6 +2040,8 @@
20072041 if not len(inputFiles):
20082042 self.setStatus("failed")
20092043 raise BackupError("No input files for %s found" % self.name)
 2044+ if (not exists( runner.config.bzip2 ) ):
 2045+ raise BackupError("bzip2 command %s not found" % runner.config.bzip2);
20102046 compressionCommand = runner.config.bzip2
20112047 compressionCommand = "%s > " % runner.config.bzip2
20122048 uncompressionCommand = [ "%s" % runner.config.bzip2, "-dc" ]
@@ -2068,6 +2104,10 @@
20692105 xml7z = self.buildOutputFilename(runner, chunk)
20702106
20712107 # FIXME need shell escape
 2108+ if (not exists( runner.config.bzip2 ) ):
 2109+ raise BackupError("bzip2 command %s not found" % runner.config.bzip2);
 2110+ if (not exists( runner.config.sevenzip ) ):
 2111+ raise BackupError("7zip command %s not found" % runner.config.sevenzip);
20722112 commandPipe = [ [ "%s -dc %s | %s a -si %s" % (runner.config.bzip2, xmlbz2, runner.config.sevenzip, xml7z) ] ]
20732113 commandSeries = [ commandPipe ]
20742114 return(commandSeries)
@@ -2153,6 +2193,8 @@
21542194 if not len(inputFiles):
21552195 self.setStatus("failed")
21562196 raise BackupError("No input files for %s found" % self.name)
 2197+ if (not exists( runner.config.sevenzip ) ):
 2198+ raise BackupError("sevenzip command %s not found" % runner.config.sevenzip);
21572199 compressionCommand = "%s a -si" % runner.config.sevenzip
21582200 uncompressionCommand = [ "%s" % runner.config.sevenzip, "e", "-so" ]
21592201
@@ -2174,6 +2216,8 @@
21752217 self._chunks = chunks
21762218
21772219 def buildCommand(self, runner, chunk = 0):
 2220+ if (not exists( runner.config.php ) ):
 2221+ raise BackupError("php command %s not found" % runner.config.php);
21782222 command = [ "%s" % runner.config.php,
21792223 "-q", "%s/maintenance/dumpBackup.php" % runner.config.wikiDir,
21802224 "--wiki=%s" % runner.dbName,
@@ -2276,6 +2320,8 @@
22772321 if not len(inputFiles):
22782322 self.setStatus("failed")
22792323 raise BackupError("No input files for %s found" % self.name)
 2324+ if (not exists( runner.config.cat ) ):
 2325+ raise BackupError("cat command %s not found" % runner.config.cat);
22802326 compressionCommand = "%s > " % runner.config.cat
22812327 uncompressionCommand = [ "%s" % runner.config.cat ]
22822328 recombineCommandString = self.buildRecombineCommandString(runner, inputFiles, outputFile, compressionCommand, uncompressionCommand, "<feed>" )

Status & tagging log