From adb0fbc7f09dc537d928f0dca1d3d5f230b059c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Luttringer?= Date: Fri, 6 Jul 2012 17:42:54 +0200 Subject: [PATCH] Also unicodify install subparser arguments --- bin/is | 7 ++----- installsystems/image.py | 4 +++- installsystems/tools.py | 9 +++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bin/is b/bin/is index cc09cdc..efe7396 100755 --- a/bin/is +++ b/bin/is @@ -29,7 +29,6 @@ import argparse import psutil import socket import sys -import locale import installsystems import installsystems.printer import installsystems.tools as istools @@ -674,10 +673,7 @@ def main(): # init arg parser arg_parser = arg_parser_init() # encode command line arguments to utf-8 - try: - args = [ unicode(x, encoding=locale.getpreferredencoding()) for x in sys.argv[1:]] - except UnicodeDecodeError as e: - raise ISError("Invalid character encoding in command line") + args = istools.argv()[1:] # first partial parsing, to get early debug and config path options = arg_parser.parse_known_args(args=args)[0] # set early command line verbosity and color @@ -736,6 +732,7 @@ def main(): except Exception as e: error(u"Unexpected error, please report it with debug enabled", exception=e) + # Entry point if __name__ == '__main__': main() diff --git a/installsystems/image.py b/installsystems/image.py index 7bf0f95..0bc09d8 100644 --- a/installsystems/image.py +++ b/installsystems/image.py @@ -981,9 +981,11 @@ class PackageImage(Image): {"parser": extparser}) # call parser (again), with full options arrow("Parsing command line") + # encode command line arguments to utf-8 + args = istools.argv()[1:] # Catch exception in custom argparse action try: - args = parser.parse_args() + args = parser.parse_args(args=args) except Exception as e: raise ISError("Argument parser", e) # run setup scripts diff --git a/installsystems/tools.py b/installsystems/tools.py index c6a2dd4..065c146 100644 --- a/installsystems/tools.py +++ b/installsystems/tools.py @@ -670,3 +670,12 @@ def render_templates(target, context, tpl_ext=".istpl", force=False, keep=False) os.chmod(file_path, st.st_mode) if not keep: os.unlink(tpl_path) + +def argv(): + ''' + Return system argv after an unicode transformation with locale preference + ''' + try: + return [unicode(x, encoding=locale.getpreferredencoding()) for x in sys.argv] + except UnicodeDecodeError as e: + raise ISError("Invalid character encoding in command line") -- GitLab