jenkins-bot has submitted this change and it was merged.
Change subject: category.py: consider also /doc subpages in template ns
......................................................................
category.py: consider also /doc subpages in template ns
For templates, categories can be in /doc subpage.
Added the check of the /doc page as well.
Modified:
- textlib.removeDisabledParts()
- textlib.getCategoryLinks()
- page.change_category()
to optionally consider also categories in tags otherwise removed.
Also Pep257 fixes in textlib.py
Bug: 55017
Change-Id: I8faecb5f0de75c0f9b635815c6a73ac367bfb2f1
---
M pywikibot/page.py
M pywikibot/textlib.py
M scripts/category.py
3 files changed, 33 insertions(+), 14 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
Mpaa: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 7c1d9d3..013afd4 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1669,7 +1669,7 @@
return self.site.protect(self, protections, reason, **kwargs)
def change_category(self, oldCat, newCat, comment=None, sortKey=None,
- inPlace=True):
+ inPlace=True, include=[]):
"""
Remove page from oldCat and add it to newCat.
@@ -1683,17 +1683,21 @@
@param inPlace: if True, change categories in place rather than
rearranging them.
+
+ @param include: list of tags not to be disabled by default in relevant
+ textlib functions, where CategoryLinks can be searched.
+ @type: list
+
@return: True if page was saved changed, otherwise False.
"""
# get list of Category objects the article is in and remove possible
# duplicates
cats = []
- for cat in textlib.getCategoryLinks(self.text, site=self.site):
+ for cat in textlib.getCategoryLinks(self.text, site=self.site,
+ include=include):
if cat not in cats:
cats.append(cat)
-
- site = self.site
if not sortKey:
sortKey = oldCat.sortKey
@@ -1718,7 +1722,7 @@
site=self.site)
else:
if newCat:
- cats[cats.index(oldCat)] = Category(site, newCat.title(),
+ cats[cats.index(oldCat)] = Category(self.site, newCat.title(),
sortKey=sortKey)
else:
cats.pop(cats.index(oldCat))
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 4b3934b..f4e4f0d 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -273,7 +273,7 @@
return text
-def removeDisabledParts(text, tags=['*']):
+def removeDisabledParts(text, tags=['*'], include=[]):
"""
Return text without portions where wiki markup is disabled.
@@ -284,7 +284,9 @@
* includeonly tags
The exact set of parts which should be removed can be passed as the
- 'parts' parameter, which defaults to all.
+ 'tags' parameter, which defaults to all.
+ Or, in alternative, default parts that shall not be removed can be
+ specified in the 'include' param.
"""
regexes = {
@@ -298,7 +300,7 @@
if '*' in tags:
tags = list(regexes.keys())
# add alias
- tags = set(tags)
+ tags = set(tags) - set(include)
if 'source' in tags:
tags.add('syntaxhighlight')
toRemoveR = re.compile('|'.join([regexes[tag] for tag in tags]),
@@ -659,8 +661,12 @@
# Functions dealing with category links
# -------------------------------------
-def getCategoryLinks(text, site=None):
+def getCategoryLinks(text, site=None, include=[]):
"""Return a list of category links found in text.
+
+ @param include: list of tags which should not be removed by
+ removeDisabledParts() and where CategoryLinks can be searched.
+ @type: list
@return: all category links found
@rtype: list of Category objects
@@ -670,7 +676,7 @@
site = pywikibot.Site()
# Ignore category links within nowiki tags, pre tags, includeonly tags,
# and HTML comments
- text = removeDisabledParts(text)
+ text = removeDisabledParts(text, include=include)
catNamespace = '|'.join(site.category_namespaces())
R = re.compile(r'\[\[\s*(?P<namespace>%s)\s*:\s*(?P<rest>.+?)\]\]'
% catNamespace, re.I)
@@ -1130,7 +1136,7 @@
def does_text_contain_section(pagetext, section):
"""
- Determines whether the page text contains the given section title.
+ Determine whether the page text contains the given section title.
@param pagetext: The wikitext of a page
@type text: unicode or string
@@ -1187,9 +1193,7 @@
class TimeStripper(object):
- """
- Find timestamp in page and return it as timezone aware datetime object.
- """
+ """Find timestamp in page and return it as timezone aware datetime object."""
def __init__(self, site=None):
if site is None:
diff --git a/scripts/category.py b/scripts/category.py
index 12beae3..ddc5665 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -634,10 +634,21 @@
for page in pagegenerators.PreloadingGenerator(gen):
if not self.title_regex or re.search(self.title_regex,
page.title()):
+
page.change_category(self.oldcat, self.newcat,
comment=self.comment,
inPlace=self.inplace)
+ # Categories for templates can be included in <includeonly> section
+ # of Template:X/doc subpage.
+ if page.namespace() == 10:
+ doc_page = pywikibot.Page(page.site, page.title() + '/doc')
+ if doc_page.exists():
+ doc_page.change_category(self.oldcat, self.newcat,
+ comment=self.comment,
+ inPlace=self.inplace,
+ include=['includeonly'])
+
@staticmethod
def check_move(name, old_page, new_page):
"""Return if the old page can be safely moved to the new page."""
--
To view, visit https://gerrit.wikimedia.org/r/164782
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8faecb5f0de75c0f9b635815c6a73ac367bfb2f1
Gerrit-PatchSet: 2
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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
XZise has submitted this change and it was merged.
Change subject: Remove references to wikipedia.py
......................................................................
Remove references to wikipedia.py
Change-Id: Ibf5eaaf153c5b7edae23779bdaba95e8b519a548
---
M generate_user_files.py
M pywikibot/config2.py
M pywikibot/exceptions.py
M pywikibot/textlib.py
M pywikibot/version.py
5 files changed, 7 insertions(+), 10 deletions(-)
Approvals:
XZise: Looks good to me, approved
diff --git a/generate_user_files.py b/generate_user_files.py
index 0043dcb..8a99806 100644
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -338,12 +338,12 @@
if pywikibot.inputChoice(
"Do you want to copy user files from an existing Pywikibot "
"installation?", ["yes", "no"], ["y", "n"]) == "y":
- oldpath = pywikibot.input("Path to existing wikipedia.py?")
+ oldpath = pywikibot.input("Path to existing user-config.py?")
if not os.path.exists(oldpath):
pywikibot.error("Not a valid path")
continue
if os.path.isfile(oldpath):
- # User probably typed /wikipedia.py at the end, so strip it
+ # User probably typed /user-config.py at the end, so strip it
oldpath = os.path.dirname(oldpath)
if not os.path.isfile(os.path.join(oldpath, "user-config.py")):
pywikibot.error("No user_config.py found in that directory")
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 0ad9bc7..ac8d1a4 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -44,9 +44,9 @@
# ############# ACCOUNT SETTINGS ##############
-# The family of sites we are working on. wikipedia.py will import
+# The family of sites we are working on. pywikibot will import
# families/xxx_family.py so if you want to change this variable,
-# you need to write such a file.
+# you need to write such a file if one does not exist.
family = 'wikipedia'
# The language code of the site we're working on.
mylang = 'language'
@@ -128,7 +128,7 @@
# edit summary to use if not supplied by bot script
# WARNING: this should NEVER be used in practice, ALWAYS supply a more
# relevant summary for bot edits
-default_edit_summary = u'Wikipedia python library v.2'
+default_edit_summary = u'Pywikibot v.2'
def get_base_dir(test_directory=None):
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index fec58df..f99c0b6 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -51,9 +51,6 @@
from pywikibot.tools import UnicodeMixin
-# TODO: These are copied from wikipedia.py; not certain that all of them
-# will be needed in the rewrite.
-
class Error(UnicodeMixin, Exception):
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 4b3934b..1efcafd 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1040,7 +1040,7 @@
if not name or name.startswith('#'):
continue
-# TODO: merged from wikipedia.py - implement the following
+# TODO: implement the following; 'self' and site dont exist in this function
# if self.site().isInterwikiLink(name):
# continue
# # {{DEFAULTSORT:...}}
diff --git a/pywikibot/version.py b/pywikibot/version.py
index 1002ffb..7e232a1 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -82,7 +82,7 @@
except:
# nothing worked; version unknown (but suppress exceptions)
# the value is most likely '$Id' + '$', it means that
- # wikipedia.py got imported without using svn at all
+ # pywikibot was imported without using version control at all.
return dict(tag='', rev='-1 (unknown)', date='0 (unknown)',
hsh='(unknown)')
--
To view, visit https://gerrit.wikimedia.org/r/165740
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibf5eaaf153c5b7edae23779bdaba95e8b519a548
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(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: [FEAT] config2: Allow to test whether a path would work
......................................................................
[FEAT] config2: Allow to test whether a path would work
The config2 now also allows to "simulate" that a specific base directory
does exist, to get rid of the warning when the user doesn't has to do
anything to make it find the user-config.py.
Change-Id: I88691ea634f0579aa28ee88d852d9073283c4ae7
---
M generate_user_files.py
M pywikibot/config2.py
2 files changed, 34 insertions(+), 21 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/generate_user_files.py b/generate_user_files.py
index 05df8f0..0043dcb 100644
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -86,6 +86,9 @@
pywikibot.output("Created new directory.")
break
+ if new_base == pywikibot.config2.get_base_dir(new_base):
+ # config would find that file
+ return new_base
from textwrap import wrap
msg = wrap(u"""WARNING: Your user files will be created in the directory
'%(new_base)s' you have chosen. To access these files, you will either have
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 0b04b5a..0ad9bc7 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -131,7 +131,7 @@
default_edit_summary = u'Wikipedia python library v.2'
-def _get_base_dir():
+def get_base_dir(test_directory=None):
r"""Return the directory in which user-specific information is stored.
This is determined in the following order -
@@ -147,7 +147,20 @@
Set PYWIKIBOT2_NO_USER_CONFIG=1 to disable loading user-config.py
+ @param test_directory: Assume that a user config file exists in this
+ directory. Used to test whether placing a user config file in this
+ directory will cause it to be selected as the base directory.
+ @type test_directory: str or None
"""
+ def exists(directory):
+ directory = os.path.abspath(directory)
+ if directory == test_directory:
+ return True
+ else:
+ return os.path.exists(os.path.join(directory, 'user-config.py'))
+
+ if test_directory is not None:
+ test_directory = os.path.abspath(test_directory)
NAME = "pywikibot"
base_dir = ""
for arg in sys.argv[1:]:
@@ -155,24 +168,22 @@
base_dir = arg[5:]
sys.argv.remove(arg)
break
- current_exists = os.path.exists(
- os.path.join(os.path.abspath("."), "user-config.py"))
- if current_exists and "PYWIKIBOT2_DIR" not in os.environ and not base_dir:
- base_dir = os.path.abspath(".")
- return base_dir
else:
- if "PYWIKIBOT2_DIR" in os.environ:
- base_dir = os.environ["PYWIKIBOT2_DIR"]
- elif not base_dir:
- is_windows = sys.platform == 'win32'
+ if 'PYWIKIBOT2_DIR' in os.environ:
+ base_dir = os.environ['PYWIKIBOT2_DIR']
+ elif exists('.'):
+ return os.path.abspath('.')
+ else:
home = os.path.expanduser("~")
- if is_windows:
+ if sys.platform == 'win32':
import platform
- _win_version = int(platform.version()[0])
- if _win_version == 5:
+ win_version = int(platform.version()[0])
+ if win_version == 5:
base_dir = os.path.join(home, "Application Data", NAME)
- elif _win_version == 6:
+ elif win_version == 6:
base_dir = os.path.join(home, "AppData\\Roaming", NAME)
+ #TODO: Throw exception otherwise to notify the user that the
+ # version of Windows is not (yet) supported
else:
base_dir = os.path.join(home, "." + NAME)
if not os.path.isdir(base_dir):
@@ -181,22 +192,21 @@
base_dir = os.path.normpath(os.path.join(os.getcwd(), base_dir))
# make sure this path is valid and that it contains user-config file
if not os.path.isdir(base_dir):
- raise RuntimeError("Directory '%(base_dir)s' does not exist."
- % locals())
- 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())
+ raise RuntimeError("Directory '%s' does not exist." % base_dir)
+ if not exists(base_dir):
+ exc_text = "No user-config.py found in directory '%s'.\n" % base_dir
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__
+ exc_text += " " + get_base_dir.__doc__
raise RuntimeError(exc_text)
return base_dir
-_base_dir = _get_base_dir()
+_get_base_dir = get_base_dir # for backward compatibility
+_base_dir = get_base_dir()
# Save base_dir for use by other modules
base_dir = _base_dir
--
To view, visit https://gerrit.wikimedia.org/r/165651
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I88691ea634f0579aa28ee88d852d9073283c4ae7
Gerrit-PatchSet: 2
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: jenkins-bot <>