jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] Use the "default"-field in Siteinfo to store cache time
......................................................................
[FEAT] Use the "default"-field in Siteinfo to store cache time
This allows Siteinfo to automatically reload after a certain time
has expired. It is also possible to determine the time of the last
request time for each field. As a use case live_version now caches
it for up to a day
The cache time is the time of the request, but the request might be
cached separately (which is the case in the tests) so it's not the
time the server actually send it.
Default values in the caches (siprops which the server didn't support)
are always expired and are always rerequested, except when the expiry
is set to False (that value basically never expires).
Change-Id: Iff4b6a68e4cdf7f3fb5be17d6704d2b23cae2175
---
M pywikibot/site.py
1 file changed, 80 insertions(+), 34 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 5132dfc..9b3a2ee 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -937,7 +937,7 @@
else:
return tools.EMPTY_DEFAULT
- def _get_siteinfo(self, prop, force=False):
+ def _get_siteinfo(self, prop, expiry):
"""
Retrieve a siteinfo property. All properties which the site doesn't
support contain the default value. Because pre-1.12 no data was
@@ -946,8 +946,8 @@
@param prop: The property names of the siteinfo.
@type prop: str or iterable
- @param force: Don't access the cached request.
- @type force: bool
+ @param expiry: The expiry date of the cached request.
+ @type expiry: int (days), L{datetime.timedelta}, False (config)
@return: A dictionary with the properties of the site. Each entry in
the dictionary is a tuple of the value and a boolean to save if it
is the default value.
@@ -962,7 +962,7 @@
raise ValueError('At least one property name must be provided.')
try:
data = pywikibot.data.api.CachedRequest(
- expiry=0 if force else pywikibot.config.API_config_expiry,
+ expiry=pywikibot.config.API_config_expiry if expiry is False else expiry,
site=self._site,
action='query',
meta='siteinfo',
@@ -971,14 +971,14 @@
if e.code == 'siunknown_siprop':
if len(props) == 1:
pywikibot.log(u"Unable to get siprop '{0}'".format(props[0]))
- return {props[0]: (Siteinfo._get_default(props[0]), True)}
+ return {props[0]: (Siteinfo._get_default(props[0]), False)}
else:
pywikibot.log(u"Unable to get siteinfo, because at least "
u"one property is unknown: '{0}'".format(
u"', '".join(props)))
results = {}
for prop in props:
- results.update(self._get_siteinfo(prop, force))
+ results.update(self._get_siteinfo(prop, expiry))
return results
else:
raise
@@ -991,17 +991,26 @@
data['warnings']['siteinfo']['*']).group(1).split(','):
prop = prop.strip()
invalid_properties += [prop]
- result[prop] = (Siteinfo._get_default(prop), True)
+ result[prop] = (Siteinfo._get_default(prop), False)
pywikibot.log(u"Unable to get siprop(s) '{0}'".format(
u"', '".join(invalid_properties)))
if 'query' in data:
- # todo iterate through the properties!
+ cache_time = datetime.datetime.utcnow()
for prop in props:
if prop in data['query']:
- result[prop] = (data['query'][prop], False)
+ result[prop] = (data['query'][prop], cache_time)
return result
- def _get_general(self, key, force):
+ @staticmethod
+ def _is_expired(cache_date, expire):
+ if expire is False: # can never expire
+ return False
+ elif not cache_date: # default values are always expired
+ return True
+ else:
+ return datetime.datetime.utcnow() - expire < cache_date
+
+ def _get_general(self, key, expiry):
"""
Return a siteinfo property which is loaded by default.
@@ -1012,10 +1021,11 @@
@param key: The key to search for.
@type key: str
- @param force: If 'general' should be queried in any case.
- @type force: bool
- @return: If that property was retrived via this method. Returns an
- empty tuple if it wasn't retrieved.
+ @param expiry: If the cache is older than the expiry it ignores the
+ cache and queries the server to get the newest value.
+ @type expiry: int (days), L{datetime.timedelta}, False (never)
+ @return: If that property was retrived via this method. Returns None if
+ the key was not in the retreived values.
@rtype: various (the value), bool (if the default value is used)
"""
if 'general' not in self._cache:
@@ -1023,6 +1033,7 @@
force = True
props = ['namespaces', 'namespacealiases']
else:
+ force = Siteinfo._is_expired(self._cache['general'][1], expiry)
props = []
if force:
props = [prop for prop in props if prop not in self._cache]
@@ -1031,23 +1042,26 @@
u"Load siteinfo properties '{0}' along with 'general'".format(
u"', '".join(props)), _logger)
props += ['general']
- default_info = self._get_siteinfo(props, force)
+ default_info = self._get_siteinfo(props, expiry)
for prop in props:
self._cache[prop] = default_info[prop]
if key in default_info:
return default_info[key]
if key in self._cache['general'][0]:
- return self._cache['general'][0][key], False
+ return self._cache['general'][0][key], self._cache['general']
else:
- return tuple()
+ return None
def __getitem__(self, key):
"""Return a siteinfo property, caching and not forcing it."""
return self.get(key, False) # caches and doesn't force it
- def get(self, key, get_default=True, cache=True, force=False):
+ def get(self, key, get_default=True, cache=True, expiry=False):
"""
Return a siteinfo property.
+
+ It will never throw an APIError if it only stated, that the siteinfo
+ property doesn't exist. Instead it will use the default value.
@param key: The name of the siteinfo property.
@type key: str
@@ -1056,30 +1070,38 @@
@param cache: Caches the result interally so that future accesses via
this method won't query the server.
@type cache: bool
- @param force: Ignores the cache and always queries the server to get
- the newest value.
- @type force: bool
+ @param expiry: If the cache is older than the expiry it ignores the
+ cache and queries the server to get the newest value.
+ @type expiry: int/float (days), L{datetime.timedelta}, False (never)
@return: The gathered property
@rtype: various
+ @raise KeyError: If the key is not a valid siteinfo property and the
+ get_default option is set to False.
@see: L{_get_siteinfo}
"""
- if not force:
+ # expire = 0 (or timedelta(0)) are always expired and their bool is
+ # False, so skip them EXCEPT if it's literally False, then they expire
+ # never: "expiry is False" is different than "not expiry"!
+ if expiry or expiry is False:
+ # if it's a int convert to timedelta
+ if expiry is not False and isinstance(expiry, (int, float)):
+ expiry = datetime.timedelta(expiry)
try:
cached = self._get_cached(key)
except KeyError:
cached = None
- # a not recognised result was cached, but they aren't requested
- if cached:
- if cached[1] and not get_default:
+ else: # cached value available
+ # is a default value, but isn't accepted
+ if not cached[1] and not get_default:
raise KeyError(key)
- else:
+ elif not Siteinfo._is_expired(cached[1], expiry):
return copy.deepcopy(cached[0])
- preloaded = self._get_general(key, force)
+ preloaded = self._get_general(key, expiry)
if not preloaded:
- preloaded = self._get_siteinfo(key, force)[key]
+ preloaded = self._get_siteinfo(key, expiry)[key]
else:
cache = False
- if preloaded[1] and not get_default:
+ if not preloaded[1] and not get_default:
raise KeyError(key)
else:
if cache:
@@ -1090,7 +1112,7 @@
"""Return the cached value or a KeyError exception if not cached."""
if 'general' in self._cache:
if key in self._cache['general'][0]:
- return (self._cache['general'][0][key], False)
+ return self._cache['general'][0][key], self._cache['general'][1]
else:
return self._cache[key]
raise KeyError(key)
@@ -1106,8 +1128,26 @@
def is_recognised(self, key):
"""Return if 'key' is a valid property name. 'None' if not cached."""
+ time = self.get_requested_time(key)
+ if time is None:
+ return None
+ else:
+ return bool(time)
+
+ def get_requested_time(self, key):
+ """
+ Return when 'key' was successfully requested from the server.
+
+ If the property is actually in the siprop 'general' it returns the
+ last request from the 'general' siprop.
+
+ @param key: The siprop value or a property of 'general'.
+ @type key: basestring
+ @return: The last time the siprop of 'key' was requested.
+ @rtype: None (never), False (default), L{datetime.datetime} (cached)
+ """
try:
- return not self._get_cached(key)[1]
+ return self._get_cached(key)[1]
except KeyError:
return None
@@ -1806,12 +1846,18 @@
def live_version(self, force=False):
"""Return the 'real' version number found on [[Special:Version]].
- Return value is a tuple (int, int, str) of the major and minor
- version numbers and any other text contained in the version.
+ By default the version number is cached for one day.
+ @param force: If the version should be read always from the server and
+ never from the cache.
+ @type force: bool
+ @return: A tuple containing the major, minor version number and any
+ text after that. If an error occured (0, 0, 0) is returned.
+ @rtype: int, int, str
"""
try:
- versionstring = self.siteinfo.get('generator', force=force)
+ versionstring = self.siteinfo.get('generator',
+ expiry=0 if force else 1)
m = re.match(r"^MediaWiki ([0-9]+)\.([0-9]+)(.*)$", versionstring)
if m:
return (int(m.group(1)), int(m.group(2)), m.group(3))
--
To view, visit https://gerrit.wikimedia.org/r/155097
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iff4b6a68e4cdf7f3fb5be17d6704d2b23cae2175
Gerrit-PatchSet: 11
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] One hasExtension() call was overlooked
......................................................................
[FIX] One hasExtension() call was overlooked
Change-Id: I0dfb3304f7a848df2da4ea3746b6adc2a1576bd9
---
M tests/page_tests.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/page_tests.py b/tests/page_tests.py
index dca5d2f..0c6c259 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -311,7 +311,7 @@
Test the integration with
Extension:Disambiguator
"""
- if not site.hasExtension('Disambiguator', False):
+ if not site.has_extension('Disambiguator'):
raise unittest.SkipTest('Disambiguator extension not loaded on test site')
pg = pywikibot.Page(site, 'Random')
pg._pageprops = set(['disambiguation', ''])
--
To view, visit https://gerrit.wikimedia.org/r/155250
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0dfb3304f7a848df2da4ea3746b6adc2a1576bd9
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Disable script makecat in tests
......................................................................
Disable script makecat in tests
The makecat script needs to be disabled until bug 69781 is
resolved.
Change-Id: I39d0c868f8f81f9ddb358b57b63e2a1a23d2838e
---
M tests/script_tests.py
1 file changed, 1 insertion(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 7e0100d..b229222 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -58,6 +58,7 @@
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
+ and name != 'makecat.py' # bug 69781
]
return ['login'] + script_list
--
To view, visit https://gerrit.wikimedia.org/r/155240
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I39d0c868f8f81f9ddb358b57b63e2a1a23d2838e
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: 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: Decoding text: catch exception
......................................................................
Decoding text: catch exception
Wrapped the decode instruction derived from
change Ia2051a2a80851b15b1a04a135763291bd633d4e3
in a "try: except:" block, as suggested in comment 9 of bug 67410
Also: added a comma in "self.CHARSET" regex in case of
"contentType" contains a list of value from HTML-meta
Change-Id: I3af86d3386ea919001287fe1c057932c16537eb4
---
M scripts/reflinks.py
1 file changed, 6 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 65dcb5b..a7f50f0 100644
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -434,7 +434,7 @@
# Regex to grasp content-type meta HTML tag in HTML source
self.META_CONTENT = re.compile(r'(?i)<meta[^>]*content\-type[^>]*>')
# Extract the encoding from a charset property (from content-type !)
- self.CHARSET = re.compile(r'(?i)charset\s*=\s*(?P<enc>[^\'";>/]*)')
+ self.CHARSET = re.compile(r'(?i)charset\s*=\s*(?P<enc>[^\'",;>/]*)')
# Extract html title from page
self.TITLE = re.compile(r'(?is)(?<=<title>).*?(?=</title>)')
# Matches content inside <script>/<style>/HTML comments
@@ -683,7 +683,11 @@
if 'utf-8' not in enc:
enc.append('utf-8')
- u = linkedpagetext.decode(enc[0]) # Bug 67410
+ try:
+ u = linkedpagetext.decode(enc[0]) # Bug 67410
+ except (UnicodeDecodeError, LookupError) as e:
+ pywikibot.output(u'%s : Decoding error - %s' % (ref.link, e))
+ continue
# Retrieves the first non empty string inside <title> tags
for m in self.TITLE.finditer(u):
--
To view, visit https://gerrit.wikimedia.org/r/155226
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3af86d3386ea919001287fe1c057932c16537eb4
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Beta16 <l.rabinelli(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: Pep257 on scripts folder
......................................................................
Pep257 on scripts folder
Done by a script I wrote, checked manually
Change-Id: I139407f9ea1789e66342d37b6f2b67e8ea674a5f
---
M scripts/archivebot.py
M scripts/blockpageschecker.py
M scripts/blockreview.py
M scripts/category.py
M scripts/category_redirect.py
M scripts/checkimages.py
M scripts/claimit.py
M scripts/commonscat.py
M scripts/cosmetic_changes.py
M scripts/create_categories.py
M scripts/data_ingestion.py
M scripts/editarticle.py
M scripts/featured.py
M scripts/fixing_redirects.py
M scripts/flickrripper.py
M scripts/harvest_template.py
M scripts/illustrate_wikidata.py
M scripts/image.py
M scripts/imagerecat.py
M scripts/interwiki.py
M scripts/isbn.py
M scripts/makecat.py
M scripts/newitem.py
M scripts/noreferences.py
M scripts/pagefromfile.py
M scripts/reflinks.py
M scripts/replace.py
M scripts/replicate_wiki.py
M scripts/solve_disambiguation.py
M scripts/template.py
M scripts/transferbot.py
M scripts/upload.py
M scripts/weblinkchecker.py
M scripts/welcome.py
34 files changed, 167 insertions(+), 199 deletions(-)
Approvals:
XZise: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 5b10838..b56c6c5 100644
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -101,8 +101,10 @@
class MissingConfigError(pywikibot.Error):
+
"""The config is missing in the header (either it's in one of the threads
- or transcluded from another page)."""
+ or transcluded from another page).
+ """
class AlgorithmError(MalformedConfigError):
@@ -110,8 +112,10 @@
class ArchiveSecurityError(pywikibot.Error):
+
"""Archive is not a subpage of page being archived and key not specified
- (or incorrect)."""
+ (or incorrect).
+ """
def str2localized_duration(site, string):
@@ -133,7 +137,8 @@
"""Accepts a string defining a time period:
7d - 7 days
36h - 36 hours
- Returns the corresponding timedelta object."""
+ Returns the corresponding timedelta object.
+ """
if string.endswith('d'):
return datetime.timedelta(days=int(string[:-1]))
elif string.endswith('h'):
@@ -172,9 +177,8 @@
class TZoneUTC(datetime.tzinfo):
- """
- Class building a UTC tzinfo object
- """
+
+ """Class building a UTC tzinfo object."""
def utcoffset(self, dt):
return ZERO
@@ -190,6 +194,7 @@
class DiscussionThread(object):
+
"""An object representing a discussion thread on a page, that is something
of the form:
@@ -250,8 +255,10 @@
class DiscussionPage(pywikibot.Page):
+
"""A class that represents a single discussion page as well as an archive
- page. Feed threads to it and run an update() afterwards."""
+ page. Feed threads to it and run an update() afterwards.
+ """
def __init__(self, source, archiver, params=None):
super(DiscussionPage, self).__init__(source)
@@ -339,9 +346,11 @@
class PageArchiver(object):
+
"""A class that encapsulates all archiving methods.
__init__ expects a pywikibot.Page object.
- Execute by running the .run() method."""
+ Execute by running the .run() method.
+ """
algo = 'none'
diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py
index 9297349..0417458 100755
--- a/scripts/blockpageschecker.py
+++ b/scripts/blockpageschecker.py
@@ -158,7 +158,7 @@
def understandBlock(text, TTP, TSP, TSMP, TTMP, TU):
- """ Understand if the page is blocked and if it has the right template """
+ """Understand if the page is blocked and if it has the right template."""
if TTP:
for catchRegex in TTP: # TTP = templateTotalProtection
resultCatch = re.findall(catchRegex, text)
@@ -206,7 +206,7 @@
def main():
- """ Main Function """
+ """Main Function."""
# Loading the comments
global categoryToCheck, project_inserted
# always, define a generator to understand if the user sets one,
diff --git a/scripts/blockreview.py b/scripts/blockreview.py
index 09e9f02..8cba078 100644
--- a/scripts/blockreview.py
+++ b/scripts/blockreview.py
@@ -109,9 +109,7 @@
% page.title(asLink=True))
def treat(self, userPage):
- """
- Loads the given page, does some changes, and saves it.
- """
+ """Loads the given page, does some changes, and saves it."""
talkText = self.load(userPage)
if not talkText:
# sanity check. No talk page found.
@@ -259,9 +257,7 @@
defaultNamespace=3)
def load(self, page):
- """
- Loads the given page, does some changes, and saves it.
- """
+ """Loads the given page, does some changes, and saves it."""
try:
# Load the page
text = page.get()
diff --git a/scripts/category.py b/scripts/category.py
index c511759..08588d4 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -296,7 +296,8 @@
def load(self, page):
"""Load the given page's content.
- If page doesn't exists returns an empty string."""
+ If page doesn't exists returns an empty string.
+ """
try:
# Load the page
text = page.get()
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py
index e5a394c..d7d9b81 100755
--- a/scripts/category_redirect.py
+++ b/scripts/category_redirect.py
@@ -80,7 +80,7 @@
self.site.code, 'category_redirect-edit-request-item')
def move_contents(self, oldCatTitle, newCatTitle, editSummary):
- """The worker function that moves pages out of oldCat into newCat"""
+ """The worker function that moves pages out of oldCat into newCat."""
while True:
try:
oldCat = pywikibot.Category(self.site,
@@ -168,7 +168,7 @@
return log_text
def run(self):
- """Run the bot"""
+ """Run the bot."""
global destmap, catlist, catmap
# user() invokes login()
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index c1ba117..77e6caf 100644
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -559,6 +559,7 @@
class LogIsFull(pywikibot.Error):
+
"""An exception indicating that the log is full and the Bot cannot add
other data to prevent Errors.
@@ -566,6 +567,7 @@
class NothingFound(pywikibot.Error):
+
""" An exception indicating that a regex has return [] instead of results.
"""
@@ -592,7 +594,7 @@
def __init__(self, site, logFulNumber=25000, sendemailActive=False,
duplicatesReport=False, logFullError=True):
- """ Constructor, define some global variable """
+ """Constructor, define some global variable."""
self.site = site
self.logFullError = logFullError
self.logFulNumber = logFulNumber
@@ -688,7 +690,7 @@
break
def uploadBotChangeFunction(self, reportPageText, upBotArray):
- """Detect the user that has uploaded the file through the upload bot"""
+ """Detect the user that has uploaded the file through the upload bot."""
regex = upBotArray[1]
results = re.findall(regex, reportPageText)
@@ -866,7 +868,7 @@
yield pywikibot.FilePage(self.site, image)
def loadHiddenTemplates(self):
- """ Function to load the white templates """
+ """Function to load the white templates."""
# A template as {{en is not a license! Adding also them in the
# whitelist template...
for langK in pywikibot.site.Family('wikipedia').langs.keys():
@@ -885,7 +887,7 @@
return self.hiddentemplates
def returnOlderTime(self, listGiven, timeListGiven):
- """ Get some time and return the oldest of them """
+ """Get some time and return the oldest of them."""
num = 0
num_older = None
max_usage = 0
@@ -942,7 +944,7 @@
return number_edits
def checkImageOnCommons(self):
- """ Checking if the file is on commons """
+ """Checking if the file is on commons."""
pywikibot.output(u'Checking if [[%s]] is on commons...'
% self.imageName)
commons_site = pywikibot.Site('commons', 'commons')
@@ -1275,7 +1277,7 @@
return self.settingsData # Useless, but it doesn't harm..
def load_licenses(self):
- """ Load the list of the licenses """
+ """Load the list of the licenses."""
## catName = i18n.translate(self.site, category_with_licenses)
## cat = pywikibot.Category(pywikibot.Site(), catName)
## categories = [page.title() for page in pagegenerators.SubCategoriesPageGenerator(cat)]
@@ -1761,7 +1763,7 @@
def main():
- """ Main function """
+ """Main function."""
# Command line configurable parameters
repeat = True # Restart after having check all the images?
limit = 80 # How many images check?
diff --git a/scripts/claimit.py b/scripts/claimit.py
index c8140fa..0dfa761 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -86,9 +86,7 @@
self.cacheSources()
def run(self):
- """
- Starts the robot.
- """
+ """Starts the robot."""
if self.exists_arg:
pywikibot.output('\'exists\' argument set to \'%s\'' % self.exists_arg)
for page in self.generator:
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 6a28ffc..48f9591 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -418,9 +418,7 @@
return u''
def getCommonscatLink(self, wikipediaPage=None):
- """
- Go through the page and return a tuple of (<templatename>, <target>)
- """
+ """Go through the page and return a tuple of (<templatename>, <target>)"""
primaryCommonscat, commonscatAlternatives = self.getCommonscatTemplate(
wikipediaPage.site.code)
commonscatTemplate = u''
@@ -504,7 +502,6 @@
""" Parse the command line arguments and get a pagegenerator to work on.
Iterate through all the pages.
"""
-
summary = None
generator = None
checkcurrent = False
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index aaf3b52..b6ba0e1 100755
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -159,9 +159,7 @@
self.title = pageTitle
def change(self, text):
- """
- Given a wiki source code text, return the cleaned up version.
- """
+ """Given a wiki source code text, return the cleaned up version."""
oldText = text
if self.site.sitename() == u'commons:commons' and self.namespace == 6:
text = self.commonsfiledesc(text)
@@ -315,9 +313,7 @@
return text
def translateAndCapitalizeNamespaces(self, text):
- """
- Makes sure that localized namespace names are used.
- """
+ """Makes sure that localized namespace names are used."""
# arz uses english stylish codes
if self.site.sitename() == 'wikipedia:arz':
return text
@@ -362,9 +358,7 @@
return text
def translateMagicWords(self, text):
- """
- Makes sure that localized namespace names are used.
- """
+ """Makes sure that localized namespace names are used."""
# not wanted at ru
# arz uses english stylish codes
if self.site.code not in ['arz', 'ru']:
diff --git a/scripts/create_categories.py b/scripts/create_categories.py
index d57cfd8..7294a57 100755
--- a/scripts/create_categories.py
+++ b/scripts/create_categories.py
@@ -73,9 +73,7 @@
def main():
- """
- Main loop. Get a generator and options.
- """
+ """Main loop. Get a generator and options."""
parent = None
basename = None
options = {}
diff --git a/scripts/data_ingestion.py b/scripts/data_ingestion.py
index ecc6052..58a0286 100755
--- a/scripts/data_ingestion.py
+++ b/scripts/data_ingestion.py
@@ -1,8 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-"""
-A generic bot to do data ingestion (batch uploading) to Commons
-"""
+"""A generic bot to do data ingestion (batch uploading) to Commons"""
#
# (C) Pywikibot team, 2013
#
@@ -23,6 +21,7 @@
class Photo(object):
+
"""
Represents a Photo (or other file), with metadata, to upload to Commons.
@@ -75,10 +74,7 @@
return fmt % self.metadata
def getDescription(self, template, extraparams={}):
- """
- Generate a description for a file
- """
-
+ """Generate a description for a file."""
params = {}
params.update(self.metadata)
params.update(extraparams)
diff --git a/scripts/editarticle.py b/scripts/editarticle.py
index 4208e90..15b6eb2 100755
--- a/scripts/editarticle.py
+++ b/scripts/editarticle.py
@@ -38,7 +38,7 @@
self.site = pywikibot.Site()
def set_options(self, *args):
- """Parse commandline and set options attribute"""
+ """Parse commandline and set options attribute."""
my_args = []
for arg in pywikibot.handleArgs(*args):
my_args.append(arg)
@@ -58,7 +58,7 @@
self.options.page = args[0]
def setpage(self):
- """Sets page and page title"""
+ """Sets page and page title."""
site = pywikibot.Site()
pageTitle = self.options.page or pywikibot.input(u"Page to edit:")
self.page = pywikibot.Page(pywikibot.Link(pageTitle, site))
diff --git a/scripts/featured.py b/scripts/featured.py
index 860190c..6893f96 100644
--- a/scripts/featured.py
+++ b/scripts/featured.py
@@ -206,8 +206,7 @@
# The values are the default values
def __init__(self, **kwargs):
- """ Only accepts options defined in availableOptions """
-
+ """Only accepts options defined in availableOptions."""
self.availableOptions.update({
'async': False, # asynchron putting a page?
'afterpage': u"!",
@@ -244,8 +243,7 @@
self.tasks = ['featured']
def itersites(self, task):
- """ generator for site codes to be processed """
-
+ """generator for site codes to be processed."""
def _generator():
if task == 'good':
item_no = good_name['wikidata'][1]
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index 0cc37d4..3e13a6e 100644
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -62,9 +62,7 @@
def treat(text, linkedPage, targetPage):
- """
- Based on the method of the same name in solve_disambiguation.py
- """
+ """Based on the method of the same name in solve_disambiguation.py."""
mysite = pywikibot.Site()
linktrail = mysite.linktrail()
diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py
index 98bad39..37a8808 100644
--- a/scripts/flickrripper.py
+++ b/scripts/flickrripper.py
@@ -95,7 +95,6 @@
TODO: Maybe add more licenses
"""
-
license = photoInfo.find('photo').attrib['license']
if flickr_allowed_license[int(license)]:
return True
@@ -104,9 +103,7 @@
def getPhotoUrl(photoSizes=None):
- """
- Get the url of the jpg file with the highest resolution
- """
+ """Get the url of the jpg file with the highest resolution."""
url = ''
# The assumption is that the largest image is last
for size in photoSizes.find('sizes').findall('size'):
@@ -139,7 +136,7 @@
def getTags(photoInfo=None):
- """ Get all the tags on a photo """
+ """Get all the tags on a photo."""
result = []
for tag in photoInfo.find('photo').find('tags').findall('tag'):
result.append(tag.text.lower())
@@ -263,7 +260,7 @@
def processPhoto(flickr=None, photo_id=u'', flickrreview=False, reviewer=u'',
override=u'', addCategory=u'', removeCategories=False,
autonomous=False):
- """ Process a single Flickr photo """
+ """Process a single Flickr photo."""
if photo_id:
pywikibot.output(str(photo_id))
(photoInfo, photoSizes) = getPhoto(flickr, photo_id)
@@ -314,7 +311,9 @@
class Tkdialog:
+
""" The user dialog. """
+
def __init__(self, photoDescription, photo, filename):
self.root = Tk()
# "%dx%d%+d%+d" % (width, height, xoffset, yoffset)
@@ -370,7 +369,7 @@
self.descriptionScrollbar.grid(row=14, column=5)
def getImage(self, photo, width, height):
- """ Take the StringIO object and build an imageTK thumbnail """
+ """Take the StringIO object and build an imageTK thumbnail."""
image = Image.open(photo)
image.thumbnail((width, height))
imageTk = ImageTk.PhotoImage(image)
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 6224e24..fd61850 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -57,9 +57,7 @@
self.cacheSources()
def run(self):
- """
- Starts the robot.
- """
+ """Starts the robot."""
self.templateTitles = self.getTemplateSynonyms(self.templateTitle)
for page in self.generator:
try:
@@ -68,9 +66,7 @@
pywikibot.exception(msg=e, tb=True)
def getTemplateSynonyms(self, title):
- """
- Fetches redirects of the title, so we can check against them
- """
+ """Fetches redirects of the title, so we can check against them."""
temp = pywikibot.Page(pywikibot.Site(), title, ns=10)
if not temp.exists():
pywikibot.error(u'Template %s does not exist.' % temp.title())
@@ -111,9 +107,7 @@
return linked_item
def processPage(self, page):
- """
- Process a single page
- """
+ """Process a single page."""
item = pywikibot.ItemPage.fromPage(page)
pywikibot.output('Processing %s' % page)
if not item.exists():
diff --git a/scripts/illustrate_wikidata.py b/scripts/illustrate_wikidata.py
index cf6cdaf..a1b25f9 100644
--- a/scripts/illustrate_wikidata.py
+++ b/scripts/illustrate_wikidata.py
@@ -48,9 +48,7 @@
% (self.wdproperty, claim.type))
def run(self):
- """
- Starts the bot.
- """
+ """Starts the bot."""
for page in self.generator:
pywikibot.output(u'Working on %s' % page.title())
item = pywikibot.ItemPage.fromPage(page)
diff --git a/scripts/image.py b/scripts/image.py
index 9d2ffc8..1bcb42b 100644
--- a/scripts/image.py
+++ b/scripts/image.py
@@ -48,10 +48,12 @@
class ImageRobot(Bot):
+
"""
This bot will load all pages yielded by a file links image page generator and
replace or remove all occurences of the old image.
"""
+
# Summary messages for replacing images
msg_replace = {
'ar': u'روبوت - استبدال الصورة %s مع %s',
@@ -130,9 +132,7 @@
% self.old_image
def run(self):
- """
- Start the bot's action.
- """
+ """Start the bot's action."""
# regular expression to find the original template.
# {{vfd}} does the same thing as {{Vfd}}, so both will be found.
# The old syntax, {{msg:vfd}}, will also be found.
diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py
index f000a59..fbeee07 100644
--- a/scripts/imagerecat.py
+++ b/scripts/imagerecat.py
@@ -50,9 +50,7 @@
def initLists():
- """
- Get the list of countries & the blacklist from Commons.
- """
+ """Get the list of countries & the blacklist from Commons."""
global category_blacklist
global countries
@@ -99,7 +97,7 @@
def getCurrentCats(imagepage):
- """ Get the categories currently on the image """
+ """Get the categories currently on the image."""
result = []
for cat in imagepage.categories():
result.append(cat.title(withNamespace=False))
@@ -185,9 +183,7 @@
def getOpenStreetMapCats(latitude, longitude):
- """
- Get a list of location categories based on the OSM nomatim tool
- """
+ """Get a list of location categories based on the OSM nomatim tool."""
result = []
locationList = getOpenStreetMap(latitude, longitude)
for i in range(0, len(locationList)):
@@ -262,7 +258,7 @@
def getUsage(use):
- """ Parse the Commonsense output to get the usage """
+ """Parse the Commonsense output to get the usage."""
result = []
lang = ''
project = ''
@@ -409,9 +405,7 @@
def removeTemplates(oldtext=u''):
- """
- Remove {{Uncategorized}} and {{Check categories}} templates
- """
+ """Remove {{Uncategorized}} and {{Check categories}} templates."""
result = re.sub(
u'\{\{\s*([Uu]ncat(egori[sz]ed( image)?)?|[Nn]ocat|[Nn]eedscategory)[^}]*\}\}', u'', oldtext)
result = re.sub(u'<!-- Remove this line once you have added categories -->',
@@ -421,9 +415,7 @@
def getCheckCategoriesTemplate(usage, galleries, ncats):
- """
- Build the check categories template with all parameters
- """
+ """Build the check categories template with all parameters."""
result = u'{{Check categories|year={{subst:CURRENTYEAR}}|month={{subst:CURRENTMONTHNAME}}|day={{subst:CURRENTDAY}}\n'
usageCounter = 1
for (lang, project, article) in usage:
@@ -442,9 +434,7 @@
def main():
- """
- Main loop. Get a generator and options. Work on all images in the generator.
- """
+ """Main loop. Get a generator and options. Work on all images in the generator."""
generator = None
onlyFilter = False
onlyUncat = False
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 8739377..1691c4f 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -362,12 +362,12 @@
class SaveError(pywikibot.Error):
- """
- An attempt to save a page with changed interwiki has failed.
- """
+
+ """An attempt to save a page with changed interwiki has failed."""
class LinkMustBeRemoved(SaveError):
+
"""
An interwiki link has to be removed, but this can't be done because of user
preferences or because the user chose not to change the page.
@@ -375,9 +375,8 @@
class GiveUpOnPage(pywikibot.Error):
- """
- The user chose not to work on this page and its linked pages any more.
- """
+
+ """The user chose not to work on this page and its linked pages any more."""
# Subpage templates. Must be in lower case,
@@ -451,10 +450,12 @@
class Global(object):
+
"""
Container class for global settings.
Use of globals outside of this is to be avoided.
"""
+
autonomous = False
confirm = False
always = False
@@ -498,7 +499,7 @@
repository = False
def readOptions(self, arg):
- """ Read all commandline parameters for the global container """
+ """Read all commandline parameters for the global container."""
if arg == '-noauto':
self.auto = False
elif arg.startswith('-hint:'):
@@ -618,6 +619,7 @@
class StoredPage(pywikibot.Page):
+
"""
Store the Page contents on disk to avoid sucking too much
memory when a big number of Page objects will be loaded
@@ -687,10 +689,12 @@
class PageTree(object):
+
"""
Structure to manipulate a set of pages.
Allows filtering efficiently by Site.
"""
+
def __init__(self):
# self.tree :
# Dictionary:
@@ -716,9 +720,7 @@
self.size = 0
def filter(self, site):
- """
- Iterates over pages that are in Site site
- """
+ """Iterates over pages that are in Site site."""
try:
for page in self.tree[site]:
yield page
@@ -743,9 +745,7 @@
pass
def removeSite(self, site):
- """
- Removes all pages from Site site
- """
+ """Removes all pages from Site site."""
try:
self.size -= len(self.tree[site])
del self.tree[site]
@@ -753,9 +753,7 @@
pass
def siteCounts(self):
- """
- Yields (Site, number of pages in site) pairs
- """
+ """Yields (Site, number of pages in site) pairs"""
for site, d in self.tree.items():
yield site, len(d)
@@ -766,6 +764,7 @@
class Subject(object):
+
"""
Class to follow the progress of a single 'subject' (i.e. a page with
all its translations)
@@ -825,8 +824,8 @@
def __init__(self, originPage=None, hints=None):
"""Constructor. Takes as arguments the Page on the home wiki
- plus optionally a list of hints for translation"""
-
+ plus optionally a list of hints for translation
+ """
if globalvar.contentsondisk:
if originPage:
originPage = StoredPage(originPage)
@@ -908,7 +907,7 @@
return page
def translate(self, hints=None, keephintedsites=False):
- """Add the given translation hints to the todo list"""
+ """Add the given translation hints to the todo list."""
if globalvar.same and self.originPage:
if hints:
links = titletranslate.translate(
@@ -970,9 +969,7 @@
return result
def makeForcedStop(self, counter):
- """
- Ends work on the page before the normal end.
- """
+ """Ends work on the page before the normal end."""
for site, count in self.todo.siteCounts():
counter.minus(site, count)
self.todo = PageTree()
@@ -1798,9 +1795,7 @@
del page._contents
def replaceLinks(self, page, newPages):
- """
- Returns True if saving was successful.
- """
+ """Returns True if saving was successful."""
if globalvar.localonly:
# In this case only continue on the Page we started with
if page != self.originPage:
@@ -2096,7 +2091,7 @@
self.generated = 0
def add(self, page, hints=None):
- """Add a single subject to the list"""
+ """Add a single subject to the list."""
subj = Subject(page, hints=hints)
self.subjects.append(subj)
for site, count in subj.openSites():
@@ -2105,7 +2100,8 @@
def setPageGenerator(self, pageGenerator, number=None, until=None):
"""Add a generator of subjects. Once the list of subjects gets
- too small, this generator is called to produce more Pages"""
+ too small, this generator is called to produce more Pages
+ """
self.pageGenerator = pageGenerator
self.generateNumber = number
self.generateUntil = until
@@ -2131,7 +2127,8 @@
def generateMore(self, number):
"""Generate more subjects. This is called internally when the
list of subjects becomes too small, but only if there is a
- PageGenerator"""
+ PageGenerator
+ """
fs = self.firstSubject()
if fs and (not globalvar.quiet):
pywikibot.output(u"NOTE: The first unfinished subject is %s"
@@ -2193,7 +2190,7 @@
break
def firstSubject(self):
- """Return the first subject that is still being worked on"""
+ """Return the first subject that is still being worked on."""
if self.subjects:
return self.subjects[0]
@@ -2201,7 +2198,8 @@
"""Return the site that has the most
open queries plus the number. If there is nothing left, return
None. Only languages that are TODO for the first Subject
- are returned."""
+ are returned.
+ """
max = 0
maxlang = None
if not self.firstSubject():
@@ -2305,22 +2303,22 @@
del self.subjects[i]
def isDone(self):
- """Check whether there is still more work to do"""
+ """Check whether there is still more work to do."""
return len(self) == 0 and self.pageGenerator is None
def plus(self, site, count=1):
- """This is a routine that the Subject class expects in a counter"""
+ """This is a routine that the Subject class expects in a counter."""
try:
self.counts[site] += count
except KeyError:
self.counts[site] = count
def minus(self, site, count=1):
- """This is a routine that the Subject class expects in a counter"""
+ """This is a routine that the Subject class expects in a counter."""
self.counts[site] -= count
def run(self):
- """Start the process until finished"""
+ """Start the process until finished."""
while not self.isDone():
self.queryStep()
diff --git a/scripts/isbn.py b/scripts/isbn.py
index 6664394..ac67dac 100755
--- a/scripts/isbn.py
+++ b/scripts/isbn.py
@@ -1160,7 +1160,7 @@
class InvalidIsbnException(pywikibot.Error):
- """Invalid ISBN"""
+ """Invalid ISBN."""
class ISBN:
@@ -1169,9 +1169,7 @@
"""
def format(self):
- """
- Puts hyphens into this ISBN number.
- """
+ """Puts hyphens into this ISBN number."""
result = ''
rest = ''
for digit in self.digits():
@@ -1221,9 +1219,7 @@
return ['978', '979']
def digits(self):
- """
- Returns a list of the digits in the ISBN code.
- """
+ """Returns a list of the digits in the ISBN code."""
result = []
for c in self.code:
if c.isdigit():
@@ -1260,9 +1256,7 @@
return []
def digits(self):
- """
- Returns a list of the digits and Xs in the ISBN code.
- """
+ """Returns a list of the digits and Xs in the ISBN code."""
result = []
for c in self.code:
if c.isdigit() or c in 'Xx':
@@ -1335,9 +1329,7 @@
def _hyphenateIsbnNumber(match):
- """
- Helper function to deal with a single ISBN
- """
+ """Helper function to deal with a single ISBN."""
code = match.group('code')
try:
i = getIsbn(code)
@@ -1355,9 +1347,7 @@
def _isbn10toIsbn13(match):
- """
- Helper function to deal with a single ISBN
- """
+ """Helper function to deal with a single ISBN."""
code = match.group('code')
try:
i = getIsbn(code)
diff --git a/scripts/makecat.py b/scripts/makecat.py
index 4eed250..c67fbef 100644
--- a/scripts/makecat.py
+++ b/scripts/makecat.py
@@ -47,7 +47,7 @@
def isdate(s):
- """returns true if s is a date or year """
+ """returns true if s is a date or year."""
dict, val = date.getAutoFormat(pywikibot.Site().language(), s)
return dict is not None
diff --git a/scripts/newitem.py b/scripts/newitem.py
index eefcf4b..7169de4 100644
--- a/scripts/newitem.py
+++ b/scripts/newitem.py
@@ -35,8 +35,7 @@
""" A bot to create new items """
def __init__(self, generator, **kwargs):
- """ Only accepts options defined in availableOptions """
-
+ """Only accepts options defined in availableOptions."""
self.availableOptions.update({
'lastedit': 7,
'pageage': 21,
diff --git a/scripts/noreferences.py b/scripts/noreferences.py
index be337ec..dde9bfd 100755
--- a/scripts/noreferences.py
+++ b/scripts/noreferences.py
@@ -423,11 +423,13 @@
class XmlDumpNoReferencesPageGenerator:
+
"""
Generator which will yield Pages that might lack a references tag.
These pages will be retrieved from a local XML dump file
(pages-articles or pages-meta-current).
"""
+
def __init__(self, xmlFilename):
"""
Arguments:
@@ -476,9 +478,7 @@
self.referencesText = u'<references />'
def lacksReferences(self, text):
- """
- Checks whether or not the page is lacking a references tag.
- """
+ """Checks whether or not the page is lacking a references tag."""
oldTextCleaned = textlib.removeDisabledParts(text)
if self.referencesR.search(oldTextCleaned) or \
self.referencesTagR.search(oldTextCleaned):
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index 8753db6..7c2f482 100644
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -59,12 +59,15 @@
class NoTitle(Exception):
- """No title found"""
+
+ """No title found."""
+
def __init__(self, offset):
self.offset = offset
class PageFromFileRobot(Bot):
+
"""
Responsible for writing pages to the wiki, with the titles and contents
given by a PageFromFileReader.
@@ -153,6 +156,7 @@
class PageFromFileReader:
+
"""
Responsible for reading the file.
@@ -163,7 +167,6 @@
def __init__(self, filename, pageStartMarker, pageEndMarker,
titleStartMarker, titleEndMarker, include, notitle):
"""Constructor.
-
Check if self.file name exists. If not, ask for a new filename.
User can quit.
@@ -179,7 +182,6 @@
def run(self):
"""Read file and yield page title and content."""
-
pywikibot.output('\n\nReading \'%s\'...' % self.filename)
try:
f = codecs.open(self.filename, 'r',
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 7293945..65dcb5b 100644
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -171,7 +171,8 @@
class XmlDumpPageGenerator:
- """Xml generator that yiels pages containing bare references"""
+
+ """Xml generator that yiels pages containing bare references."""
def __init__(self, xmlFilename, xmlStart, namespaces):
self.xmlStart = xmlStart
@@ -204,7 +205,8 @@
class RefLink:
- """Container to handle a single bare reference"""
+
+ """Container to handle a single bare reference."""
def __init__(self, link, name):
self.refname = name
@@ -215,22 +217,22 @@
self.title = None
def refTitle(self):
- """Return the <ref> with its new title"""
+ """Return the <ref> with its new title."""
return '<ref%s>[%s %s<!-- %s -->]</ref>' % (self.refname, self.link,
self.title,
self.linkComment)
def refLink(self):
- """No title has been found, return the unbracketed link"""
+ """No title has been found, return the unbracketed link."""
return '<ref%s>%s</ref>' % (self.refname, self.link)
def refDead(self):
- """Dead link, tag it with a {{dead link}}"""
+ """Dead link, tag it with a {{dead link}}."""
tag = i18n.translate(self.site, deadLinkTag) % self.link
return '<ref%s>%s</ref>' % (self.refname, tag)
def transform(self, ispdf=False):
- """Normalize the title"""
+ """Normalize the title."""
# convert html entities
if not ispdf:
self.title = pywikibot.html2unicode(self.title)
@@ -275,6 +277,7 @@
class DuplicateReferences:
+
""" When some references are duplicated in an article,
name the first, and remove the content of the others
@@ -387,10 +390,7 @@
class ReferencesRobot(Bot):
def __init__(self, generator, **kwargs):
- """
- - generator : Page generator
-
- """
+ """- generator : Page generator."""
self.availableOptions.update({
'ignorepdf': False, # boolean
'limit': None, # int, stop after n modified pages
@@ -446,7 +446,7 @@
r'application/(?:xhtml\+xml|xml)|text/(?:ht|x)ml')
def httpError(self, err_num, link, pagetitleaslink):
- """Log HTTP Error"""
+ """Log HTTP Error."""
pywikibot.output(u'HTTP error (%s) for %s on %s'
% (err_num, link, pagetitleaslink), toStdout=True)
@@ -483,7 +483,7 @@
os.unlink(infile)
def run(self):
- """ Run the Bot """
+ """Run the Bot."""
try:
deadLinks = codecs.open(listof404pages, 'r', 'latin_1').read()
except IOError:
diff --git a/scripts/replace.py b/scripts/replace.py
index adb31ce..79b841a 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -142,6 +142,7 @@
class XmlDumpReplacePageGenerator:
+
"""
Iterator that will yield Pages that might contain text to replace.
@@ -219,9 +220,9 @@
class ReplaceRobot(Bot):
- """
- A bot that can do text replacements.
- """
+
+ """A bot that can do text replacements."""
+
def __init__(self, generator, replacements, exceptions={},
acceptall=False, allowoverlap=False, recursive=False,
addedCat=None, sleep=None, summary='', site=None):
@@ -276,9 +277,7 @@
self.summary = summary
def isTitleExcepted(self, title):
- """
- Iff one of the exceptions applies for the given title, returns True.
- """
+ """Iff one of the exceptions applies for the given title, returns True."""
if "title" in self.exceptions:
for exc in self.exceptions['title']:
if exc.search(title):
@@ -320,9 +319,7 @@
return new_text
def run(self):
- """
- Starts the bot.
- """
+ """Starts the bot."""
# Run the generator which will yield Pages which might need to be
# changed.
for page in self.generator:
diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py
index e22aa55..b873640 100644
--- a/scripts/replicate_wiki.py
+++ b/scripts/replicate_wiki.py
@@ -38,7 +38,7 @@
def namespaces(site):
- """dict from namespace number to prefix"""
+ """dict from namespace number to prefix."""
ns = dict(map(lambda n: (site.getNamespaceIndex(n), n),
site.namespaces()))
ns[0] = ''
@@ -46,13 +46,14 @@
def multiple_replace(text, word_dict):
- """Replace all occurrences in text of key value pairs in word_dict"""
+ """Replace all occurrences in text of key value pairs in word_dict."""
for key in word_dict:
text = text.replace(key, word_dict[key])
return text
class SyncSites:
+
"""Work is done in here."""
def __init__(self, options):
@@ -91,7 +92,7 @@
pywikibot.output('')
def check_sysops(self):
- """Check if sysops are the same on all wikis """
+ """Check if sysops are the same on all wikis."""
def get_users(site):
userlist = [ul['name'] for ul in site.allusers(group='sysop')]
return set(userlist)
@@ -104,7 +105,7 @@
self.user_diff[site] = diff
def check_namespaces(self):
- """Check all namespaces, to be ditched for clarity"""
+ """Check all namespaces, to be ditched for clarity."""
namespaces = [
0, # Main
8, # MediaWiki
@@ -125,8 +126,7 @@
self.check_namespace(ns)
def check_namespace(self, namespace):
- """Check an entire namespace"""
-
+ """Check an entire namespace."""
pywikibot.output("\nCHECKING NAMESPACE %s" % namespace)
pages = imap(lambda p: p.title(),
self.original.allpages('!', namespace=namespace))
@@ -144,7 +144,7 @@
pywikibot.output('')
def generate_overviews(self):
- """Create page on wikis with overview of bot results"""
+ """Create page on wikis with overview of bot results."""
for site in self.sites:
sync_overview_page = Page(site,
'User:%s/sync.py overview' % site.user())
@@ -171,8 +171,7 @@
% (site.user(), str(self.original)))
def check_page(self, pagename):
- """Check one page"""
-
+ """Check one page."""
pywikibot.output("\nChecking %s" % pagename)
sys.stdout.flush()
page1 = Page(self.original, pagename)
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index 1d15922..8a6cffb 100644
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -388,6 +388,7 @@
class PrimaryIgnoreManager(object):
+
"""
If run with the -primary argument, reads from a file which pages should
not be worked on; these are the ones where the user pressed n last time.
diff --git a/scripts/template.py b/scripts/template.py
index 80df20b..48763cc 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -143,11 +143,13 @@
class XmlDumpTemplatePageGenerator:
+
"""
Generator which will yield Pages to pages that might contain the chosen
template. These pages will be retrieved from a local XML dump file
(cur table).
"""
+
def __init__(self, templates, xmlfilename):
"""
Arguments:
@@ -186,6 +188,7 @@
class TemplateRobot(Bot):
+
"""
This bot will load all pages yielded by a page generator and replace or
remove all occurences of the old template, or substitute them with the
diff --git a/scripts/transferbot.py b/scripts/transferbot.py
index a9c7965..12590c1 100644
--- a/scripts/transferbot.py
+++ b/scripts/transferbot.py
@@ -49,25 +49,31 @@
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
diff --git a/scripts/upload.py b/scripts/upload.py
index 5c39065..108f564 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -126,7 +126,7 @@
return tempname
def process_filename(self):
- """Return base filename portion of self.url"""
+ """Return base filename portion of self.url."""
# Isolate the pure name
filename = self.url
# Filename may be either a local file path or a URL
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py
index 8d7b223..80c9736 100644
--- a/scripts/weblinkchecker.py
+++ b/scripts/weblinkchecker.py
@@ -174,7 +174,8 @@
class XmlDumpPageGenerator:
- """Xml generator that yiels pages containing a web link"""
+
+ """Xml generator that yiels pages containing a web link."""
def __init__(self, xmlFilename, xmlStart, namespaces):
self.xmlStart = xmlStart
@@ -215,6 +216,7 @@
class LinkChecker(object):
+
"""
Given a HTTP URL, tries to load the page from the Internet and checks if it
is still online.
@@ -466,6 +468,7 @@
class LinkCheckThread(threading.Thread):
+
""" A thread responsible for checking one URL. After checking the page, it
will die.
@@ -500,6 +503,7 @@
class History:
+
""" Store previously found dead links. The URLs are dictionary keys, and
values are lists of tuples where each tuple represents one time the URL was
found dead. Tuples have the form (title, date, error) where title is the
@@ -537,9 +541,7 @@
self.historyDict = {}
def log(self, url, error, containingPage, archiveURL):
- """
- Logs an error report to a text file in the deadlinks subdirectory.
- """
+ """Logs an error report to a text file in the deadlinks subdirectory."""
if archiveURL:
errorReport = u'* %s ([%s archive])\n' % (url, archiveURL)
else:
@@ -567,9 +569,7 @@
archiveURL)
def setLinkDead(self, url, error, page, day):
- """
- Adds the fact that the link was found dead to the .dat file.
- """
+ """Adds the fact that the link was found dead to the .dat file."""
self.semaphore.acquire()
now = time.time()
if url in self.historyDict:
@@ -617,11 +617,13 @@
class DeadLinkReportThread(threading.Thread):
+
"""
A Thread that is responsible for posting error reports on talk pages. There
will only be one DeadLinkReportThread, and it is using a semaphore to make
sure that two LinkCheckerThreads can not access the queue at the same time.
"""
+
def __init__(self):
threading.Thread.__init__(self)
self.semaphore = threading.Semaphore()
@@ -714,6 +716,7 @@
class WeblinkCheckerRobot:
+
"""
Bot which will use several LinkCheckThreads at once to search for dead
weblinks on pages provided by the given generator.
@@ -787,7 +790,7 @@
def check(url):
- """Peform a check on URL"""
+ """Peform a check on URL."""
c = LinkChecker(url)
return c.check()
diff --git a/scripts/welcome.py b/scripts/welcome.py
index 92bfaf7..37f3956 100644
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -406,8 +406,10 @@
class Global(object):
+
"""Container class for global settings.
- Use of globals outside of this is to be avoided."""
+ Use of globals outside of this is to be avoided.
+ """
attachEditCount = 1 # number of edits that an user required to be welcomed
dumpToLog = 15 # number of users that are required to add the log :)
--
To view, visit https://gerrit.wikimedia.org/r/155106
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I139407f9ea1789e66342d37b6f2b67e8ea674a5f
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Wikibase API now reports the Qid for missing items
......................................................................
Wikibase API now reports the Qid for missing items
Whereas wikibase has reported -1 for deleted items, it is now reporting
the id of the item. e.g. Q404 is a deleted item, which wbgetentities now
returns a successful result of
{"id": "Q404", "missing": ""}
A test was expecting -1, and now needs to expect Q404.
Change-Id: I713476bfbac61e1e7561cac94e1fec21a44d4db1
---
M tests/wikibase_tests.py
1 file changed, 2 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
XZise: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index a9142dd..0f1cba9 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -254,9 +254,8 @@
self.assertEquals(hasattr(item, '_content'), False)
self.assertRaises(pywikibot.NoPage, item.get)
self.assertEquals(hasattr(item, '_content'), True)
- # the title has now changed
- self.assertEquals(item._link._title, '-1')
- self.assertEquals(item.title(), '-1')
+ self.assertEquals(item._link._title, 'Q404')
+ self.assertEquals(item.title(), 'Q404')
self.assertEquals(item.exists(), False)
def test_fromPage_noprops(self):
--
To view, visit https://gerrit.wikimedia.org/r/155123
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I713476bfbac61e1e7561cac94e1fec21a44d4db1
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: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>