[c-c shell] make script arguments available as __args__ in the script namespace. Use scriptargs instead of args as process_script argument name.
authorJulien Jehannet <julien.jehannet@logilab.fr>
Wed, 28 Apr 2010 17:57:36 +0200
changeset 5436 2455ca3a2a3a
parent 5435 cc7d00a1b36e
child 5437 ac19fdcd297b
[c-c shell] make script arguments available as __args__ in the script namespace. Use scriptargs instead of args as process_script argument name.
cwctl.py
migration.py
test/data/scripts/script1.py
test/data/scripts/script2.py
test/data/scripts/script3.py
test/unittest_cwctl.py
--- a/cwctl.py	Wed Apr 28 18:13:38 2010 +0200
+++ b/cwctl.py	Wed Apr 28 17:57:36 2010 +0200
@@ -783,7 +783,7 @@
 
     Arguments after bare "--" string will not be processed by the shell command
     You can use it to pass extra arguments to your script and expect for
-    them in 'scriptargs' afterwards.
+    them in '__args__' afterwards.
 
     <instance>
       the identifier of the instance to connect.
@@ -869,7 +869,7 @@
                 # remember that usage requires instance appid as first argument
                 scripts, args = self.cmdline_parser.largs[1:], self.cmdline_parser.rargs
                 for script in scripts:
-                    mih.cmd_process_script(script, args=args)
+                    mih.cmd_process_script(script, scriptargs=args)
             else:
                 mih.interactive_shell()
         finally:
--- a/migration.py	Wed Apr 28 18:13:38 2010 +0200
+++ b/migration.py	Wed Apr 28 17:57:36 2010 +0200
@@ -287,14 +287,14 @@
         if confirmed
 
         Context environment can have these variables defined:
-        - __name__   : will be determine by funcname parameter
-        - __file__   : is the name of the script if it exists
-        - scriptargs : script arguments coming from command-line
+        - __name__ : will be determine by funcname parameter
+        - __file__ : is the name of the script if it exists
+        - __args__ : script arguments coming from command-line
 
         :param migrscript: name of the script
-        :param funcname: defines __name__ internally (or use __main__)
-        :params args: arguments of the script
-        :keyword args: extra arguments of the script given by command-line
+        :param funcname: defines __name__ inside the shell (or use __main__)
+        :params args: optional arguments for funcname
+        :keyword scriptargs: optional arguments of the script
         """
         migrscript = os.path.normpath(migrscript)
         if migrscript.endswith('.py'):
@@ -312,7 +312,7 @@
             else:
                 pyname = splitext(basename(migrscript))[0]
             scriptlocals.update({'__file__': migrscript, '__name__': pyname,
-                                 'scriptargs': kwargs.pop("args", [])})
+                                 '__args__': kwargs.pop("scriptargs", [])})
             execfile(migrscript, scriptlocals)
             if funcname is not None:
                 try:
--- a/test/data/scripts/script1.py	Wed Apr 28 18:13:38 2010 +0200
+++ b/test/data/scripts/script1.py	Wed Apr 28 17:57:36 2010 +0200
@@ -1,3 +1,3 @@
 assert 'data/scripts/script1.py' == __file__
 assert '__main__' == __name__
-assert [] == scriptargs, scriptargs
+assert [] == __args__, __args__
--- a/test/data/scripts/script2.py	Wed Apr 28 18:13:38 2010 +0200
+++ b/test/data/scripts/script2.py	Wed Apr 28 17:57:36 2010 +0200
@@ -1,3 +1,3 @@
 assert 'data/scripts/script2.py' == __file__
 assert '__main__' == __name__
-assert ['-v'] == scriptargs, scriptargs
+assert ['-v'] == __args__, __args__
--- a/test/data/scripts/script3.py	Wed Apr 28 18:13:38 2010 +0200
+++ b/test/data/scripts/script3.py	Wed Apr 28 17:57:36 2010 +0200
@@ -1,3 +1,3 @@
 assert 'data/scripts/script3.py' == __file__
 assert '__main__' == __name__
-assert ['-vd', '-f', 'FILE.TXT'] == scriptargs, scriptargs
+assert ['-vd', '-f', 'FILE.TXT'] == __args__, __args__
--- a/test/unittest_cwctl.py	Wed Apr 28 18:13:38 2010 +0200
+++ b/test/unittest_cwctl.py	Wed Apr 28 17:57:36 2010 +0200
@@ -58,7 +58,7 @@
         for script, args in scripts.items():
             scriptname = os.path.join('data/scripts/', script)
             self.assert_(os.path.exists(scriptname))
-            mih.cmd_process_script(scriptname, None, args=args)
+            mih.cmd_process_script(scriptname, None, scriptargs=args)
 
 
 if __name__ == '__main__':