[Python-checkins] python/nondist/sandbox/setuptools/setuptools/command alias.py, 1.3, 1.4

pje@users.sourceforge.net pje at users.sourceforge.net
Fri Jul 8 17:49:56 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22808/setuptools/command

Modified Files:
	alias.py 
Log Message:
Cleaner argument quoting in command aliases.


Index: alias.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/alias.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- alias.py	8 Jul 2005 15:11:19 -0000	1.3
+++ alias.py	8 Jul 2005 15:49:53 -0000	1.4
@@ -5,6 +5,15 @@
 from distutils.errors import *
 from setuptools.command.setopt import edit_config, option_base, config_file
 
+def shquote(arg):
+    """Quote an argument for later parsing by shlex.split()"""
+    for c in '"', "'", "\\", "#":
+        if c in arg: return repr(arg)
+    if arg.split()<>[arg]:
+        return repr(arg)
+    return arg        
+
+
 class alias(option_base):
     """Define a shortcut that invokes one or more commands"""
     
@@ -17,13 +26,11 @@
 
     boolean_options = option_base.boolean_options + ['remove']
 
-
     def initialize_options(self):
         option_base.initialize_options(self)
         self.args = None
         self.remove = None
 
-
     def finalize_options(self):
         option_base.finalize_options(self)
         if self.remove and len(self.args)<>1:
@@ -32,13 +39,6 @@
                 "using --remove"
             )
 
-
-
-
-
-
-
-
     def run(self):
         aliases = self.distribution.get_option_dict('aliases')
 
@@ -61,7 +61,7 @@
                 return
         else:
             alias = self.args[0]
-            command = ' '.join(map(repr,self.args[1:]))
+            command = ' '.join(map(shquote,self.args[1:]))
 
         edit_config(self.filename, {'aliases': {alias:command}}, self.dry_run)
 



More information about the Python-checkins mailing list