# HG changeset patch # User Julien Jehannet # Date 1272470256 -7200 # Node ID 2455ca3a2a3aba8c98588a88f9c9b7ae28c2670f # Parent cc7d00a1b36e2596e709d43e79a87af184396b15 [c-c shell] make script arguments available as __args__ in the script namespace. Use scriptargs instead of args as process_script argument name. diff -r cc7d00a1b36e -r 2455ca3a2a3a 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. 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: diff -r cc7d00a1b36e -r 2455ca3a2a3a migration.py --- 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: diff -r cc7d00a1b36e -r 2455ca3a2a3a test/data/scripts/script1.py --- 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__ diff -r cc7d00a1b36e -r 2455ca3a2a3a test/data/scripts/script2.py --- 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__ diff -r cc7d00a1b36e -r 2455ca3a2a3a test/data/scripts/script3.py --- 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__ diff -r cc7d00a1b36e -r 2455ca3a2a3a test/unittest_cwctl.py --- 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__':