Skip to content

Commit

Permalink
Py3: sys.argv conversion compat.
Browse files Browse the repository at this point in the history
  • Loading branch information
achadwick committed Mar 3, 2018
1 parent 7e4cac6 commit b233471
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions mypaint.py
Expand Up @@ -127,19 +127,27 @@ def win32_unicode_argv():
"and submit patches if it's not."
)
logger.warning("Falling back to POSIX-style argument handling")
return [s.decode(sys.getfilesystemencoding()) for s in sys.argv]


def get_paths():
join = os.path.join

# Convert sys.argv to a list of unicode objects
# (actually converting sys.argv confuses gtk, thus we add a new variable)
# Post-Py3: almost certainly not needed, but check *all* platforms
# before removing this stuff.

sys.argv_unicode = None
if sys.platform == 'win32':
sys.argv_unicode = win32_unicode_argv()
else:
sys.argv_unicode = [s.decode(sys.getfilesystemencoding())
for s in sys.argv]

if sys.argv_unicode is None:
argv_unicode = []
for s in sys.argv:
if hasattr(s, "decode"):
s = s.decode(sys.getfilesystemencoding())
argv_unicode.append(s)
sys.argv_unicode = argv_unicode

# Script and its location, in canonical absolute form
scriptfile = os.path.realpath(sys.argv_unicode[0])
Expand Down

0 comments on commit b233471

Please sign in to comment.