XZise has uploaded a new change for review.
https://gerrit.wikimedia.org/r/184241
Change subject: [FIX] Editor: Support spaces, delete always and warn on \n (etc)
......................................................................
[FIX] Editor: Support spaces, delete always and warn on \n (etc)
This support spaces in the editor file name and deletes the temporary
file even if there was no change. It also warns if the filename contains
a string literal like \n wih Windows because the backslash was used as a
path delimiter without escaping them.
Bug: T86481
Change-Id: If7e9feee49acd1147c5554cdd74a7ad0758397c5
---
M pywikibot/config2.py
M pywikibot/editor.py
2 files changed, 19 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/41/184241/1
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index e7df241..6e1a27e 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -886,6 +886,17 @@
elif transliteration_target in ('None', 'none'):
transliteration_target = None
+if sys.platform == 'win32' and editor:
+ # single character string literals from
+ # https://docs.python.org/2/reference/lexical_analysis.html#string-literals
+ # encode('unicode-escape') also changes Unicode characters
+ if set(editor) & set('\a\b\f\n\r\t\v'):
+ print('WARNING: The editor path contains probably invalid escaped '
+ 'characters. Make sure to use a raw-string (r"..." or r\'...\'),
'
+ 'forward slashs as a path delimiter or to escape the normal '
+ 'path delimiter.')
+
+
# Fix up default site
if family == 'wikipedia' and mylang == 'language':
print("WARNING: family and mylang are not set.\n"
diff --git a/pywikibot/editor.py b/pywikibot/editor.py
index d3e268a..678dca2 100644
--- a/pywikibot/editor.py
+++ b/pywikibot/editor.py
@@ -11,9 +11,12 @@
__version__ = '$Id$'
#
-import os
-import tempfile
import codecs
+import os
+import shlex
+import subprocess
+import tempfile
+
import pywikibot
from pywikibot import config
@@ -24,7 +27,7 @@
def command(self, tempFilename, text, jumpIndex=None):
"""Return editor selected in user-config.py."""
- command = config.editor
+ command = '"{0}"'.format(config.editor)
if jumpIndex:
# Some editors make it possible to mark occurrences of substrings,
# or to jump to the line of the first occurrence.
@@ -80,10 +83,11 @@
tempFile.write(text)
creationDate = os.stat(tempFilename).st_mtime
command = self.command(tempFilename, text, jumpIndex)
- os.system(command)
+ subprocess.call(shlex.split(command))
lastChangeDate = os.stat(tempFilename).st_mtime
if lastChangeDate == creationDate:
# Nothing changed
+ os.unlink(tempFilename)
return None
else:
with codecs.open(tempFilename, 'r',
--
To view, visit https://gerrit.wikimedia.org/r/184241
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If7e9feee49acd1147c5554cdd74a7ad0758397c5
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