[Checkins] SVN: zc.zope3recipes/trunk/zc/zope3recipes/debugzope.py handle $PYTHONSTARTUP the way it should be (like an interactive Python);

Fred Drake fdrake at gmail.com
Thu Mar 17 17:41:50 EDT 2011


Log message for revision 121013:
  handle $PYTHONSTARTUP the way it should be (like an interactive Python);
  globals defined by $PYTHONSTARTUP are in the environment you interact in

Changed:
  U   zc.zope3recipes/trunk/zc/zope3recipes/debugzope.py

-=-
Modified: zc.zope3recipes/trunk/zc/zope3recipes/debugzope.py
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/debugzope.py	2011-03-17 19:02:01 UTC (rev 121012)
+++ zc.zope3recipes/trunk/zc/zope3recipes/debugzope.py	2011-03-17 21:41:50 UTC (rev 121013)
@@ -40,17 +40,27 @@
     db = zope.app.appsetup.appsetup.multi_database(options.databases)[0][0]
     notify(zope.app.appsetup.interfaces.DatabaseOpened(db))
 
-    if "PYTHONSTARTUP" in os.environ:
-        execfile(os.environ["PYTHONSTARTUP"])
+    globs = {"__name__": "__main__"}
+    startup = os.environ.get("PYTHONSTARTUP")
+    if startup:
+        try:
+            f = open(startup)
+        except (OSError, IOError):
+            # Not readable or not there, which is allowed.
+            pass
+        else:
+            f.close()
+            globs["__file__"] = startup
+            execfile(startup, globs, globs)
+            del globs["__file__"]
 
     app = zope.app.debug.Debugger.fromDatabase(db)
-    return dict(
-        app = app,
-        debugger = app,
-        root = app.root(),
-        __name__ = '__main__',
-        )
+    globs["app"] = app
+    globs["debugger"] = app
+    globs["root"] = app.root()
 
+    return globs
+
 def debug(args=None, main_module=None):
     if args is None:
         args = sys.argv[1:]



More information about the checkins mailing list