[Zope-Checkins] SVN: Zope/trunk/ Merged c118727 from 2.12 branch

Hanno Schlichting hannosch at hannosch.eu
Tue Dec 7 09:30:30 EST 2010


Log message for revision 118731:
  Merged c118727 from 2.12 branch
  

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/doc/operation.rst
  U   Zope/trunk/src/Zope2/Startup/zopectl.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst	2010-12-07 14:29:52 UTC (rev 118730)
+++ Zope/trunk/doc/CHANGES.rst	2010-12-07 14:30:30 UTC (rev 118731)
@@ -11,6 +11,8 @@
 Bugs Fixed
 ++++++++++
 
+- Fixed argument parsing for entrypoint based zopectl commands.
+
 - Fixed the usage of ``pstats.Stats()`` output stream. The
   `Control_Panel/DebugInfo/manage_profile` ZMI view was broken in Python 2.5+.
 

Modified: Zope/trunk/doc/operation.rst
===================================================================
--- Zope/trunk/doc/operation.rst	2010-12-07 14:29:52 UTC (rev 118730)
+++ Zope/trunk/doc/operation.rst	2010-12-07 14:30:30 UTC (rev 118731)
@@ -177,17 +177,19 @@
    Due to an implementation detail of ``zopectl`` you can not use a minus
    character (``-``) in the command name.
 
-This adds a ``init_app`` command that can be used directly from the commandline::
+This adds a ``init_app`` command that can be used directly from the command
+line::
 
     bin\zopectl init_app
 
-The command must be implemented as a python callable. It will be called with
-two parameters: the Zope2 application and a tuple with all commandline
+The command must be implemented as a Python callable. It will be called with
+two parameters: the Zope2 application and a list with all command line
 arguments. Here is a basic example:
 
 .. code-block:: python
 
    def init_application(app, args):
-       print 'Initialisating the application'
+       print 'Initializing the application'
 
-
+Make sure the callable can be imported without side-effects, such as setting
+up the database connection used by Zope 2.

Modified: Zope/trunk/src/Zope2/Startup/zopectl.py
===================================================================
--- Zope/trunk/src/Zope2/Startup/zopectl.py	2010-12-07 14:29:52 UTC (rev 118730)
+++ Zope/trunk/src/Zope2/Startup/zopectl.py	2010-12-07 14:30:30 UTC (rev 118731)
@@ -366,8 +366,9 @@
             # ['run "arg 1" "arg2"'] rather than ['run','arg 1','arg2'].
             # If that's the case, we'll use csv to do the parsing
             # so that we can split on spaces while respecting quotes.
-            if len(self.options.args) == 1:
-                tup = csv.reader(self.options.args, delimiter=' ').next()
+            tup = self.options.args
+            if len(tup) == 1:
+                tup = csv.reader(tup, delimiter=' ').next()
 
             # Remove -c and add command name as sys.argv[0]
             cmd = [ 'import sys',
@@ -376,13 +377,14 @@
                    ]
             if len(tup) > 1:
                 argv = tup[1:]
-                cmd.append('[sys.argv.append(x) for x in %s]; ' % argv)
+                for a in argv:
+                    cmd.append('sys.argv.append(r\'%s\')' % a)
             cmd.extend([
                 'import pkg_resources',
                 'import Zope2',
                 'func=pkg_resources.EntryPoint.parse(\'%s\').load(False)' % entry_point,
                 'app=Zope2.app()',
-                'func(app)',
+                'func(app, sys.argv[1:])',
                 ])
             cmdline = self.get_startup_cmd(self.options.python, ' ; '.join(cmd))
             self._exitstatus = os.system(cmdline)



More information about the Zope-Checkins mailing list