ArielGlenn has uploaded a new change for review.
https://gerrit.wikimedia.org/r/243368
Change subject: pylint for monitor.py
......................................................................
pylint for monitor.py
camelcase, lines too long, indentation issues
Change-Id: I6200b074d8ff6289b2f2f279cbe4f8045956c34d
---
M xmldumps-backup/monitor.py
1 file changed, 73 insertions(+), 68 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/dumps
refs/changes/68/243368/1
diff --git a/xmldumps-backup/monitor.py b/xmldumps-backup/monitor.py
index 4fad301..c9333d5 100644
--- a/xmldumps-backup/monitor.py
+++ b/xmldumps-backup/monitor.py
@@ -5,80 +5,85 @@
from os.path import exists
from dumps.WikiDump import FileUtils, Wiki, Config
-def addToFilename(filename, infix):
- main, suffix = filename.split('.',1)
- return main + "-" + infix + ("." + suffix if suffix else "")
+def add_to_filename(filename, infix):
+ base, suffix = filename.split('.', 1)
+ return base + "-" + infix + ("." + suffix if suffix else "")
-def generateIndex(otherIndexhtml = None, sortedByDb=False, showlocks=True):
- running = False
- states = []
-
- if sortedByDb:
- dbs = sorted(config.dbList)
+def generate_index(config, other_indexhtml=None, sorted_by_db=False,
showlocks=True):
+ running = False
+ states = []
+
+ if sorted_by_db:
+ dbs = sorted(config.dbList)
+ else:
+ dbs = config.dbListByAge()
+
+ for db_name in dbs:
+ wiki = Wiki(config, db_name)
+ if wiki.isStale():
+ print db_name + " is stale"
+ wiki.cleanupStaleLock()
+ if showlocks:
+ if wiki.isLocked():
+ try:
+ filehdl = open(wiki.lockFile(), 'r')
+ (host, pid) = filehdl.readline().split(" ")
+ filehdl.close()
+ print db_name, "is locked by pid", pid, "on", host
+ except:
+ print db_name, "is locked"
+ running = running or wiki.isLocked()
+ states.append(wiki.statusLine())
+
+ if running:
+ status = "Dumps are in progress..."
+ elif exists("maintenance.txt"):
+ status = FileUtils.readFile("maintenance.txt")
+ else:
+ status = "Dump process is idle."
+
+ if other_indexhtml is None:
+ other_index_link = ""
+ else:
+ if sorted_by_db:
+ other_sortedby = "dump date"
else:
- dbs = config.dbListByAge()
+ other_sortedby = "wiki name"
- for dbName in dbs:
- wiki = Wiki(config, dbName)
- if wiki.isStale():
- print dbName + " is stale"
- wiki.cleanupStaleLock()
- if showlocks:
- if wiki.isLocked():
- try:
- f = open( wiki.lockFile(), 'r' )
- (host, pid) = f.readline().split(" ")
- f.close()
- print dbName, "is locked by pid", pid, "on", host
- except:
- print dbName, "is locked"
- running = running or wiki.isLocked()
- states.append(wiki.statusLine())
-
- if running:
- status = "Dumps are in progress..."
- elif exists("maintenance.txt"):
- status = FileUtils.readFile("maintenance.txt")
- else:
- status = "Dump process is idle."
-
- if otherIndexhtml is None:
- otherIndexLink = ""
- else:
- if sortedByDb:
- otherSortedBy = "dump date"
- else:
- otherSortedBy = "wiki name"
+ other_index_link = ('Also view sorted by <a href="%s">%s</a>'
+ % (os.path.basename(other_indexhtml),
other_sortedby))
- otherIndexLink = ('Also view sorted by <a href="%s">%s</a>'
- % (os.path.basename(otherIndexhtml),
otherSortedBy))
+ return config.readTemplate("download-index.html") % {
+ "otherIndexLink": other_index_link,
+ "status": status,
+ "items": "\n".join(states)}
- return config.readTemplate("download-index.html") % {
- "otherIndexLink": otherIndexLink,
- "status": status,
- "items": "\n".join(states)}
-
-def updateIndex():
- outputFileName = os.path.join(config.publicDir, config.index)
- outputFileNameSortedByDb = addToFilename(os.path.join(config.publicDir,
config.index), "bydb")
+def update_index(config):
+ output_fname = os.path.join(config.publicDir, config.index)
+ output_fname_sorted_by_db = add_to_filename(os.path.join(
+ config.publicDir, config.index), "bydb")
- tempFilename = outputFileName + ".tmp"
- file = open(tempFilename, "wt")
- file.write(generateIndex(otherIndexhtml=outputFileNameSortedByDb))
- file.close()
- os.rename(tempFilename, outputFileName)
+ temp_fname = output_fname + ".tmp"
+ filehdl = open(temp_fname, "wt")
+ filehdl.write(generate_index(config,
other_indexhtml=output_fname_sorted_by_db))
+ filehdl.close()
+ os.rename(temp_fname, output_fname)
- tempFilename = outputFileNameSortedByDb + ".tmp"
- file = open(tempFilename, "wt")
- file.write(generateIndex(otherIndexhtml=outputFileName,
sortedByDb=True, showlocks=False))
- file.close()
- os.rename(tempFilename, outputFileNameSortedByDb)
+ temp_fname = output_fname_sorted_by_db + ".tmp"
+ filehdl = open(temp_fname, "wt")
+ filehdl.write(generate_index(config, other_indexhtml=output_fname,
+ sorted_by_db=True, showlocks=False))
+ filehdl.close()
+ os.rename(temp_fname, output_fname_sorted_by_db)
+
+def main():
+ # can specify name of alternate config file
+ if len(sys.argv) >= 2:
+ config = Config(sys.argv[1])
+ else:
+ config = Config()
+ update_index(config)
+
if __name__ == "__main__":
- # can specify name of alternate config file
- if (len(sys.argv) >= 2):
- config = Config(sys.argv[1])
- else:
- config = Config()
-
- updateIndex()
+ main()
--
To view, visit https://gerrit.wikimedia.org/r/243368
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6200b074d8ff6289b2f2f279cbe4f8045956c34d
Gerrit-PatchSet: 1
Gerrit-Project: operations/dumps
Gerrit-Branch: ariel
Gerrit-Owner: ArielGlenn <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits