Revision: 8099
Author: xqt
Date: 2010-04-16 06:54:47 +0000 (Fri, 16 Apr 2010)
Log Message:
-----------
crossupdate from trunk/rewrite
Modified Paths:
--------------
branches/rewrite/scripts/editarticle.py
trunk/pywikipedia/editarticle.py
Modified: branches/rewrite/scripts/editarticle.py
===================================================================
--- branches/rewrite/scripts/editarticle.py 2010-04-16 06:29:58 UTC (rev 8098)
+++ branches/rewrite/scripts/editarticle.py 2010-04-16 06:54:47 UTC (rev 8099)
@@ -50,17 +50,18 @@
def command(self, tempFilename, text, jumpIndex = None):
command = config.editor
if jumpIndex:
- # Some editors make it possible to mark occurences of substrings, or
- # to jump to the line of the first occurence.
+ # Some editors make it possible to mark occurences of substrings,
+ # or to jump to the line of the first occurence.
# TODO: Find a better solution than hardcoding these, e.g. a config
# option.
line = text[:jumpIndex].count('\n')
column = jumpIndex - (text[:jumpIndex].rfind('\n') + 1)
else:
line = column = 0
- # Linux editors. We use startswith() because some users might use parameters.
+ # Linux editors. We use startswith() because some users might use
+ # parameters.
if config.editor.startswith('kate'):
- command += " -l %i -c %i" % (line, column)
+ command += " -l %i -c %i" % (line + 1, column + 1)
elif config.editor.startswith('gedit'):
command += " +%i" % (line + 1) # seems not to support columns
elif config.editor.startswith('emacs'):
@@ -172,7 +173,9 @@
fp = open(fn, 'w')
fp.write(new)
fp.close()
- pywikibot.output(u"An edit conflict has arisen. Your edit has been saved to
%s. Please try again." % fn)
+ pywikibot.output(
+ u"An edit conflict has arisen. Your edit has been saved to %s. Please
try again."
+ % fn)
def run(self):
try:
@@ -186,7 +189,8 @@
changes = pywikibot.input(u"What did you change?")
comment = pywikibot.translate(pywikibot.getSite(), msg) % changes
try:
- self.page.put(new, comment = comment, minorEdit = False,
watchArticle=self.options.watch)
+ self.page.put(new, comment=comment, minorEdit=False,
+ watchArticle=self.options.watch)
except pywikibot.EditConflict:
self.handle_edit_conflict(new)
else:
Modified: trunk/pywikipedia/editarticle.py
===================================================================
--- trunk/pywikipedia/editarticle.py 2010-04-16 06:29:58 UTC (rev 8098)
+++ trunk/pywikipedia/editarticle.py 2010-04-16 06:54:47 UTC (rev 8099)
@@ -6,7 +6,7 @@
#
# (C) Gerrit Holl 2004
-# (C) Pywikipedia team, 2004-2009
+# (C) Pywikipedia team, 2004-2010
#
__version__ = "$Id$"
#
@@ -50,15 +50,16 @@
def command(self, tempFilename, text, jumpIndex = None):
command = config.editor
if jumpIndex:
- # Some editors make it possible to mark occurences of substrings, or
- # to jump to the line of the first occurence.
+ # Some editors make it possible to mark occurences of substrings,
+ # or to jump to the line of the first occurence.
# TODO: Find a better solution than hardcoding these, e.g. a config
# option.
line = text[:jumpIndex].count('\n')
column = jumpIndex - (text[:jumpIndex].rfind('\n') + 1)
else:
line = column = 0
- # Linux editors. We use startswith() because some users might use parameters.
+ # Linux editors. We use startswith() because some users might use
+ # parameters.
if config.editor.startswith('kate'):
command += " -l %i -c %i" % (line + 1, column + 1)
elif config.editor.startswith('gedit'):
@@ -126,27 +127,32 @@
os.unlink(tempFilename)
return self.restoreLinebreaks(newcontent)
else:
- return self.restoreLinebreaks(pywikibot.ui.editText(text, jumpIndex =
jumpIndex, highlight = highlight))
+ return self.restoreLinebreaks(
+ pywikibot.ui.editText(text, jumpIndex=jumpIndex,
+ highlight=highlight))
class ArticleEditor:
# join lines if line starts with this ones
joinchars = string.letters + '[]' + string.digits
- def __init__(self):
- self.set_options()
+ def __init__(self, *args):
+ self.set_options(*args)
self.setpage()
self.site = pywikibot.getSite()
- def set_options(self):
+ def set_options(self, *args):
"""Parse commandline and set options attribute"""
my_args = []
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handleArgs(*args):
my_args.append(arg)
parser = optparse.OptionParser()
- parser.add_option("-r", "--edit_redirect",
action="store_true", default=False, help="Ignore/edit redirects")
+ parser.add_option("-r", "--edit_redirect",
action="store_true",
+ default=False, help="Ignore/edit redirects")
parser.add_option("-p", "--page", help="Page to
edit")
- parser.add_option("-w", "--watch",
action="store_true", default=False, help="Watch article after edit")
- #parser.add_option("-n", "--new_data", default="",
help="Automatically generated content")
+ parser.add_option("-w", "--watch",
action="store_true", default=False,
+ help="Watch article after edit")
+ #parser.add_option("-n", "--new_data", default="",
+ # help="Automatically generated content")
(self.options, args) = parser.parse_args(args=my_args)
# for convenience, if we have an arg, stuff it into the opt, so we
@@ -167,7 +173,9 @@
fp = open(fn, 'w')
fp.write(new)
fp.close()
- pywikibot.output(u"An edit conflict has arisen. Your edit has been saved to
%s. Please try again." % fn)
+ pywikibot.output(
+ u"An edit conflict has arisen. Your edit has been saved to %s. Please
try again."
+ % fn)
def run(self):
try:
@@ -181,14 +189,15 @@
changes = pywikibot.input(u"What did you change?")
comment = pywikibot.translate(pywikibot.getSite(), msg) % changes
try:
- self.page.put(new, comment = comment, minorEdit = False,
watchArticle=self.options.watch)
+ self.page.put(new, comment=comment, minorEdit=False,
+ watchArticle=self.options.watch)
except pywikibot.EditConflict:
self.handle_edit_conflict(new)
else:
pywikibot.output(u"Nothing changed")
-def main():
- app = ArticleEditor()
+def main(*args):
+ app = ArticleEditor(*args)
app.run()
if __name__ == "__main__":