jenkins-bot has submitted this change and it was merged.
Change subject: Make transferbot exit cleanly when no arguments given.
......................................................................
Make transferbot exit cleanly when no arguments given.
Bug: 68662
Change-Id: If091461be0addece8600a413b7f64547e7cb7a8c
---
M scripts/transferbot.py
M tests/script_tests.py
2 files changed, 35 insertions(+), 4 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/transferbot.py b/scripts/transferbot.py
index 50372da..dcc6144 100644
--- a/scripts/transferbot.py
+++ b/scripts/transferbot.py
@@ -48,6 +48,29 @@
}
+class WikiTransferException(Exception):
+ """Base class for exceptions from this script.
+
+ Makes it easier for clients to catch all expected exceptions that the script might
+ throw
+ """
+ pass
+
+
+class TargetSiteMissing(WikiTransferException):
+ """Thrown when the target site is the same as the source site.
+
+ Based on the way each are initialized, this is likely to happen when the target site
+ simply hasn't been specified.
+ """
+ pass
+
+
+class TargetPagesMissing(WikiTransferException):
+ """Thrown if no page range has been specified for the script to operate on."""
+ pass
+
+
def main():
tohandle = pywikibot.handleArgs()
@@ -75,11 +98,11 @@
tosite = pywikibot.Site(tolang, tofamily)
if fromsite == tosite:
- raise Exception('Target site not different from source site')
+ raise TargetSiteMissing('Target site not different from source site')
gen = genFactory.getCombinedGenerator()
if not gen:
- raise Exception('Target pages not specified')
+ raise TargetPagesMissing('Target pages not specified')
gen_args = ' '.join(gen_args)
pywikibot.output(u"""
@@ -129,4 +152,13 @@
if __name__ == "__main__":
- main()
+ try:
+ main()
+ except TargetSiteMissing as e:
+ pywikibot.error(u'Need to specify a target site and/or language')
+ pywikibot.error(u'Try running this script with -help for help/usage')
+ pywikibot.exception()
+ except TargetPagesMissing as e:
+ pywikibot.error(u'Need to specify a page range')
+ pywikibot.error(u'Try running this script with -help for help/usage')
+ pywikibot.exception()
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 9b7ae9f..1e8e5a6 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -227,7 +227,6 @@
'imagerecat', # bug 68658
'imagetransfer', # bug 68659
'pagefromfile', # bug 68660
- 'transferbot', # raises custom Exception
'upload', # raises custom ValueError
] or \
(config.family == 'wikidata' and script_name == 'lonelypages') or \
--
To view, visit https://gerrit.wikimedia.org/r/151808
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If091461be0addece8600a413b7f64547e7cb7a8c
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Audiodude <audiodude(a)gmail.com>
Gerrit-Reviewer: Audiodude <audiodude(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: add_text: 'page' is now a mandatory argument
......................................................................
add_text: 'page' is now a mandatory argument
to fix SyntaxError: non-default argument follows default argument
https://travis-ci.org/wikimedia/pywikibot-core/jobs/31764485#L871
actually, there was no reason for making 'page' optional
Change-Id: I3de824dfd61276a3943b543db5d86f3ba3ce6b28
---
M scripts/add_text.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/add_text.py b/scripts/add_text.py
index cd12b4b..ece394b 100644
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -117,7 +117,7 @@
]
-def add_text(page=None, addText, summary=None, regexSkip=None,
+def add_text(page, addText, summary=None, regexSkip=None,
regexSkipUrl=None, always=False, up=False, putText=True,
oldTextGiven=None, reorderEnabled=True, create=False):
site = page.site
--
To view, visit https://gerrit.wikimedia.org/r/151993
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3de824dfd61276a3943b543db5d86f3ba3ce6b28
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Disable testing of scripts/editarticle.py
......................................................................
Disable testing of scripts/editarticle.py
With GUI editing now part of core, editarticle tries to load a
GUI window, which isnt possible on the travis-ci environment.
Change-Id: I8f3d40cb79f92ad10e935df8cef6e02ca5413257
---
M tests/script_tests.py
1 file changed, 1 insertion(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/script_tests.py b/tests/script_tests.py
index ded3821..000993e 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -57,6 +57,7 @@
and name != 'imageuncat.py' # this halts indefinitely
and name != 'welcome.py' # result depends on speed
and name != 'script_wui.py' # depends on lua compiling
+ and name != 'editarticle.py' # requires a X DISPLAY
]
return ['login'] + script_list
--
To view, visit https://gerrit.wikimedia.org/r/151985
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8f3d40cb79f92ad10e935df8cef6e02ca5413257
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: call pywikibot.showHelp() instead of raising NoEnoughData
......................................................................
call pywikibot.showHelp() instead of raising NoEnoughData
in add_text.py and commonscat.py
- the expected failures were removed from script_tests.py
- the 'addText' argument of add_text.add_text()
is now mandatory
bug: 69091
Change-Id: I23f8a29ad5864be6ff649ad7a2c59e0810d9c7c3
---
M scripts/add_text.py
M scripts/commonscat.py
M tests/script_tests.py
3 files changed, 12 insertions(+), 21 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/add_text.py b/scripts/add_text.py
index a8aca2f..cd12b4b 100644
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -117,15 +117,9 @@
]
-class NoEnoughData(pywikibot.Error):
- """ Error class for when the user doesn't specified all the data needed """
-
-
-def add_text(page=None, addText=None, summary=None, regexSkip=None,
+def add_text(page=None, addText, summary=None, regexSkip=None,
regexSkipUrl=None, always=False, up=False, putText=True,
oldTextGiven=None, reorderEnabled=True, create=False):
- if not addText:
- raise NoEnoughData('You have to specify what text you want to add!')
site = page.site
if not summary:
summary = i18n.twtranslate(site, 'add_text-adding',
@@ -350,8 +344,8 @@
if not generator:
generator = genFactory.getCombinedGenerator()
if not generator:
- raise NoEnoughData(
- 'You have to specify the generator you want to use for the script!')
+ pywikibot.showHelp()
+ return
if talkPage:
generator = pagegenerators.PageWithTalkPageGenerator(generator)
site = pywikibot.Site()
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 09b892d..082cb9b 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -56,7 +56,7 @@
#
# (C) Multichill, 2008-2009
# (C) Xqt, 2009-2014
-# (C) Pywikibot team, 2008-2012
+# (C) Pywikibot team, 2008-2014
#
# Distributed under the terms of the MIT license.
#
@@ -574,13 +574,14 @@
if not generator:
generator = genFactory.getCombinedGenerator()
- if not generator:
- raise add_text.NoEnoughData(u'You have to specify the generator you '
- u'want to use for the script!')
- pregenerator = pagegenerators.PreloadingGenerator(generator)
- bot = CommonscatBot(pregenerator, always, summary)
- bot.run()
+ if generator:
+ pregenerator = pagegenerators.PreloadingGenerator(generator)
+ bot = CommonscatBot(pregenerator, always, summary)
+ bot.run()
+ else:
+ pywikibot.showHelp()
+
if __name__ == "__main__":
main()
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 57f860e..ded3821 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -102,9 +102,7 @@
# Some of these are not pretty, but at least they are informative
# and not backtraces starting deep in the pywikibot package.
no_args_expected_results = {
- 'add_text': 'NoEnoughData',
'archivebot': 'NOTE: you must specify a template to run the bot',
- 'commonscat': 'add_text.NoEnoughData',
'create_categories': 'No pages to work on',
# TODO: until done here, remember to set editor = None in user_config.py
'editarticle': 'Nothing changed', # This masks related bug 68645 but that
@@ -217,9 +215,7 @@
test_name = 'test_' + script_name + '_no_args'
dct[test_name] = test_execution(script_name, ['-simulate'],
no_args_expected_results)
- if script_name in ['add_text', # raises custom NoEnoughData
- 'checkimages', # bug 68613
- 'commonscat', # raises custom NoEnoughData
+ if script_name in ['checkimages', # bug 68613
'data_ingestion', # bug 68611
'disambredir', # quittable auto-run with
# highly variable output.
--
To view, visit https://gerrit.wikimedia.org/r/151971
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I23f8a29ad5864be6ff649ad7a2c59e0810d9c7c3
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: standardize lonelypages.py
......................................................................
standardize lonelypages.py
- LonelyPagesBot extends pywikibot.Bot and uses self.userPut()
with built-in 'always' option
- simplified check for orphan pages
- used the standard NewpagesPageGenerator()
- fix bug 69089
Change-Id: I18f64b215c6b45c9c27813cc116d476acfb51431
---
M scripts/lonelypages.py
1 file changed, 112 insertions(+), 138 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/lonelypages.py b/scripts/lonelypages.py
index 66a7dc6..95b51fb 100644
--- a/scripts/lonelypages.py
+++ b/scripts/lonelypages.py
@@ -21,7 +21,7 @@
-enable: Enable or disable the bot via a Wiki Page.
--disambig: Set a page where the bot save the name of the disambig
+-disambig: Set a page where the bot saves the name of the disambig
pages found (default: skip the pages)
-limit: Set how many pages check.
@@ -43,10 +43,10 @@
#
import re
+import sys
import pywikibot
-from pywikibot import i18n
-from pywikibot import pagegenerators
+from pywikibot import i18n, pagegenerators, Bot
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -54,7 +54,7 @@
'¶ms;': pagegenerators.parameterHelp,
}
-Template = {
+template = {
'ar': u'{{يتيمة|تاريخ={{نسخ:اسم_شهر}} {{نسخ:عام}}}}',
'ca': u'{{Orfe|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}',
'en': u'{{Orphan|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}',
@@ -75,137 +75,91 @@
}
-def main():
- enablePage = None # Check if someone set an enablePage or not
- limit = 50000 # Hope that there aren't so many lonely pages in a project
- generator = None # Check if bot should use default generator or not
- nwpages = False # Check variable for newpages
- always = False # Check variable for always
- disambigPage = None # If no disambigPage given, not use it.
+class LonelyPagesBot(Bot):
+ def __init__(self, generator, **kwargs):
+ self.availableOptions.update({
+ 'enablePage': None, # Check if someone set an enablePage or not
+ 'disambigPage': None, # If no disambigPage given, not use it.
+ })
+ super(LonelyPagesBot, self).__init__(**kwargs)
+ self.generator = generator
- # Arguments!
- local_args = pywikibot.handleArgs()
- genFactory = pagegenerators.GeneratorFactory()
+ # Take the configurations according to our project
+ self.site = pywikibot.Site()
+ if self.getOption('enablePage'):
+ self.options['enablePage'] = pywikibot.Page(
+ self.site, self.getOption('enablePage'))
+ self.comment = i18n.twtranslate(
+ self.site, 'lonelypages-comment-add-template')
+ self.commentdisambig = i18n.twtranslate(
+ self.site, 'lonelypages-comment-add-disambig-template')
+ self.template = i18n.translate(self.site, template)
+ self.exception = i18n.translate(self.site, exception_regex)
+ if self.template is None or self.exception is None:
+ pywikibot.showHelp()
+ sys.exit(u'Missing configuration for site %s' % self.site)
+ # DisambigPage part
+ if self.getOption('disambigPage') is not None:
+ self.disambigpage = pywikibot.Page(self.site, self.getOption('disambigPage'))
+ try:
+ self.disambigtext = self.disambigpage.get()
+ except pywikibot.NoPage:
+ pywikibot.output(u"%s doesn't esist, skip!" % self.disambigpage.title())
+ self.disambigtext = ''
+ except pywikibot.IsRedirectPage:
+ pywikibot.output(u"%s is a redirect, don't use it!"
+ % self.disambigpage.title())
+ self.options['disambigPage'] = None
- for arg in local_args:
- if arg.startswith('-enable'):
- if len(arg) == 7:
- enablePage = pywikibot.input(
- u'Would you like to check if the bot should run or not?')
- else:
- enablePage = arg[8:]
- if arg.startswith('-disambig'):
- if len(arg) == 9:
- disambigPage = pywikibot.input(
- u'In which page should the bot save the disambig pages?')
- else:
- disambigPage = arg[10:]
- elif arg.startswith('-limit'):
- if len(arg) == 6:
- limit = int(pywikibot.input(
- u'How many pages do you want to check?'))
- else:
- limit = int(arg[7:])
- elif arg.startswith('-newpages'):
- if len(arg) == 9:
- nwlimit = 50 # Default: 50 pages
- else:
- nwlimit = int(arg[10:])
- generator = pywikibot.Site().newpages(number=nwlimit)
- nwpages = True
- elif arg == '-always':
- always = True
- else:
- genFactory.handleArg(arg)
- # Retrive the site
- wikiSite = pywikibot.Site()
+ def enable_page(self):
+ enable = self.getOption('enablePage')
+ if enable is not None:
+ try:
+ getenable = enable.get()
+ except pywikibot.NoPage:
+ pywikibot.output(
+ u"%s doesn't esist, I use the page as if it was blank!"
+ % enable.title())
+ getenable = ''
+ except pywikibot.IsRedirectPage:
+ pywikibot.output(u"%s is a redirect, skip!" % enable.title())
+ getenable = ''
+ return getenable == 'enable'
+ return True
- if not generator:
- generator = genFactory.getCombinedGenerator()
-
- # If the generator is not given, use the default one
- if not generator:
- generator = wikiSite.lonelypages(repeat=True, number=limit)
- # Take the configurations according to our project
- comment = i18n.twtranslate(wikiSite, 'lonelypages-comment-add-template')
- commentdisambig = i18n.twtranslate(wikiSite, 'lonelypages-comment-add-disambig-template')
- template = i18n.translate(wikiSite, Template)
- exception = i18n.translate(wikiSite, exception_regex)
- if template is None or exception is None:
- raise Exception("Missing configuration for site %r" % wikiSite)
- # EnablePage part
- if enablePage is not None:
- # Define the Page Object
- enable = pywikibot.Page(wikiSite, enablePage)
- # Loading the page's data
- try:
- getenable = enable.text
- except pywikibot.NoPage:
- pywikibot.output(
- u"%s doesn't esist, I use the page as if it was blank!"
- % enable.title())
- getenable = ''
- except pywikibot.IsRedirectPage:
- pywikibot.output(u"%s is a redirect, skip!" % enable.title())
- getenable = ''
+ def run(self):
# If the enable page is set to disable, turn off the bot
# (useful when the bot is run on a server)
- if getenable != 'enable':
+ if not self.enable_page():
pywikibot.output('The bot is disabled')
return
- # DisambigPage part
- if disambigPage is not None:
- disambigpage = pywikibot.Page(wikiSite, disambigPage)
- try:
- disambigtext = disambigpage.get()
- except pywikibot.NoPage:
- pywikibot.output(u"%s doesn't esist, skip!" % disambigpage.title())
- disambigtext = ''
- except pywikibot.IsRedirectPage:
- pywikibot.output(u"%s is a redirect, don't use it!"
- % disambigpage.title())
- disambigPage = None
- # Main Loop
- for page in generator:
- if nwpages:
- # The newpages generator returns a tuple, not a Page object.
- page = page[0]
+ # Main Loop
+ for page in self.generator:
+ self.treat(page)
+
+ def treat(self, page):
pywikibot.output(u"Checking %s..." % page.title())
if page.isRedirectPage(): # If redirect, skip!
pywikibot.output(u'%s is a redirect! Skip...' % page.title())
- continue
- # refs is not a list, it's a generator while resList... is a list, yes.
- refs = page.getReferences()
- refsList = list()
- for j in refs:
- if j is None:
- # We have to find out why the function returns that value
- pywikibot.error(u'1 --> Skip page')
- continue
- refsList.append(j)
- # This isn't possible with a generator
- if refsList != []:
+ return
+ refs = list(page.getReferences(total=1))
+ if len(refs) > 0:
pywikibot.output(u"%s isn't orphan! Skip..." % page.title())
- continue
- # Never understood how a list can turn in "None", but it happened :-S
- elif refsList is None:
- # We have to find out why the function returns that value
- pywikibot.error(u'2 --> Skip page')
- continue
+ return
else:
# no refs, no redirect; check if there's already the template
try:
oldtxt = page.get()
except pywikibot.NoPage:
pywikibot.output(u"%s doesn't exist! Skip..." % page.title())
- continue
+ return
except pywikibot.IsRedirectPage:
pywikibot.output(u"%s is a redirect! Skip..." % page.title())
- continue
+ return
# I've used a loop in a loop. If I use continue in the second loop,
# it won't do anything in the first. So let's create a variable to
# avoid this problem.
- for regexp in exception:
+ for regexp in self.exception:
res = re.findall(regexp, oldtxt.lower())
# Found a template! Let's skip the page!
if res != []:
@@ -214,40 +168,60 @@
% page.title())
break
else:
- continue
- if page.isDisambig() and disambigPage is not None:
+ return
+ if page.isDisambig() and self.getOption('disambigPage') is not None:
pywikibot.output(u'%s is a disambig page, report..'
% page.title())
- if not page.title().lower() in disambigtext.lower():
- disambigtext = u"%s\n*[[%s]]" % (disambigtext, page.title())
- disambigpage.put(disambigtext, commentdisambig)
- continue
+ if not page.title().lower() in self.disambigtext.lower():
+ self.disambigtext = u"%s\n*[[%s]]" % (self.disambigtext, page.title())
+ self.disambigpage.text = self.disambigtext
+ self.disambigpage.save(self.commentdisambig)
+ return
# Is the page a disambig but there's not disambigPage? Skip!
elif page.isDisambig():
pywikibot.output(u'%s is a disambig page, skip...'
% page.title())
- continue
+ return
else:
# Ok, the page need the template. Let's put it there!
# Adding the template in the text
- newtxt = u"%s\n%s" % (template, oldtxt)
- pywikibot.output(u"\t\t>>> %s <<<" % page.title())
- pywikibot.showDiff(oldtxt, newtxt)
- choice = 'y'
- if not always:
- choice = pywikibot.inputChoice(
- u'Orphan page found, add template?',
- ['Yes', 'No', 'All'], 'yna')
- if choice == 'a':
- always = True
- choice = 'y'
- if choice == 'y':
- page.text = newtxt
- try:
- page.save(comment)
- except pywikibot.EditConflict:
- pywikibot.output(u'Edit Conflict! Skip...')
- continue
+ newtxt = u"%s\n%s" % (self.template, oldtxt)
+ self.userPut(page, oldtxt, newtxt, comment=self.comment)
+
+
+def main():
+ options = {}
+
+ local_args = pywikibot.handleArgs()
+ genFactory = pagegenerators.GeneratorFactory()
+ site = pywikibot.Site()
+
+ for arg in local_args:
+ if arg.startswith('-enable'):
+ if len(arg) == 7:
+ options['enablePage'] = pywikibot.input(
+ u'Would you like to check if the bot should run or not?')
+ else:
+ options['enablePage'] = arg[8:]
+ elif arg.startswith('-disambig'):
+ if len(arg) == 9:
+ options['disambigPage'] = pywikibot.input(
+ u'In which page should the bot save the disambig pages?')
+ else:
+ options['disambigPage'] = arg[10:]
+ elif arg == '-always':
+ options['always'] = True
+ else:
+ genFactory.handleArg(arg)
+
+ generator = genFactory.getCombinedGenerator()
+
+ # If the generator is not given, use the default one
+ if not generator:
+ generator = site.lonelypages(total=genFactory.limit)
+
+ bot = LonelyPagesBot(generator, **options)
+ bot.run()
if __name__ == '__main__':
main()
--
To view, visit https://gerrit.wikimedia.org/r/148941
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I18f64b215c6b45c9c27813cc116d476acfb51431
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Allow pywikibot to load without a user-config.py
......................................................................
Allow pywikibot to load without a user-config.py
Set environment variable PYWIKIBOT2_NO_USER_CONFIG=1
to allow the library to load without a user-config.py
Emits a warning to help triage problems with this
functionality.
Change-Id: I8f77f7634989bef75701ed5cf952844e339c1243
---
M pywikibot/config2.py
1 file changed, 14 insertions(+), 6 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 6103f23..b967973 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -137,6 +137,8 @@
'.pywikibot' directory (Unix and similar) under the user's home
directory.
+ Set PYWIKIBOT2_NO_USER_CONFIG=1 to disable loading user-config.py
+
"""
NAME = "pywikibot"
base_dir = ""
@@ -176,11 +178,13 @@
if not os.path.exists(os.path.join(base_dir, "user-config.py")):
exc_text = ("No user-config.py found in directory '%(base_dir)s'.\n"
% locals())
- exc_text += " Please check that user-config.py is stored in the correct location.\n"
- exc_text += " Directory where user-config.py is searched is determined as follows:\n\n"
- exc_text += " " + _get_base_dir.__doc__
-
- raise RuntimeError(exc_text)
+ if os.environ.get('PYWIKIBOT2_NO_USER_CONFIG', '0') == '1':
+ print(exc_text)
+ else:
+ exc_text += " Please check that user-config.py is stored in the correct location.\n"
+ exc_text += " Directory where user-config.py is searched is determined as follows:\n\n"
+ exc_text += " " + _get_base_dir.__doc__
+ raise RuntimeError(exc_text)
return base_dir
@@ -704,7 +708,11 @@
# Get the user files
_thislevel = 0
-_fns = [os.path.join(_base_dir, "user-config.py")]
+if os.environ.get('PYWIKIBOT2_NO_USER_CONFIG', '0') == '1':
+ print("WARNING: Skipping loading of user-config.py.")
+ _fns = []
+else:
+ _fns = [os.path.join(_base_dir, "user-config.py")]
for _filename in _fns:
_thislevel += 1
if os.path.exists(_filename):
--
To view, visit https://gerrit.wikimedia.org/r/151658
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8f77f7634989bef75701ed5cf952844e339c1243
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Hashar <hashar(a)free.fr>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Bug 68657-claimit without arguments has no output
......................................................................
Bug 68657-claimit without arguments has no output
Added help output.
Change-Id: I8abeae56052dfa78a1cfbac812987d56ec5ad0f1
---
M scripts/claimit.py
M tests/script_tests.py
2 files changed, 9 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/claimit.py b/scripts/claimit.py
index af74030..c8140fa 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -60,6 +60,12 @@
import pywikibot
from pywikibot import pagegenerators, WikidataBot
+# This is required for the text that is shown when you run this script
+# with the parameter -help or without parameters.
+docuReplacements = {
+ '¶ms;': pagegenerators.parameterHelp,
+}
+
class ClaimRobot(WikidataBot):
"""
@@ -190,7 +196,8 @@
generator = gen.getCombinedGenerator()
if not generator:
- # FIXME: Should throw some help
+ # show help text from the top of this file
+ pywikibot.showHelp()
return
bot = ClaimRobot(generator, claims, exists_arg)
diff --git a/tests/script_tests.py b/tests/script_tests.py
index ef151ed..e631458 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -107,6 +107,7 @@
'archivebot': 'NOTE: you must specify a template to run the bot',
'commonscat': 'add_text.NoEnoughData',
'create_categories': 'No pages to work on',
+ # TODO: until done here, remember to set editor = None in user_config.py
'editarticle': 'Nothing changed', # This masks related bug 68645 but that
# bug is more broadly about config
# rather than editarticle.
@@ -220,7 +221,6 @@
if script_name in ['add_text', # raises custom NoEnoughData
'checkimages', # bug 68613
'commonscat', # raises custom NoEnoughData
- 'claimit', # bug 68657 - zero output
'data_ingestion', # bug 68611
'disambredir', # quittable auto-run with
# highly variable output.
--
To view, visit https://gerrit.wikimedia.org/r/151786
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8abeae56052dfa78a1cfbac812987d56ec5ad0f1
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: jenkins-bot <>