jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Category: Only dump cache if loaded ......................................................................
[FIX] Category: Only dump cache if loaded
This also removes the 'loaded' variable as it's basically defined if both the attributes are present. This also set the content to 'loaded' after loading the file.
Change-Id: I788166b45f5644a23d6d3dad858f8d32b6e16e38 --- M scripts/category.py 1 file changed, 7 insertions(+), 4 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py index 68dfc9d..246d637 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -141,12 +141,16 @@ if not os.path.isabs(filename): filename = config.datafilepath(filename) self.filename = filename - self.loaded = False if rebuild: self.rebuild()
+ @property + def is_loaded(self): + """Return whether the contents have been loaded.""" + return hasattr(self, 'catContentDB') and hasattr(self, 'superclassDB') + def _load(self): - if not self.loaded: + if not self.is_loaded(): try: f = bz2.BZ2File(self.filename, 'r') pywikibot.output(u'Reading dump from %s' @@ -166,7 +170,6 @@ def rebuild(self): self.catContentDB = {} self.superclassDB = {} - self.loaded = True
def getSubcats(self, supercat): """Return the list of subcategories for a given supercategory. @@ -226,7 +229,7 @@ filename = self.filename elif not os.path.isabs(filename): filename = config.datafilepath(filename) - if self.catContentDB or self.superclassDB: + if self.is_loaded and (self.catContentDB or self.superclassDB): pywikibot.output(u'Dumping to %s, please wait...' % config.shortpath(filename)) f = bz2.BZ2File(filename, 'w')