[Zope-Checkins] CVS: Zope/lib/python/Zope/Startup - zopectl.py:1.3.2.7

Chris McDonough chrism at plope.com
Tue Feb 24 00:44:02 EST 2004


Update of /cvs-repository/Zope/lib/python/Zope/Startup
In directory cvs.zope.org:/tmp/cvs-serv6633

Modified Files:
      Tag: Zope-2_7-branch
	zopectl.py 
Log Message:
Pass along command line args to scripts called via "zopectl run".  This allows
you to use scripts which require arguments under zopectl run.

If you do "zopectl run scriptname.py arg1 arg2", the value of sys.argv 
within the script will consist of ['scriptname.py', 'arg1', 'arg2'].


=== Zope/lib/python/Zope/Startup/zopectl.py 1.3.2.6 => 1.3.2.7 ===
--- Zope/lib/python/Zope/Startup/zopectl.py:1.3.2.6	Sun Dec 21 19:24:25 2003
+++ Zope/lib/python/Zope/Startup/zopectl.py	Tue Feb 24 00:43:59 2004
@@ -152,14 +152,25 @@
         print "         manually using a Python interactive shell"
 
     def do_run(self, arg):
-        cmdline = self.get_startup_cmd(self.options.python,
-            'import Zope; app=Zope.app(); execfile(\'%s\')' % arg)
+        tup = arg.split(' ')
+        if not arg:
+            print "usage: run <script> [args]"
+            return
+        # remove -c and add script as sys.argv[0]
+        script = tup[0]
+        cmd = 'import sys; sys.argv.pop(); sys.argv.append(\'%s\');'  % script
+        if len(tup) > 1:
+            argv = tup[1:]
+            cmd += '[sys.argv.append(x) for x in %s];' % argv
+        cmd += 'import Zope; app=Zope.app(); execfile(\'%s\')' % script
+        cmdline = self.get_startup_cmd(self.options.python, cmd)
         os.system(cmdline)
 
     def help_run(self):
-        print "run <script> -- run a Python script with the Zope environment"
-        print "                set up.  The script can use the name 'app' to"
-        print "                access the top-level Zope object"
+        print "run <script> [args] -- run a Python script with the Zope "
+        print "                       environment set up.  The script can use "
+        print "                       the name 'app' access the top-level Zope"
+        print "                       object"
 
     def do_adduser(self, arg):
         try:




More information about the Zope-Checkins mailing list