jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/437060 )
Change subject: Fix some of the N806 errors ......................................................................
Fix some of the N806 errors
Change-Id: Id4a37c79941aa721ba0e022cabaa812855c98010 --- M pywikibot/bot.py M pywikibot/data/wikistats.py M pywikibot/titletranslate.py M pywikibot/tools/_logging.py M scripts/basic.py M scripts/clean_sandbox.py M scripts/commons_link.py M scripts/cosmetic_changes.py M scripts/create_categories.py M scripts/delete.py M scripts/editarticle.py M scripts/image.py M scripts/imageharvest.py M scripts/imageuncat.py M scripts/interwikidata.py M scripts/listpages.py M scripts/lonelypages.py M scripts/ndashredir.py M scripts/pagefromfile.py M scripts/patrol.py M scripts/piper.py M scripts/protect.py M scripts/selflink.py M scripts/spamremove.py M scripts/states_redirect.py M scripts/surnames_redirects.py M scripts/templatecount.py M scripts/touch.py M scripts/transferbot.py M scripts/upload.py M tox.ini 31 files changed, 251 insertions(+), 287 deletions(-)
Approvals: Dvorapa: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py index af0792a..84f4073 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -139,6 +139,66 @@ ui = uiModule.UI() pywikibot.argvu = ui.argvu()
+_GLOBAL_HELP = ''' +GLOBAL OPTIONS +============== +(Global arguments available for all bots) + +-dir:PATH Read the bot's configuration data from directory given by + PATH, instead of from the default directory. + +-lang:xx Set the language of the wiki you want to work on, overriding + the configuration in user-config.py. xx should be the + language code. + +-family:xyz Set the family of the wiki you want to work on, e.g. + wikipedia, wiktionary, wikitravel, ... + This will override the configuration in user-config.py. + +-user:xyz Log in as user 'xyz' instead of the default username. + +-daemonize:xyz Immediately return control to the terminal and redirect + stdout and stderr to file xyz. + (only use for bots that require no input from stdin). + +-help Show this help text. + +-log Enable the log file, using the default filename + '%s-bot.log' + Logs will be stored in the logs subdirectory. + +-log:xyz Enable the log file, using 'xyz' as the filename. + +-nolog Disable the log file (if it is enabled by default). + +-maxlag Sets a new maxlag parameter to a number of seconds. Defer bot + edits during periods of database server lag. Default is set + by config.py + +-putthrottle:n Set the minimum time (in seconds) the bot will wait between +-pt:n saving pages. +-put_throttle:n + +-debug:item Enable the log file and include extensive debugging data +-debug for component "item" (for all components if the second form + is used). + +-verbose Have the bot provide additional console output that may be +-v useful in debugging. + +-cosmeticchanges Toggles the cosmetic_changes setting made in config.py or +-cc user-config.py to its inverse and overrules it. All other + settings and restrictions are untouched. + +-simulate Disables writing to the server. Useful for testing and + debugging of new code (if given, doesn't do any real + changes, but only shows what would have been changed). + +-<config var>:n You may use all given numeric config variables as option and + modify it with command line. + +''' +
# It's not possible to use pywikibot.exceptions.PageRelatedError as that is # importing pywikibot.data.api which then needs pywikibot.bot @@ -228,9 +288,9 @@ """ global _handlers_initialized
- moduleName = calledModuleName() - if not moduleName: - moduleName = "terminal-interface" + module_name = calledModuleName() + if not module_name: + module_name = 'terminal-interface'
logging.addLevelName(VERBOSE, "VERBOSE") # for messages to be displayed on terminal at "verbose" setting @@ -263,11 +323,11 @@ ui.init_handlers(root_logger, **config.userinterface_init_kwargs)
# if user has enabled file logging, configure file handler - if moduleName in config.log or '*' in config.log: + if module_name in config.log or '*' in config.log: if config.logfilename: logfile = config.datafilepath("logs", config.logfilename) else: - logfile = config.datafilepath("logs", "%s-bot.log" % moduleName) + logfile = config.datafilepath('logs', '%s-bot.log' % module_name) file_handler = RotatingFileHandler(filename=logfile, maxBytes=1024 * config.logfilesize, backupCount=config.logfilecount) @@ -856,10 +916,10 @@ # get the name of the module calling this function. This is # required because the -help option loads the module's docstring and # because the module name will be used for the filename of the log. - moduleName = calledModuleName() - if not moduleName: - moduleName = "terminal-interface" - nonGlobalArgs = [] + module_name = calledModuleName() + if not module_name: + module_name = 'terminal-interface' + non_global_args = [] username = None do_help = None if do_help else False for arg in args: @@ -877,8 +937,8 @@ elif option in ('-putthrottle', '-pt'): config.put_throttle = int(value) elif option == '-log': - if moduleName not in config.log: - config.log.append(moduleName) + if module_name not in config.log: + config.log.append(module_name) if value: config.logfilename = value elif option == '-nolog': @@ -915,8 +975,8 @@ # other settings. # elif option == '-debug': - if moduleName not in config.log: - config.log.append(moduleName) + if module_name not in config.log: + config.log.append(module_name) if value: if value not in config.debug_log: config.debug_log.append(value) @@ -938,7 +998,7 @@ setattr(config, _arg, int(value)) except (ValueError, TypeError, AttributeError): # argument not global -> specific bot script will take care - nonGlobalArgs.append(arg) + non_global_args.append(arg)
if username: config.usernames[config.family][config.mylang] = username @@ -954,7 +1014,7 @@ sys.exit(0)
debug('handle_args() completed.', _logger) - return nonGlobalArgs + return non_global_args
@deprecated("handle_args") @@ -973,79 +1033,21 @@ except NameError: module_name = "no_module"
- globalHelp = u''' -GLOBAL OPTIONS -============== -(Global arguments available for all bots) - --dir:PATH Read the bot's configuration data from directory given by - PATH, instead of from the default directory. - --lang:xx Set the language of the wiki you want to work on, overriding - the configuration in user-config.py. xx should be the - language code. - --family:xyz Set the family of the wiki you want to work on, e.g. - wikipedia, wiktionary, wikitravel, ... - This will override the configuration in user-config.py. - --user:xyz Log in as user 'xyz' instead of the default username. - --daemonize:xyz Immediately return control to the terminal and redirect - stdout and stderr to file xyz. - (only use for bots that require no input from stdin). - --help Show this help text. - --log Enable the log file, using the default filename - '%s-bot.log' - Logs will be stored in the logs subdirectory. - --log:xyz Enable the log file, using 'xyz' as the filename. - --nolog Disable the log file (if it is enabled by default). - --maxlag Sets a new maxlag parameter to a number of seconds. Defer bot - edits during periods of database server lag. Default is set - by config.py - --putthrottle:n Set the minimum time (in seconds) the bot will wait between --pt:n saving pages. --put_throttle:n - --debug:item Enable the log file and include extensive debugging data --debug for component "item" (for all components if the second form - is used). - --verbose Have the bot provide additional console output that may be --v useful in debugging. - --cosmeticchanges Toggles the cosmetic_changes setting made in config.py or --cc user-config.py to its inverse and overrules it. All other - settings and restrictions are untouched. - --simulate Disables writing to the server. Useful for testing and - debugging of new code (if given, doesn't do any real - changes, but only shows what would have been changed). - --<config var>:n You may use all given numeric config variables as option and - modify it with command line. - -''' % module_name + global_help = _GLOBAL_HELP % module_name try: module = __import__('%s' % module_name) - helpText = module.__doc__ - if PY2 and isinstance(helpText, bytes): - helpText = helpText.decode('utf-8') + help_text = module.__doc__ + if PY2 and isinstance(help_text, bytes): + help_text = help_text.decode('utf-8') if hasattr(module, 'docuReplacements'): for key, value in module.docuReplacements.items(): - helpText = helpText.replace(key, value.strip('\n\r')) - pywikibot.stdout(helpText) # output to STDOUT + help_text = help_text.replace(key, value.strip('\n\r')) + pywikibot.stdout(help_text) # output to STDOUT except Exception: if module_name: pywikibot.stdout(u'Sorry, no help available for %s' % module_name) pywikibot.log('showHelp:', exc_info=True) - pywikibot.stdout(globalHelp) + pywikibot.stdout(global_help)
def suggest_help(missing_parameters=[], missing_generator=False, @@ -1101,9 +1103,9 @@ except IOError: command_log_file = codecs.open(command_log_filename, 'w', 'utf-8') # add a timestamp in ISO 8601 formulation - isoDate = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + iso_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) command_log_file.write('%s r%s Python %s ' - % (isoDate, version.getversiondict()['rev'], + % (iso_date, version.getversiondict()['rev'], sys.version.split()[0])) s = u' '.join(args) command_log_file.write(s + os.linesep) @@ -1143,16 +1145,14 @@ @param kwargs: options @type kwargs: dict """ + valid_options = set(self.availableOptions) + received_options = set(kwargs) + # contains the options overridden from defaults - self.options = {} + self.options = { + opt: kwargs[opt] for opt in received_options & valid_options}
- validOptions = set(self.availableOptions) - receivedOptions = set(kwargs) - - for opt in receivedOptions & validOptions: - self.options[opt] = kwargs[opt] - - for opt in receivedOptions - validOptions: + for opt in received_options - valid_options: pywikibot.warning(u'%s is not a valid option. It was ignored.' % opt)
diff --git a/pywikibot/data/wikistats.py b/pywikibot/data/wikistats.py index 2ed1447..2c079fc 100644 --- a/pywikibot/data/wikistats.py +++ b/pywikibot/data/wikistats.py @@ -104,7 +104,7 @@ path = '/{format}/{table}.{format}' else: path = '/api.php?action=dump&table={table}&format={format}' - URL = self.url + path + url = self.url + path
if table not in self.ALL_KEYS: pywikibot.warning('WikiStats unknown table %s' % table) @@ -112,7 +112,7 @@ if table in self.FAMILY_MAPPING: table = self.FAMILY_MAPPING[table]
- r = http.fetch(URL.format(table=table, format=format)) + r = http.fetch(url.format(table=table, format=format)) return r.raw
def raw_cached(self, table, format): diff --git a/pywikibot/titletranslate.py b/pywikibot/titletranslate.py index 073393f..d5ca6df 100644 --- a/pywikibot/titletranslate.py +++ b/pywikibot/titletranslate.py @@ -78,19 +78,19 @@ if auto and page: # search inside all dictionaries for this link sitelang = page.site.lang - dictName, value = date.getAutoFormat(sitelang, page.title()) - if dictName: + dict_name, value = date.getAutoFormat(sitelang, page.title()) + if dict_name: pywikibot.output( u'TitleTranslate: %s was recognized as %s with value %d' - % (page.title(), dictName, value)) - for entryLang, entry in date.formats[dictName].items(): - if entryLang not in site.languages(): + % (page.title(), dict_name, value)) + for entry_lang, entry in date.formats[dict_name].items(): + if entry_lang not in site.languages(): continue - if entryLang != sitelang: + if entry_lang != sitelang: newname = entry(value) x = pywikibot.Link( newname, - pywikibot.Site(code=entryLang, + pywikibot.Site(code=entry_lang, fam=site.family)) result.add(x) return list(result) diff --git a/pywikibot/tools/_logging.py b/pywikibot/tools/_logging.py index 715fbcb..24717a4 100644 --- a/pywikibot/tools/_logging.py +++ b/pywikibot/tools/_logging.py @@ -113,9 +113,9 @@
Formatter.formatException also strips the trailing \n, which we need. """ - strExc = logging.Formatter.formatException(self, ei) + exception_string = logging.Formatter.formatException(self, ei)
- if PY2 and isinstance(strExc, bytes): - return strExc.decode(self._encoding) + '\n' + if PY2 and isinstance(exception_string, bytes): + return exception_string.decode(self._encoding) + '\n' else: - return strExc + '\n' + return exception_string + '\n' diff --git a/scripts/basic.py b/scripts/basic.py index db0402f..9bf50e7 100755 --- a/scripts/basic.py +++ b/scripts/basic.py @@ -166,13 +166,13 @@ # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory()
# Parse command line arguments for arg in local_args:
# Catch the pagegenerators options - if genFactory.handleArg(arg): + if gen_factory.handleArg(arg): continue # nothing to do here
# Now pick up your own options @@ -189,7 +189,7 @@
# The preloading option is responsible for downloading multiple # pages from the wiki simultaneously. - gen = genFactory.getCombinedGenerator(preload=True) + gen = gen_factory.getCombinedGenerator(preload=True) if gen: # pass generator and private options to the bot bot = BasicBot(gen, **options) diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py index 20c91c9..784edcd 100755 --- a/scripts/clean_sandbox.py +++ b/scripts/clean_sandbox.py @@ -162,45 +162,46 @@ while True: wait = False now = time.strftime("%d %b %Y %H:%M:%S (UTC)", time.gmtime()) - for sandboxPage in self.generator: + for sandbox_page in self.generator: pywikibot.output(u'Preparing to process sandbox page %s' - % sandboxPage.title(asLink=True)) - if sandboxPage.isRedirectPage(): + % sandbox_page.title(asLink=True)) + if sandbox_page.isRedirectPage(): pywikibot.warning( u'%s is a redirect page, cleaning it anyway' - % sandboxPage.title(asLink=True)) + % sandbox_page.title(asLink=True)) try: - text = sandboxPage.text + text = sandbox_page.text if not self.getOption('text'): - translatedContent = i18n.translate(self.site, content) + translated_content = i18n.translate(self.site, content) else: - translatedContent = self.getOption('text') + translated_content = self.getOption('text') if self.getOption('summary'): - translatedMsg = self.getOption('summary') + translated_msg = self.getOption('summary') else: - translatedMsg = i18n.twtranslate( + translated_msg = i18n.twtranslate( self.site, 'clean_sandbox-cleaned') - subst = 'subst:' in translatedContent - pos = text.find(translatedContent.strip()) - if text.strip() == translatedContent.strip(): + subst = 'subst:' in translated_content + pos = text.find(translated_content.strip()) + if text.strip() == translated_content.strip(): pywikibot.output( u'The sandbox is still clean, no change necessary.') - elif subst and sandboxPage.userName() == self.site.user(): + elif subst and sandbox_page.userName() == self.site.user(): pywikibot.output( u'The sandbox might be clean, no change necessary.') elif pos != 0 and not subst: - sandboxPage.put(translatedContent, translatedMsg) - pywikibot.showDiff(text, translatedContent) + sandbox_page.put(translated_content, translated_msg) + pywikibot.showDiff(text, translated_content) pywikibot.output(u'Standard content was changed, ' u'sandbox cleaned.') else: edit_delta = (datetime.datetime.utcnow() - - sandboxPage.editTime()) + sandbox_page.editTime()) delta = self.getOption('delay_td') - edit_delta # Is the last edit more than 'delay' minutes ago? if delta <= datetime.timedelta(0): - sandboxPage.put(translatedContent, translatedMsg) - pywikibot.showDiff(text, translatedContent) + sandbox_page.put( + translated_content, translated_msg) + pywikibot.showDiff(text, translated_content) pywikibot.output(u'Standard content was changed, ' u'sandbox cleaned.') else: # wait for the rest diff --git a/scripts/commons_link.py b/scripts/commons_link.py index e5664dd..dcfe800 100755 --- a/scripts/commons_link.py +++ b/scripts/commons_link.py @@ -76,8 +76,8 @@ commonspage.get(get_redirect=True) pagetitle = commonspage.title(withNamespace=not catmode) if page.title() == pagetitle: - oldText = page.get() - text = oldText + old_text = page.get() + text = old_text
# for Commons/Commonscat template s = self.findTemplate.search(text) @@ -96,7 +96,7 @@ page.site, 'commons_link%s-template-added' % ('', '-cat')[catmode]) try: - self.userPut(page, oldText, text, + self.userPut(page, old_text, text, summary=comment) except pywikibot.EditConflict: pywikibot.output( @@ -128,7 +128,7 @@ options = {}
local_args = pywikibot.handle_args(args) - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory()
for arg in local_args: if arg in ('pages', 'categories'): @@ -136,9 +136,9 @@ elif arg == '-always': options['always'] = True else: - genFactory.handleArg(arg) + gen_factory.handleArg(arg)
- gen = genFactory.getCombinedGenerator(preload=True) + gen = gen_factory.getCombinedGenerator(preload=True) if 'action' in options and gen: bot = CommonsLinkBot(gen, **options) bot.run() diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py index af91233..8f53756 100644 --- a/scripts/cosmetic_changes.py +++ b/scripts/cosmetic_changes.py @@ -68,11 +68,11 @@
def treat_page(self): """Treat page with the cosmetic toolkit.""" - ccToolkit = cosmetic_changes.CosmeticChangesToolkit.from_page( + cc_toolkit = cosmetic_changes.CosmeticChangesToolkit.from_page( self.current_page, False, self.getOption('ignore')) - changedText = ccToolkit.change(self.current_page.get()) - if changedText is not False: - self.put_current(new_text=changedText, + changed_text = cc_toolkit.change(self.current_page.get()) + if changed_text is not False: + self.put_current(new_text=changed_text, summary=self.getOption('summary'), asynchronous=self.getOption('async'))
@@ -90,7 +90,7 @@
# Process global args and prepare generator args parser local_args = pywikibot.handle_args(args) - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory()
for arg in local_args: if arg.startswith('-summary:'): @@ -111,7 +111,7 @@ raise ValueError( 'Unknown ignore mode "{0}"!'.format(ignore_mode)) else: - genFactory.handleArg(arg) + gen_factory.handleArg(arg)
site = pywikibot.Site()
@@ -120,7 +120,7 @@ options['summary'] = i18n.twtranslate(site, 'cosmetic_changes-standalone')
- gen = genFactory.getCombinedGenerator(preload=True) + gen = gen_factory.getCombinedGenerator(preload=True) if gen: if options.get('always') or config.simulate or pywikibot.input_yn( warning + '\nDo you really want to continue?', diff --git a/scripts/create_categories.py b/scripts/create_categories.py index 91bcc42..70cf106 100755 --- a/scripts/create_categories.py +++ b/scripts/create_categories.py @@ -90,7 +90,7 @@
# Process global args and prepare generator args parser local_args = pywikibot.handle_args(args) - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory()
for arg in local_args: if arg == '-always': @@ -100,7 +100,7 @@ elif arg.startswith('-basename'): basename = arg[len('-basename:'):].strip() else: - genFactory.handleArg(arg) + gen_factory.handleArg(arg)
missing = set() if not parent: @@ -108,7 +108,7 @@ if not basename: missing.add('-basename')
- generator = genFactory.getCombinedGenerator() + generator = gen_factory.getCombinedGenerator() if generator and missing: bot = CreateCategoriesBot(generator, parent, basename, **options) bot.run() diff --git a/scripts/delete.py b/scripts/delete.py index 08d243c..5c7a8a4 100755 --- a/scripts/delete.py +++ b/scripts/delete.py @@ -224,14 +224,13 @@ @param args: command line arguments @type args: list of unicode """ - pageName = '' + page_name = '' summary = None - generator = None options = {}
# read command line parameters local_args = pywikibot.handle_args(args) - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory() mysite = pywikibot.Site()
for arg in local_args: @@ -260,31 +259,31 @@ namespaces = mysite.namespaces options['orphansonly'] = namespaces else: - genFactory.handleArg(arg) + gen_factory.handleArg(arg) found = arg.find(':') + 1 if found: - pageName = arg[found:] + page_name = arg[found:]
if not summary: un = 'un' if 'undelete' in options else '' - if pageName: + if page_name: if arg.startswith(('-cat', '-subcats')): summary = i18n.twtranslate(mysite, 'delete-from-category', - {'page': pageName}) + {'page': page_name}) elif arg.startswith('-links'): summary = i18n.twtranslate(mysite, un + 'delete-linked-pages', - {'page': pageName}) + {'page': page_name}) elif arg.startswith('-ref'): summary = i18n.twtranslate(mysite, 'delete-referring-pages', - {'page': pageName}) + {'page': page_name}) elif arg.startswith('-imageused'): summary = i18n.twtranslate(mysite, un + 'delete-images', - {'page': pageName}) + {'page': page_name}) elif arg.startswith('-file'): summary = i18n.twtranslate(mysite, un + 'delete-from-file')
- generator = genFactory.getCombinedGenerator() + generator = gen_factory.getCombinedGenerator() # We are just deleting pages, so we have no need of using a preloading # page generator to actually get the text of those pages. if generator: diff --git a/scripts/editarticle.py b/scripts/editarticle.py index 49a389a..df951ad 100755 --- a/scripts/editarticle.py +++ b/scripts/editarticle.py @@ -73,8 +73,8 @@
def setpage(self): """Set page and page title.""" - pageTitle = self.options.page or pywikibot.input("Page to edit:") - self.page = pywikibot.Page(pywikibot.Link(pageTitle, self.site)) + page_title = self.options.page or pywikibot.input('Page to edit:') + self.page = pywikibot.Page(pywikibot.Link(page_title, self.site)) if not self.options.edit_redirect and self.page.isRedirectPage(): self.page = self.page.getRedirectTarget()
@@ -94,8 +94,8 @@ old = self.page.get(get_redirect=self.options.edit_redirect) except pywikibot.NoPage: old = "" - textEditor = TextEditor() - new = textEditor.edit(old) + text_editor = TextEditor() + new = text_editor.edit(old) if new and old != new: pywikibot.showDiff(old, new) changes = pywikibot.input("What did you change?") diff --git a/scripts/image.py b/scripts/image.py index bfe5ee9..dcae5af 100755 --- a/scripts/image.py +++ b/scripts/image.py @@ -156,8 +156,8 @@ site = pywikibot.Site() old_imagepage = pywikibot.FilePage(site, old_image) gen = pagegenerators.FileLinksGenerator(old_imagepage) - preloadingGen = pagegenerators.PreloadingGenerator(gen) - bot = ImageRobot(preloadingGen, old_image, new_image, + preloading_gen = pagegenerators.PreloadingGenerator(gen) + bot = ImageRobot(preloading_gen, old_image, new_image, site=site, **options) bot.run() return True diff --git a/scripts/imageharvest.py b/scripts/imageharvest.py index b21ed96..104f898 100644 --- a/scripts/imageharvest.py +++ b/scripts/imageharvest.py @@ -129,8 +129,7 @@ % (mysite.namespace(14), cat)) desc += "\r\n\r\n" + basicdesc + "\r\n\r\n" + \ "\r\n".join(categories) - uploadBot = UploadRobot(image, description=desc) - uploadBot.run() + UploadRobot(image, description=desc).run() elif answer == 's': break
diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py index f285299..d2619ca 100755 --- a/scripts/imageuncat.py +++ b/scripts/imageuncat.py @@ -1273,9 +1273,9 @@ pywikibot.output(u'Got category ' + category.title()) return False
- for templateWithTrail in page.templates(): + for template_with_trail in page.templates(): # Strip of trailing garbage - template = templateWithTrail.title().rstrip('\n').rstrip() + template = template_with_trail.title().rstrip('\n').rstrip() if template in skipTemplates: # Already tagged with a template, skip it pywikibot.output(u'Already tagged, skip it') @@ -1340,7 +1340,7 @@ elif choice == 'q': return False
- genFactory = pagegenerators.GeneratorFactory(site) + gen_factory = pagegenerators.GeneratorFactory(site)
for arg in local_args: param_arg, sep, param_value = arg.partition(':') @@ -1359,11 +1359,11 @@ '-recentchanges without parameters', '-recentchanges:offset,duration', 2, ArgumentDeprecationWarning) - genFactory.handleArg(arg) + gen_factory.handleArg(arg) else: - genFactory.handleArg(arg) + gen_factory.handleArg(arg)
- generator = genFactory.getCombinedGenerator(gen=generator, preload=True) + generator = gen_factory.getCombinedGenerator(gen=generator, preload=True) if not generator: pywikibot.bot.suggest_help(missing_generator=True) return False diff --git a/scripts/interwikidata.py b/scripts/interwikidata.py index 229e5cc..5d4e14c 100644 --- a/scripts/interwikidata.py +++ b/scripts/interwikidata.py @@ -221,10 +221,10 @@ @type args: list of unicode """ local_args = pywikibot.handle_args(args) - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory() options = {} for arg in local_args: - if genFactory.handleArg(arg): + if gen_factory.handleArg(arg): continue option, sep, value = arg.partition(':') option = option[1:] if option.startswith('-') else None @@ -235,7 +235,7 @@
site = pywikibot.Site()
- generator = genFactory.getCombinedGenerator(preload=True) + generator = gen_factory.getCombinedGenerator(preload=True) if generator: bot = IWBot(generator=generator, site=site, **options) bot.run() diff --git a/scripts/listpages.py b/scripts/listpages.py index 511b4e4..0529ef1 100755 --- a/scripts/listpages.py +++ b/scripts/listpages.py @@ -190,7 +190,7 @@
# Process global args and prepare generator args parser local_args = pywikibot.handle_args(args) - genFactory = GeneratorFactory() + gen_factory = GeneratorFactory()
for arg in local_args: option, sep, value = arg.partition(':') @@ -215,7 +215,7 @@ elif option == '-summary': summary = value else: - genFactory.handleArg(arg) + gen_factory.handleArg(arg)
if base_dir: base_dir = os.path.expanduser(base_dir) @@ -250,7 +250,7 @@ if re.match('^[a-z_-]+$', summary): summary = i18n.twtranslate(site, summary)
- gen = genFactory.getCombinedGenerator() + gen = gen_factory.getCombinedGenerator() if gen: i = 0 output_list = [] diff --git a/scripts/lonelypages.py b/scripts/lonelypages.py index a8e0131..a527687 100755 --- a/scripts/lonelypages.py +++ b/scripts/lonelypages.py @@ -235,7 +235,7 @@ options = {}
local_args = pywikibot.handle_args(args) - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory() site = pywikibot.Site()
for arg in local_args: @@ -254,13 +254,13 @@ elif arg == '-always': options['always'] = True else: - genFactory.handleArg(arg) + gen_factory.handleArg(arg)
- generator = genFactory.getCombinedGenerator() + generator = gen_factory.getCombinedGenerator()
# If the generator is not given, use the default one if not generator: - generator = site.lonelypages(total=genFactory.limit) + generator = site.lonelypages(total=gen_factory.limit)
bot = LonelyPagesBot(generator, **options) bot.run() diff --git a/scripts/ndashredir.py b/scripts/ndashredir.py index a9b3245..1928356 100644 --- a/scripts/ndashredir.py +++ b/scripts/ndashredir.py @@ -137,13 +137,13 @@ # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory()
# Parse command line arguments for arg in local_args:
# Catch the pagegenerators options - if genFactory.handleArg(arg): + if gen_factory.handleArg(arg): continue # nothing to do here
# Now pick up custom options @@ -158,7 +158,7 @@
# The preloading option is responsible for downloading multiple pages # from the wiki simultaneously. - gen = genFactory.getCombinedGenerator(preload=True) + gen = gen_factory.getCombinedGenerator(preload=True) if gen: # pass generator and private options to the bot bot = DashRedirectBot(gen, **options) diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py index 6df0993..cb2fb6b 100755 --- a/scripts/pagefromfile.py +++ b/scripts/pagefromfile.py @@ -253,21 +253,23 @@
def findpage(self, text): """Find page to work on.""" - pageR = re.compile(re.escape(self.pageStartMarker) + "(.*?)" + - re.escape(self.pageEndMarker), re.DOTALL) - titleR = re.compile(re.escape(self.titleStartMarker) + "(.*?)" + - re.escape(self.titleEndMarker)) + page_regex = re.compile( + re.escape(self.pageStartMarker) + '(.*?)' + + re.escape(self.pageEndMarker), re.DOTALL) + title_regex = re.compile( + re.escape(self.titleStartMarker) + '(.*?)' + + re.escape(self.titleEndMarker))
- location = pageR.search(text) + location = page_regex.search(text) if self.include: contents = location.group() else: contents = location.group(1) try: - title = titleR.search(contents).group(1) + title = title_regex.search(contents).group(1) if self.notitle: # Remove title (to allow creation of redirects) - contents = titleR.sub('', contents, count=1) + contents = title_regex.sub('', contents, count=1) except AttributeError: raise NoTitle(location.end()) else: diff --git a/scripts/patrol.py b/scripts/patrol.py index 0f79da6..0e4cb92 100755 --- a/scripts/patrol.py +++ b/scripts/patrol.py @@ -469,7 +469,7 @@ recentchanges = False newpages = False repeat = False - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory() options = {}
# Parse command line arguments @@ -492,7 +492,7 @@ elif arg.startswith("-whitelist:"): options['whitelist'] = arg[len('-whitelist:'):] else: - generator = genFactory.handleArg(arg) + generator = gen_factory.handleArg(arg) if not generator: if ':' in arg: m = arg.split(':') @@ -523,7 +523,7 @@ gen = site.newpages feed = api_feed_repeater(gen, delay=60, repeat=repeat, user=usercontribs, - namespaces=genFactory.namespaces, + namespaces=gen_factory.namespaces, recent_new_gen=False) bot.run(feed)
@@ -531,7 +531,7 @@ pywikibot.output(u'Recentchanges:') gen = site.recentchanges feed = api_feed_repeater(gen, delay=60, repeat=repeat, - namespaces=genFactory.namespaces, + namespaces=gen_factory.namespaces, user=usercontribs) bot.run(feed)
diff --git a/scripts/piper.py b/scripts/piper.py index 50296b7..bfc162f 100755 --- a/scripts/piper.py +++ b/scripts/piper.py @@ -90,18 +90,18 @@ pipe.append(str(program), '--') # py2-py3 compatibility
# Create a temporary filename to save the piped stuff to - tempFilename = '%s.%s' % (tempfile.mktemp(), 'txt') - with pipe.open(tempFilename, 'w') as file: + temp_filename = '%s.%s' % (tempfile.mktemp(), 'txt') + with pipe.open(temp_filename, 'w') as file: file.write(text)
# Now retrieve the munged text - with open(tempFilename, 'r') as file: + with open(temp_filename, 'r') as file: unicode_text = file.read() if not isinstance(unicode_text, UnicodeType): # py2-py3 compatibility unicode_text = unicode_text.decode('utf-8')
# clean up - os.unlink(tempFilename) + os.unlink(temp_filename) return unicode_text
def treat_page(self): @@ -124,7 +124,7 @@ # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory() # The program to pipe stuff through filters = [] options = {} @@ -139,11 +139,11 @@ else: # check if a standard argument like # -start:XYZ or -ref:Asdf was given. - genFactory.handleArg(arg) + gen_factory.handleArg(arg)
options['filters'] = filters
- gen = genFactory.getCombinedGenerator(preload=True) + gen = gen_factory.getCombinedGenerator(preload=True) if gen: # The preloading generator is responsible for downloading multiple # pages from the wiki simultaneously. diff --git a/scripts/protect.py b/scripts/protect.py index 8171dd7..6e78bad 100755 --- a/scripts/protect.py +++ b/scripts/protect.py @@ -169,7 +169,7 @@
# read command line parameters local_args = pywikibot.handle_args(args) - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory() site = pywikibot.Site()
generator_type = None @@ -215,7 +215,7 @@ protections[p_type_arg] = level is_p_type = True if not is_p_type: - if not genFactory.handleArg(arg): + if not gen_factory.handleArg(arg): raise ValueError('Unknown parameter "{0}"'.format(arg)) found = arg.find(':') if found: @@ -237,7 +237,7 @@ site, 'protect-{0}'.format(message_type), message_properties)
- generator = genFactory.getCombinedGenerator() + generator = gen_factory.getCombinedGenerator() # We are just protecting pages, so we have no need of using a preloading # page generator to actually get the text of those pages. if generator: diff --git a/scripts/selflink.py b/scripts/selflink.py index a5b2ad6..2f77f27 100755 --- a/scripts/selflink.py +++ b/scripts/selflink.py @@ -82,25 +82,23 @@ @param args: command line arguments @type args: list of unicode """ - # Page generator - gen = None # Process global args and prepare generator args parser local_args = pywikibot.handle_args(args) - genFactory = GeneratorFactory() - botArgs = {} + gen_factory = GeneratorFactory() + bot_args = {}
for arg in local_args: if arg == '-always': - botArgs['always'] = True + bot_args['always'] = True else: - genFactory.handleArg(arg) + gen_factory.handleArg(arg)
- gen = genFactory.getCombinedGenerator(preload=True) + gen = gen_factory.getCombinedGenerator(preload=True) if not gen: pywikibot.bot.suggest_help(missing_generator=True) return False
- bot = SelflinkBot(gen, **botArgs) + bot = SelflinkBot(gen, **bot_args) bot.run() return True
diff --git a/scripts/spamremove.py b/scripts/spamremove.py index 2502895..6e94a66 100755 --- a/scripts/spamremove.py +++ b/scripts/spamremove.py @@ -131,7 +131,7 @@ protocol = 'http' options = {} local_args = pywikibot.handle_args(args) - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory() for arg in local_args: if arg == '-always': options['always'] = True @@ -139,7 +139,7 @@ protocol = arg.partition(':')[2] elif arg.startswith('-summary:'): options['summary'] = arg.partition(':')[2] - elif genFactory.handleArg(arg): + elif gen_factory.handleArg(arg): continue else: spam_external_url = arg @@ -150,7 +150,7 @@
link_search = pagegenerators.LinksearchPageGenerator(spam_external_url, protocol=protocol) - generator = genFactory.getCombinedGenerator(gen=link_search) + generator = gen_factory.getCombinedGenerator(gen=link_search) generator = pagegenerators.PreloadingGenerator(generator)
bot = SpamRemoveBot(generator, spam_external_url, **options) diff --git a/scripts/states_redirect.py b/scripts/states_redirect.py index c04d7a8..742b6f9 100755 --- a/scripts/states_redirect.py +++ b/scripts/states_redirect.py @@ -70,8 +70,7 @@ if so, create a redirect from Something, ST.. """ for sn in self.abbrev: - R = re.compile(r', %s$' % sn) - if R.search(page.title()): + if re.search(r', %s$' % sn, page.title()): pl = pywikibot.Page(self.site, page.title().replace(sn, self.abbrev[sn])) # A bit hacking here - the real work is done in the diff --git a/scripts/surnames_redirects.py b/scripts/surnames_redirects.py index 949e3a6..e956ff8 100755 --- a/scripts/surnames_redirects.py +++ b/scripts/surnames_redirects.py @@ -111,15 +111,15 @@ options = {}
local_args = pywikibot.handle_args(args) - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory()
for arg in local_args: if arg == '-surnames_last': options['surnames_last'] = True else: - genFactory.handleArg(arg) + gen_factory.handleArg(arg)
- gen = genFactory.getCombinedGenerator() + gen = gen_factory.getCombinedGenerator() if gen: bot = SurnamesBot(gen, **options) bot.run() diff --git a/scripts/templatecount.py b/scripts/templatecount.py index b31d22f..6b36177 100755 --- a/scripts/templatecount.py +++ b/scripts/templatecount.py @@ -63,16 +63,16 @@ @param namespaces: list of namespace numbers @type namespaces: list """ - FORMAT = '{0:<10}: {1:>5}' - templateDict = cls.template_dict(templates, namespaces) + format = '{0:<10}: {1:>5}' + template_dict = cls.template_dict(templates, namespaces) pywikibot.stdout('\nNumber of transclusions per template') pywikibot.stdout('-' * 36) total = 0 - for key in templateDict: - count = len(templateDict[key]) - pywikibot.stdout(FORMAT.format(key, count)) + for key in template_dict: + count = len(template_dict[key]) + pywikibot.stdout(format.format(key, count)) total += count - pywikibot.stdout(FORMAT.format('TOTAL', total)) + pywikibot.stdout(format.format('TOTAL', total)) pywikibot.stdout('Report generated on {0}' ''.format(datetime.datetime.utcnow().isoformat()))
@@ -89,14 +89,14 @@ @param namespaces: list of namespace numbers @type namespaces: list """ - templateDict = cls.template_dict(templates, namespaces) + template_dict = cls.template_dict(templates, namespaces) pywikibot.stdout('\nList of pages transcluding templates:') for key in templates: pywikibot.output(u'* %s' % key) pywikibot.stdout('-' * 36) total = 0 - for key in templateDict: - for page in templateDict[key]: + for key in template_dict: + for page in template_dict[key]: pywikibot.stdout(page.title()) total += 1 pywikibot.output(u'Total page count: %d' % total) @@ -118,11 +118,7 @@
@rtype: dict """ - gen = cls.template_dict_generator(templates, namespaces) - templateDict = {} - for template, transcludingArray in gen: - templateDict[template] = transcludingArray - return templateDict + return dict(cls.template_dict_generator(templates, namespaces))
@staticmethod def template_dict_generator(templates, namespaces): @@ -143,12 +139,12 @@ mysite = pywikibot.Site() mytpl = mysite.namespaces.TEMPLATE for template in templates: - transcludingArray = [] + transcluding_array = [] gen = pywikibot.Page(mysite, template, ns=mytpl).getReferences( namespaces=namespaces, onlyTemplateInclusion=True) for page in gen: - transcludingArray.append(page) - yield template, transcludingArray + transcluding_array.append(page) + yield template, transcluding_array
def main(*args): @@ -161,7 +157,7 @@ @type args: list of unicode """ operation = None - argsList = [] + args_list = [] namespaces = []
for arg in pywikibot.handle_args(args): @@ -173,17 +169,17 @@ except ValueError: namespaces.append(arg[len('-namespace:'):]) else: - argsList.append(arg) + args_list.append(arg)
if not operation: pywikibot.bot.suggest_help(missing_parameters=['operation']) return False
robot = TemplateCountRobot() - if not argsList: - argsList = templates + if not args_list: + args_list = templates
- if 'reflist' in argsList: + if 'reflist' in args_list: pywikibot.output( u'NOTE: it will take a long time to count "reflist".') choice = pywikibot.input_choice( @@ -191,14 +187,14 @@ [('yes', 'y'), ('no', 'n'), ('skip', 's')], 'y', automatic_quit=False) if choice == 's': - argsList.remove('reflist') + args_list.remove('reflist') elif choice == 'n': return
if operation == "count": - robot.countTemplates(argsList, namespaces) + robot.countTemplates(args_list, namespaces) elif operation == "list": - robot.listTemplates(argsList, namespaces) + robot.listTemplates(args_list, namespaces)
if __name__ == "__main__": diff --git a/scripts/touch.py b/scripts/touch.py index f674ed8..7dc97cf 100755 --- a/scripts/touch.py +++ b/scripts/touch.py @@ -81,7 +81,7 @@
# Process global args and prepare generator args parser local_args = pywikibot.handle_args(args) - genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory()
bot_class = TouchBot for arg in local_args: @@ -90,11 +90,11 @@ elif arg == '-redir': pywikibot.output(u'-redirect option is deprecated, ' 'do not use it anymore.') - elif not genFactory.handleArg(arg) and arg.startswith("-"): + elif not gen_factory.handleArg(arg) and arg.startswith('-'): # -botflag options[arg[1:].lower()] = True
- gen = genFactory.getCombinedGenerator(preload=True) + gen = gen_factory.getCombinedGenerator(preload=True) if gen: bot = bot_class(generator=gen, **options) pywikibot.Site().login() diff --git a/scripts/transferbot.py b/scripts/transferbot.py index 30d54f0..2988990 100755 --- a/scripts/transferbot.py +++ b/scripts/transferbot.py @@ -98,10 +98,10 @@ overwrite = False gen_args = []
- genFactory = pagegenerators.GeneratorFactory() + gen_factory = pagegenerators.GeneratorFactory()
for arg in local_args: - if genFactory.handleArg(arg): + if gen_factory.handleArg(arg): gen_args.append(arg) continue if arg.startswith('-tofamily'): @@ -117,7 +117,7 @@ if fromsite == tosite: raise TargetSiteMissing('Target site not different from source site')
- gen = genFactory.getCombinedGenerator() + gen = gen_factory.getCombinedGenerator() if not gen: raise TargetPagesMissing('Target pages not specified')
diff --git a/scripts/upload.py b/scripts/upload.py index c0146d2..f729d51 100755 --- a/scripts/upload.py +++ b/scripts/upload.py @@ -103,11 +103,11 @@ url = u'' description = [] summary = None - keepFilename = False + keep_filename = False always = False - useFilename = None + use_filename = None filename_prefix = None - verifyDescription = True + verify_description = True aborts = set() ignorewarn = set() chunk_size = 0 @@ -121,21 +121,21 @@ for option in local_args: arg, _, value = option.partition(':') if arg == '-always': - keepFilename = True + keep_filename = True always = True - verifyDescription = False + verify_description = False elif arg == '-recursive': recursive = True elif arg == '-keep': - keepFilename = True + keep_filename = True elif arg == '-filename': - useFilename = value + use_filename = value elif arg == '-prefix': filename_prefix = value elif arg == '-summary': summary = value elif arg == '-noverify': - verifyDescription = False + verify_description = False elif arg == '-abortonwarn': if value and aborts is not True: aborts.add(value) @@ -198,9 +198,9 @@ else: url = [url]
- bot = UploadRobot(url, description=description, useFilename=useFilename, - keepFilename=keepFilename, - verifyDescription=verifyDescription, aborts=aborts, + bot = UploadRobot(url, description=description, useFilename=use_filename, + keepFilename=keep_filename, + verifyDescription=verify_description, aborts=aborts, ignoreWarning=ignorewarn, chunk_size=chunk_size, always=always, summary=summary, filename_prefix=filename_prefix) diff --git a/tox.ini b/tox.ini index 7b7c4f7..06402f7 100644 --- a/tox.ini +++ b/tox.ini @@ -161,13 +161,11 @@ pwb.py : T001 # pydocstyle cannot handle multiple __all__ variables pywikibot/__init__.py : P103, D999, N806 - pywikibot/bot.py : N806 pywikibot/comms/http.py : T001 pywikibot/compat/catlib.py : N803 pywikibot/config2.py : N806 pywikibot/cosmetic_changes.py : N803, N806 pywikibot/data/api.py : N803, N806 - pywikibot/data/wikistats.py : N806 pywikibot/date.py : E241, N803, N806 pywikibot/diff.py : N806 pywikibot/editor.py : N803, N806 @@ -185,8 +183,6 @@ pywikibot/site.py : N803, N806 pywikibot/specialbots.py : N803, N806 pywikibot/textlib.py : E241, N801, N803, N806 - pywikibot/titletranslate.py : N806 - pywikibot/tools/_logging.py : N806 pywikibot/tools/ip.py : N803 pywikibot/userinterfaces/cgi_interface.py : N803 pywikibot/userinterfaces/gui.py : N812, N803, N806 @@ -200,7 +196,6 @@ pywikibot/xmlreader.py : N803, N806 scripts/add_text.py : N803, N806 scripts/archive/featured.py : D102, D103 - scripts/basic.py : N806 scripts/blockpageschecker.py : N803, N806 scripts/capitalize_redirects.py : N806 scripts/casechecker.py : N803, N806 @@ -208,58 +203,33 @@ scripts/category_redirect.py : N803, N806 scripts/cfd.py : N803, N806 scripts/checkimages.py : N801, N803, N806 - scripts/clean_sandbox.py : N806 - scripts/commons_link.py : N806 scripts/commonscat.py : N803, N806 - scripts/cosmetic_changes.py : N806 - scripts/create_categories.py : N806 scripts/data_ingestion.py : N803, N806 - scripts/delete.py : N806 - scripts/editarticle.py : N806 scripts/fixing_redirects.py : N803, N806 scripts/flickrripper.py : T001, N803, N806 scripts/followlive.py : N803 scripts/harvest_template.py : T001, N803 - scripts/image.py : N806 scripts/imagecopy.py : N801, N803, N806 scripts/imagecopy_self.py : N801, N803, N806 - scripts/imageharvest.py : N806 scripts/imagerecat.py : N803, N806 scripts/imagetransfer.py : E241, N803, N806 - scripts/imageuncat.py : N806 scripts/interwiki.py : P102, N803, N806 - scripts/interwikidata.py : N806 scripts/isbn.py : N803, N806 - scripts/listpages.py : N806 - scripts/lonelypages.py : N806 scripts/maintenance/* : T001 scripts/makecat.py : D103 scripts/match_images.py : N803, N806 scripts/misspelling.py : N803, N806 scripts/movepages.py : N803, N806 - scripts/ndashredir.py : N806 scripts/noreferences.py : N803, N806 scripts/nowcommons.py : N803, N806 - scripts/pagefromfile.py : N806 - scripts/patrol.py : N806 - scripts/piper.py : N806 - scripts/protect.py : N806 scripts/redirect.py : N803, N806 scripts/reflinks.py : N806 scripts/replace.py : N803, N806 scripts/script_wui.py : D102, N806 - scripts/selflink.py : N806 scripts/solve_disambiguation.py : N803, N806 - scripts/spamremove.py : N806 - scripts/states_redirect.py : N806 - scripts/surnames_redirects.py : N806 scripts/table2wiki.py : N806 scripts/template.py : N806 - scripts/templatecount.py : N806 - scripts/touch.py : N806 - scripts/transferbot.py : N806 scripts/unlink.py : N803 - scripts/upload.py : N806 scripts/watchlist.py : N803 scripts/weblinkchecker.py : N803, N806 scripts/welcome.py : N806
pywikibot-commits@lists.wikimedia.org