From 22d3c06e79b1156449aa69878043e3d85633d65f Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Jun 13 2016 03:51:41 +0000 Subject: fix broken when non-ASCII in path Path can be got from current directory or the --path option. In both cases, unicode string is used instead of byte string. This change is compatible with Python 3 by defining pyrpkg own's u and getcwd methods, that is because it's necessary to convert path specified via --path option from byte string to Unicode string in UTF-8, and get current directory as Unicode string. So far, six.moves.getcwd is only supported in 1.10.0 which is available for fc24, thus, six.moves.getcwd is not available in any old distros using older version of six. This is related to the fix of bug 1286374. Signed-off-by: Chenxiong Qi --- diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py index b5cbbc1..61349e6 100644 --- a/src/pyrpkg/__init__.py +++ b/src/pyrpkg/__init__.py @@ -43,6 +43,7 @@ from .gitignore import GitIgnore from pyrpkg.lookaside import CGILookasideCache from pyrpkg.sources import SourcesFile from pyrpkg.utils import cached_property, warn_deprecated, log_result +from pyrpkg.utils import u, getcwd from osbs.api import OSBS from osbs.conf import Configuration diff --git a/src/pyrpkg/cli.py b/src/pyrpkg/cli.py index 767e92d..30d7a3a 100755 --- a/src/pyrpkg/cli.py +++ b/src/pyrpkg/cli.py @@ -23,6 +23,8 @@ from six.moves import xmlrpc_client import pwd import koji +import utils + OSBS_DEFAULT_CONF_FILE = "/etc/osbs/osbs.conf" class cliClient(object): @@ -176,6 +178,7 @@ class cliClient(object): help='Run Koji commands as a different user') # Let the user define a path to work in rather than cwd self.parser.add_argument('--path', default=None, + type=utils.u, help='Define the directory to work in ' '(defaults to cwd)') # Verbosity diff --git a/src/pyrpkg/utils.py b/src/pyrpkg/utils.py index c6af23a..ba297a2 100644 --- a/src/pyrpkg/utils.py +++ b/src/pyrpkg/utils.py @@ -16,6 +16,16 @@ This module contains a bunch of utilities used elsewhere in pyrpkg. import warnings warnings.simplefilter('always', DeprecationWarning) +import os +import six + +if six.PY3: + u = lambda s: s + getcwd = os.getcwd +else: + u = lambda s: s.decode('utf-8') + getcwd = os.getcwdu + class cached_property(property): """A property caching its return value diff --git a/src/rpkg b/src/rpkg index fc743be..6cd10e2 100755 --- a/src/rpkg +++ b/src/rpkg @@ -12,6 +12,7 @@ import pyrpkg import pyrpkg.cli +import pyrpkg.utils import os import sys import logging @@ -40,7 +41,7 @@ client.parse_cmdline() if not client.args.path: try: - client.args.path=os.getcwd() + client.args.path = pyrpkg.utils.getcwd() except: print('Could not get current path, have you deleted it?') sys.exit(1)