[Zope3-checkins] SVN: Zope3/trunk/ added "debug" command to zopectl

Fred L. Drake, Jr. fdrake at gmail.com
Thu Oct 21 16:03:54 EDT 2004


Log message for revision 28236:
  added "debug" command to zopectl

Changed:
  _U  Zope3/trunk/bin/
  A   Zope3/trunk/bin/debugzope
  A   Zope3/trunk/bin/zopectl
  U   Zope3/trunk/src/zope/app/debug/debug.py
  A   Zope3/trunk/src/zope/app/server/controller.py
  U   Zope3/trunk/src/zope/app/server/main.py
  A   Zope3/trunk/zopeskel/bin/debugzope.in
  U   Zope3/trunk/zopeskel/bin/zopectl.in

-=-

Property changes on: Zope3/trunk/bin
___________________________________________________________________
Name: svn:ignore
   - zopectl
runzope

   + runzope


Added: Zope3/trunk/bin/debugzope
===================================================================
--- Zope3/trunk/bin/debugzope	2004-10-21 18:53:16 UTC (rev 28235)
+++ Zope3/trunk/bin/debugzope	2004-10-21 20:03:53 UTC (rev 28236)
@@ -0,0 +1,59 @@
+#!/usr/bin/env python2.3
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Script to run the Zope Application Server from the Python prompt.
+
+$Id$
+"""
+import os
+import sys
+
+os.environ["PYTHONINSPECT"] = "true"
+
+SCRIPT_NAME = os.path.abspath(__file__)
+INSTANCE_HOME = os.path.dirname(os.path.dirname(SCRIPT_NAME))
+del SCRIPT_NAME
+SOFTWARE_HOME = os.path.join(INSTANCE_HOME, "src")
+
+if SOFTWARE_HOME not in sys.path:
+    sys.path.insert(0, SOFTWARE_HOME)
+
+CONFIG_FILE = os.path.join(INSTANCE_HOME, "zope.conf")
+if not os.path.exists(CONFIG_FILE):
+    CONFIG_FILE += ".in"
+
+
+def startup():
+    # This removes the script directory from sys.path, which we do
+    # since there are no modules here.
+    #
+    basepath = filter(None, sys.path)
+
+    sys.path[:] = [os.path.join(INSTANCE_HOME, "lib", "python"),
+                   SOFTWARE_HOME] + basepath
+
+    from zope.app.server.main import debug
+    db = debug(["-C", CONFIG_FILE] + sys.argv[1:])
+    if "PYTHONSTARTUP" in os.environ:
+        execfile(os.environ["PYTHONSTARTUP"])
+    return db
+
+
+if __name__ == '__main__':
+    db = startup()
+    del startup
+    from zope.app.debug import Debugger
+    debugger = Debugger.fromDatabase(db)
+    del db
+    del Debugger


Property changes on: Zope3/trunk/bin/debugzope
___________________________________________________________________
Name: svn:executable
   + *

Added: Zope3/trunk/bin/zopectl
===================================================================
--- Zope3/trunk/bin/zopectl	2004-10-21 18:53:16 UTC (rev 28235)
+++ Zope3/trunk/bin/zopectl	2004-10-21 20:03:53 UTC (rev 28236)
@@ -0,0 +1,19 @@
+#!/usr/bin/env python2.3
+
+import os
+import sys
+
+SCRIPT_NAME = os.path.abspath(__file__)
+INSTANCE_HOME = os.path.dirname(os.path.dirname(SCRIPT_NAME))
+SOFTWARE_HOME = os.path.join(INSTANCE_HOME, "src")
+
+if SOFTWARE_HOME not in sys.path:
+    sys.path.insert(0, SOFTWARE_HOME)
+
+CONFIG_FILE = os.path.join(INSTANCE_HOME, "zdaemon.conf")
+
+sys.argv[1:1] = ["-C", CONFIG_FILE]
+
+
+from zope.app.server.controller import main
+main()


Property changes on: Zope3/trunk/bin/zopectl
___________________________________________________________________
Name: svn:executable
   + *

Modified: Zope3/trunk/src/zope/app/debug/debug.py
===================================================================
--- Zope3/trunk/src/zope/app/debug/debug.py	2004-10-21 18:53:16 UTC (rev 28235)
+++ Zope3/trunk/src/zope/app/debug/debug.py	2004-10-21 20:03:53 UTC (rev 28236)
@@ -35,6 +35,12 @@
             config(config_file)
         self.db = database(db)
 
+    def fromDatabase(cls, db):
+        inst = cls.__new__(cls)
+        inst.db = db
+        return inst
+    fromDatabase = classmethod(fromDatabase)
+
     def root(self):
         """Get the top-level application object
 

Added: Zope3/trunk/src/zope/app/server/controller.py
===================================================================
--- Zope3/trunk/src/zope/app/server/controller.py	2004-10-21 18:53:16 UTC (rev 28235)
+++ Zope3/trunk/src/zope/app/server/controller.py	2004-10-21 20:03:53 UTC (rev 28236)
@@ -0,0 +1,38 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Top-level controller for 'zopectl'.
+"""
+
+import os
+
+import zdaemon.zdctl
+
+
+INSTANCE_HOME = os.path.dirname(
+    os.path.dirname(os.path.dirname(zdaemon.__file__)))
+
+
+class ZopectlCmd(zdaemon.zdctl.ZDCmd):
+
+    def do_debug(self, rest):
+        cmdline = "%s/bin/debugzope" % INSTANCE_HOME
+        os.system(cmdline)
+
+    def help_debug(self):
+        print "debug -- Initialize the Zope application, providing a"
+        print "         debugger object at an interactive Python prompt."
+
+
+def main(args=None, options=None, cmdclass=ZopectlCmd):
+    zdaemon.zdctl.main(args, options, cmdclass)


Property changes on: Zope3/trunk/src/zope/app/server/controller.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:eol-style
   + native

Modified: Zope3/trunk/src/zope/app/server/main.py
===================================================================
--- Zope3/trunk/src/zope/app/server/main.py	2004-10-21 18:53:16 UTC (rev 28235)
+++ Zope3/trunk/src/zope/app/server/main.py	2004-10-21 20:03:53 UTC (rev 28236)
@@ -50,7 +50,7 @@
     t0 = time.time()
     c0 = time.clock()
 
-    setup(args)
+    setup(load_options(args))
 
     t1 = time.time()
     c1 = time.clock()
@@ -60,6 +60,16 @@
     sys.exit(0)
 
 
+def debug(args=None):
+    options = load_options(args)
+
+    zope.app.appsetup.config(options.site_definition)
+
+    db = options.database.open()
+    notify(zope.app.appsetup.DatabaseOpened(db))
+    return db
+
+
 def run():
     try:
         ThreadedAsync.loop()
@@ -68,7 +78,7 @@
         pass
 
 
-def setup(args=None):
+def load_options(args=None):
     if args is None:
         args = sys.argv[1:]
     options = ZopeOptions()
@@ -78,7 +88,10 @@
 
     if options.path:
         sys.path[:0] = [os.path.abspath(p) for p in options.path]
+    return options
 
+
+def setup(options):
     sys.setcheckinterval(options.check_interval)
 
     options.eventlog()

Added: Zope3/trunk/zopeskel/bin/debugzope.in
===================================================================
--- Zope3/trunk/zopeskel/bin/debugzope.in	2004-10-21 18:53:16 UTC (rev 28235)
+++ Zope3/trunk/zopeskel/bin/debugzope.in	2004-10-21 20:03:53 UTC (rev 28236)
@@ -0,0 +1,50 @@
+#!<<PYTHON>> -i
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Script to run the Zope Application Server from the Python prompt.
+
+$Id$
+"""
+import os
+import sys
+
+
+SOFTWARE_HOME = "<<SOFTWARE_HOME>>"
+INSTANCE_HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+CONFIG_FILE = os.path.join(INSTANCE_HOME, "etc", "zope.conf")
+
+
+def startup():
+    # This removes the script directory from sys.path, which we do
+    # since there are no modules here.
+    #
+    basepath = filter(None, sys.path)
+
+    sys.path[:] = [os.path.join(INSTANCE_HOME, "lib", "python"),
+                   SOFTWARE_HOME] + basepath
+
+    from zope.app.server.main import debug
+    db = debug(["-C", CONFIG_FILE] + sys.argv[1:])
+    if "PYTHONSTARTUP" in os.environ:
+        execfile(os.environ["PYTHONSTARTUP"])
+    return db
+
+
+if __name__ == '__main__':
+    db = startup()
+    del startup
+    from zope.app.debug import Debugger
+    debugger = Debugger.fromDatabase(db)
+    del db
+    del Debugger


Property changes on: Zope3/trunk/zopeskel/bin/debugzope.in
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Modified: Zope3/trunk/zopeskel/bin/zopectl.in
===================================================================
--- Zope3/trunk/zopeskel/bin/zopectl.in	2004-10-21 18:53:16 UTC (rev 28235)
+++ Zope3/trunk/zopeskel/bin/zopectl.in	2004-10-21 20:03:53 UTC (rev 28236)
@@ -34,8 +34,9 @@
     sys.path[:] = [os.path.join(INSTANCE_HOME, "lib", "python"),
                    SOFTWARE_HOME] + basepath
 
-    from zdaemon.zdctl import main
-    main(["-C", CONFIG_FILE] + sys.argv[1:])
+    import zope.app.server.controller
+    zope.app.server.controller.INSTANCE_HOME = INSTANCE_HOME
+    zope.app.server.controller.main(["-C", CONFIG_FILE] + sys.argv[1:])
 
 
 if __name__ == '__main__':



More information about the Zope3-Checkins mailing list