XZise has uploaded a new change for review.
https://gerrit.wikimedia.org/r/213524
Change subject: [FEAT] pagefromfile: Support separator with append
......................................................................
[FEAT] pagefromfile: Support separator with append
When using appendbottom or appendtop it is possible to add any text between the
old and new text.
Change-Id: I116cbb644135fa3ddc25c5a01f0f3415a865e681
---
M scripts/pagefromfile.py
1 file changed, 23 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/24/213524/1
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index 209355a..b92c85a 100755
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-"""
+r"""
Bot to upload pages from a file.
This bot takes its input from a file that contains a number of
@@ -46,6 +46,11 @@
-appendtop add the text to the top of it
-appendbottom add the text to the bottom of it
-force overwrite the existing page
+
+It's possible to define a separator after the 'append' modes which is added
+between the exisiting and new text. For example -appendtop:foo would add 'foo'
+between the parts. The \n (two separate characters) is replaced by the newline
+character.
"""
#
# (C) Andre Engels, 2004
@@ -137,16 +142,19 @@
pagecontents.find(self.getOption('nocontent').lower()) != -1:
pywikibot.output(u'Page has %s so it is skipped' %
self.getOption('nocontent'))
return
- if self.getOption('append') == 'top':
- pywikibot.output(u"Page %s already exists, appending on top!"
- % title)
- contents = contents + pagecontents
- comment = comment_top
- elif self.getOption('append') == 'bottom':
- pywikibot.output(u"Page %s already exists, appending on
bottom!"
- % title)
- contents = pagecontents + contents
- comment = comment_bottom
+ if self.getOption('append'):
+ separator = self.getOption('append')[1]
+ if separator == r'\n':
+ separator = '\n'
+ if self.getOption('append')[0] == 'top':
+ above, below = contents, pagecontents
+ comment = comment_top
+ else:
+ above, below = pagecontents, contents
+ comment = comment_bottom
+ pywikibot.output('Page {0} already exists, appending on
{1}!'.format(
+ title, self.getOption('append')[0]))
+ contents = above + separator + below
elif self.getOption('force'):
pywikibot.output(u"Page %s already exists, ***overwriting!"
% title)
@@ -277,8 +285,10 @@
filename = arg[6:]
elif arg == "-include":
include = True
- elif arg.startswith('-append') and arg[7:] in ('top', 'bottom'):
- options['append'] = arg[7:]
+ elif arg.startswith('-appendbottom'):
+ options['append'] = ('bottom', arg[len('-appendbottom:'):])
+ elif arg.startswith('-appendtop'):
+ options['append'] = ('top', arg[len('-appendtop:'):])
elif arg == "-force":
options['force'] = True
elif arg == "-safe":
--
To view, visit https://gerrit.wikimedia.org/r/213524
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I116cbb644135fa3ddc25c5a01f0f3415a865e681
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits