allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: Allow unicode scripttask params; specifically for delete_projects reason
Date Tue, 12 Jan 2016 22:12:36 GMT
Repository: allura
Updated Branches:
  refs/heads/db/unicode_args [created] 671527e2a


Allow unicode scripttask params; specifically for delete_projects reason


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/671527e2
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/671527e2
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/671527e2

Branch: refs/heads/db/unicode_args
Commit: 671527e2ada18b18db996a3f5c1c37b8d1254f2b
Parents: a0f7f3d
Author: Dave Brondsema <dave@brondsema.net>
Authored: Tue Jan 12 17:00:37 2016 -0500
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Tue Jan 12 17:00:37 2016 -0500

----------------------------------------------------------------------
 Allura/allura/scripts/delete_projects.py | 2 +-
 Allura/allura/scripts/scripttask.py      | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/671527e2/Allura/allura/scripts/delete_projects.py
----------------------------------------------------------------------
diff --git a/Allura/allura/scripts/delete_projects.py b/Allura/allura/scripts/delete_projects.py
index 6c83c9b..66232d7 100644
--- a/Allura/allura/scripts/delete_projects.py
+++ b/Allura/allura/scripts/delete_projects.py
@@ -55,7 +55,7 @@ class DeleteProjects(ScriptTask):
         parser = argparse.ArgumentParser(description='Completely delete projects')
         parser.add_argument('projects', metavar='nbhd/project', type=str, nargs='+',
                             help='List of projects to delete in a form nbhd_prefix/shortname')
-        parser.add_argument('-r', '--reason', type=str,
+        parser.add_argument('-r', '--reason', type=lambda s: s.decode('utf8'),
                             help='Reason why these projects are being deleted')
         parser.add_argument('--disable-users', action='store_true', default=False,
                             help='Disable all users belonging to groups Admin and Developer
in these projects.')

http://git-wip-us.apache.org/repos/asf/allura/blob/671527e2/Allura/allura/scripts/scripttask.py
----------------------------------------------------------------------
diff --git a/Allura/allura/scripts/scripttask.py b/Allura/allura/scripts/scripttask.py
index a8494c9..c46d7b6 100644
--- a/Allura/allura/scripts/scripttask.py
+++ b/Allura/allura/scripts/scripttask.py
@@ -74,7 +74,12 @@ class ScriptTask(object):
     @classmethod
     def _execute_task(cls, arg_string):
         try:
-            options = cls.parser().parse_args(shlex.split(arg_string or ''))
+            if isinstance(arg_string, unicode):
+                # shlex doesn't support unicode fully, so encode it http://stackoverflow.com/a/14219159/79697
+                # decode has to happen in the arg parser (e.g. see delete_projects.py)
+                arg_string = arg_string.encode('utf8')
+            args_split = shlex.split(arg_string or '')
+            options = cls.parser().parse_args(args_split)
         except SystemExit:
             raise Exception("Error parsing args: '%s'" % arg_string)
         return cls.execute(options)


Mime
View raw message