[z3-checkins] r13679 - z3/zopejam/trunk/src/zopejam
hathawsh at codespeak.net
hathawsh at codespeak.net
Wed Jun 22 09:28:06 CEST 2005
Author: hathawsh
Date: Wed Jun 22 09:28:04 2005
New Revision: 13679
Added:
z3/zopejam/trunk/src/zopejam/inspector.py
Modified:
z3/zopejam/trunk/src/zopejam/main.py
Log:
Load directive schemas using a partially isolated inspector module.
Added: z3/zopejam/trunk/src/zopejam/inspector.py
==============================================================================
--- (empty file)
+++ z3/zopejam/trunk/src/zopejam/inspector.py Wed Jun 22 09:28:04 2005
@@ -0,0 +1,78 @@
+
+# (c) 2005 Shane Hathaway
+# License: ZPL 2.1
+
+"""This standalone module inspects configured code.
+
+Zope Jam uses this module to provide a degree of isolation between the
+configuration UI and code under development. Also, this strategy
+makes it possible to re-inspect some of the code without restarting.
+
+"""
+
+import cPickle
+import os
+import sys
+
+from zope.interface.interfaces import IInterface
+
+_import_chickens = {}, {}, ("*",) # dead chickens needed by __import__
+
+
+def inspect_interfaces(names):
+ """Returns {name: {'doc', 'bases', 'attrs' | 'error'}}"""
+ res = {}
+ # the names are absolute.
+ todo = list(names)
+ while todo:
+ name = todo.pop()
+ if res.has_key(name):
+ continue
+ info = {}
+ res[name] = info
+
+ pos = name.rfind('.')
+ if pos >= 0:
+ mname = name[:pos]
+ oname = name[pos + 1:]
+ else:
+ mname = ''
+ oname = name
+
+ try:
+ module = __import__(mname, *_import_chickens)
+ obj = getattr(module, oname)
+ except:
+ info['error'] = str(sys.exc_info()[1])
+ continue
+
+ if IInterface.providedBy(obj):
+ info['doc'] = getattr(obj, '__doc__', None)
+ bases = []
+ for base in getattr(obj, '__bases__', ()):
+ m = getattr(base, '__module__', None)
+ n = getattr(base, '__name__', None)
+ if m and n:
+ fullname = '%s.%s' % (m, n)
+ bases.append(fullname)
+ if not res.has_key(fullname):
+ todo.append(fullname)
+ info['bases'] = bases
+ attrs = {}
+ for n in obj.names(False):
+ attrs[n] = obj[n]
+ info['attrs'] = attrs
+ else:
+ info['error'] = 'not an interface; type is %s' % str(type(obj))
+ return res
+
+
+def main():
+ # pickle in, pickle out.
+ funcname, args, kwargs = cPickle.load(sys.stdin)
+ func = globals()[funcname]
+ res = func(*args, **kwargs)
+ cPickle.dump(res, sys.stdout, protocol=2)
+
+if __name__ == '__main__':
+ main()
Modified: z3/zopejam/trunk/src/zopejam/main.py
==============================================================================
--- z3/zopejam/trunk/src/zopejam/main.py (original)
+++ z3/zopejam/trunk/src/zopejam/main.py Wed Jun 22 09:28:04 2005
@@ -5,9 +5,11 @@
"""Zope Jam main
"""
-# Note: all development currently uses wxPython 2.6.
+# Note: all development currently uses wxPython 2.6 and Python 2.4.
+import cPickle
import os
+import subprocess
import sys
import time
import wx
@@ -67,7 +69,7 @@
raise RuntimeError('conflict on %s' % repr(dfn.fullname))
self.definitions[dfn.fullname] = dfn
- if 1:
+ if 0:
print len(self.definitions)
items = self.definitions.items()
items.sort()
@@ -84,6 +86,35 @@
end = time.time()
print '%d directives found in %f seconds' % (count, end - start)
+ self.load_definition_schemas()
+
+ def call_inspector(self, funcname, *args, **kw):
+ start = time.time()
+ inspector_py = os.path.join(here, 'inspector.py')
+ env = os.environ.copy()
+ env['PYTHONPATH'] = os.pathsep.join(self.pythonpath)
+ p = subprocess.Popen(
+ [self.interpreter, inspector_py],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ env=env)
+ cPickle.dump((funcname, args, kw), p.stdin, protocol=2)
+ res_pickle = p.stdout.read()
+ exit_code = p.wait()
+ if exit_code:
+ raise RuntimeError(
+ "inspector failed with exit code %s" % exit_code)
+ print 'pickle size:', len(res_pickle)
+ res = cPickle.loads(res_pickle)
+ end = time.time()
+ print "inspect time", end - start
+ return res
+
+ def load_definition_schemas(self):
+ names = [dfn.abs_schema for dfn in self.definitions.values()]
+ self.schemas = self.call_inspector('inspect_interfaces', names)
+ import pprint
+ pprint.pprint(self.schemas)
class PaletteImageList(wx.ImageList):
More information about the z3-checkins
mailing list