jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/458527 )
Change subject: [doc] Enable documentation generated for makecat.py script ......................................................................
[doc] Enable documentation generated for makecat.py script
- put all global settings into main and use global variables for access - rename global variable "main" to "main_ns" - use pywikibot.handle_args(args) before handling local options
Bug: T203675 Change-Id: I23f3bfb8cd0c8c7fbb027e38ab99d6f037ff7c14 --- M scripts/makecat.py 1 file changed, 45 insertions(+), 15 deletions(-)
Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/makecat.py b/scripts/makecat.py index fd73b7c..82f8b5e 100755 --- a/scripts/makecat.py +++ b/scripts/makecat.py @@ -58,10 +58,11 @@
"""Bot tries to find new articles for a given category."""
- @classmethod - def needcheck(cls, pl): + @staticmethod + def needcheck(pl): """Verify whether the current page may be processed.""" - if main: + global main_ns, checked, skipdates + if main_ns: if pl.namespace() != 0: return False if pl in checked: @@ -79,6 +80,10 @@ def include(cls, pl, checklinks=True, realinclude=True, linkterm=None, summary=''): """Include the current page to the working category.""" + global mysite + global workingcat, parentcats, removeparent + global checkforward, checkbackward + global checked, tocheck cl = checklinks if linkterm: actualworkingcat = pywikibot.Category(mysite, workingcat.title(), @@ -125,6 +130,9 @@ @classmethod def asktoadd(cls, pl, summary): """Work on current page and ask to add article to category.""" + global mysite + global checked, tocheck + global excludefile if pl.site != mysite: return if pl.isRedirectPage(): @@ -201,17 +209,35 @@ pywikibot.output('Not understood.')
-try: - checked = {} +def main(*args): + """ + Process command line arguments and invoke bot. + + If args is an empty list, sys.argv is used. + + @param args: command line arguments + @type args: list of unicode + """ + global main_ns, skipdates + global mysite + global workingcat, parentcats, removeparent + global checkforward, checkbackward + global checked, tocheck + global excludefile + + main_ns = True skipdates = False + removeparent = True checkforward = True checkbackward = True - checkbroken = True - removeparent = True - main = True - workingcatname = '' + checked = {} tocheck = DequeGenerator() - for arg in pywikibot.handle_args(): + + checkbroken = True + workingcatname = '' + + local_args = pywikibot.handle_args(args) + for arg in local_args: if arg.startswith('-nodate'): skipdates = True elif arg.startswith('-forward'): @@ -222,7 +248,7 @@ elif arg.startswith('-keepparent'): removeparent = False elif arg.startswith('-all'): - main = False + main_ns = False elif not workingcatname: workingcatname = arg
@@ -296,8 +322,12 @@ if checkbroken or page.exists(): MakeCatBot.asktoadd(page, summary)
-finally: + +if __name__ == '__main__': try: - excludefile.close() - except Exception: - pass + main() + finally: + try: + excludefile.close() + except Exception: + pass
pywikibot-commits@lists.wikimedia.org