home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from IPython import ipapi
- from IPython import Release
- from types import StringType
- import sys
- import os
- import textwrap
- _marker = []
-
- def shasattr(obj, attr, acquire = False):
- if not acquire:
- obj = obj.aq_base
-
- return getattr(obj, attr, _marker) is not _marker
-
-
- class ZopeDebug(object):
-
- def __init__(self):
- self.instancehome = os.environ.get('INSTANCE_HOME')
- configfile = os.environ.get('CONFIG_FILE')
- if configfile is None and self.instancehome is not None:
- configfile = os.path.join(self.instancehome, 'etc', 'zope.conf')
-
- if configfile is None:
- raise RuntimeError('CONFIG_FILE env not set')
- configfile is None
- print 'CONFIG_FILE=', configfile
- print 'INSTANCE_HOME=', self.instancehome
- self.configfile = configfile
-
- try:
- configure = configure
- import Zope2
- except ImportError:
- configure = configure
- import Zope
-
- configure(configfile)
-
- try:
- import Zope2
- app = Zope2.app()
- except ImportError:
- import Zope
- app = Zope.app()
-
- makerequest = makerequest
- import Testing.makerequest
- self.app = makerequest(app)
-
- try:
- self._make_permissive()
- print 'Permissive security installed'
- except:
- print 'Permissive security NOT installed'
-
- if not self.portal:
- pass
- self._pwd = self.app
-
- try:
- getSiteManager = getSiteManager
- import zope.component
- getGlobalSiteManager = getGlobalSiteManager
- import zope.component
- setSite = setSite
- import zope.app.component.hooks
- if self.portal is not None:
- setSite(self.portal)
- gsm = getGlobalSiteManager()
- sm = getSiteManager()
- if sm is gsm:
- print 'ERROR SETTING SITE!'
-
- except:
- pass
-
-
-
- def utils(self):
-
- class Utils((object,)):
- commit = self.commit
- sync = self.sync
- objectInfo = self.objectInfo
- ls = self.ls
- pwd = self.pwd
- cd = self.cd
- su = self.su
- getCatalogInfo = self.getCatalogInfo
-
- def cwd(self):
- return self.pwd()
-
- cwd = property(cwd)
-
- return Utils()
-
- utils = property(utils)
-
- def namespace(self):
- return dict(utils = self.utils, app = self.app, portal = self.portal)
-
- namespace = property(namespace)
-
- def portal(self):
- portals = self.app.objectValues('Plone Site')
- if len(portals):
- return portals[0]
- raise KeyError('No Plone Site found.')
-
- portal = property(portal)
-
- def pwd(self):
- return self._pwd
-
-
- def _make_permissive(self):
- PermissiveSecurityPolicy = PermissiveSecurityPolicy
- import Products.CMFCore.tests.base.security
- import AccessControl
- newSecurityManager = newSecurityManager
- import AccessControl.SecurityManagement
- setSecurityPolicy = setSecurityPolicy
- import AccessControl.SecurityManager
- _policy = PermissiveSecurityPolicy()
- self.oldpolicy = setSecurityPolicy(_policy)
- newSecurityManager(None, AccessControl.User.system)
-
-
- def su(self, username):
- user = self.portal.acl_users.getUser(username)
- if not user:
- print "Can't find %s in %s" % (username, self.portal.acl_users)
- return None
- ZopeSecurityPolicy = ZopeSecurityPolicy
- import AccessControl
- import AccessControl
- newSecurityManager = newSecurityManager
- getSecurityManager = getSecurityManager
- import AccessControl.SecurityManagement
- setSecurityPolicy = setSecurityPolicy
- import AccessControl.SecurityManager
- _policy = ZopeSecurityPolicy
- self.oldpolicy = setSecurityPolicy(_policy)
- wrapped_user = user.__of__(self.portal.acl_users)
- newSecurityManager(None, user)
- print 'User changed.'
- return getSecurityManager().getUser()
-
-
- def getCatalogInfo(self, obj = None, catalog = 'portal_catalog', query = None, sort_on = 'created', sort_order = 'reverse'):
- if obj and query:
- print 'Ignoring %s, using query.' % obj
-
- catalog = self.portal.get(catalog)
- if not catalog:
- return 'No catalog'
- indexes = catalog._catalog.indexes
- if not query:
- if type(obj) is StringType:
- cwd = self.pwd()
- obj = cwd.unrestrictedTraverse(obj)
-
- query = { }
- if indexes.get('path'):
- join = join
- import string
- path = join(obj.getPhysicalPath(), '/')
- query.update({
- 'path': path })
-
- if indexes.get('getID'):
- query.update({
- 'getID': obj.id })
-
- if indexes.get('UID') and shasattr(obj, 'UID'):
- query.update({
- 'UID': obj.UID() })
-
-
- if indexes.get(sort_on):
- query.update({
- 'sort_on': sort_on,
- 'sort_order': sort_order })
-
- if not query:
- return 'Empty query'
- results = catalog(**query)
- result_info = []
- for r in results:
- rid = r.getRID()
- if rid:
- result_info.append({
- 'path': catalog.getpath(rid),
- 'metadata': catalog.getMetadataForRID(rid),
- 'indexes': catalog.getIndexDataForRID(rid) })
- continue
- query
- result_info.append({
- 'missing': rid })
-
- if len(result_info) == 1:
- return result_info[0]
- return result_info
-
-
- def commit(self):
-
- try:
- import transaction
- transaction.get().commit()
- except ImportError:
- get_transaction().commit()
-
-
-
- def sync(self):
- self.app._p_jar.sync()
-
-
- def objectInfo(self, o):
- Title = ''
- t = getattr(o, 'Title', None)
- if t:
- Title = t()
-
- return {
- 'id': o.getId(),
- 'Title': Title,
- 'portal_type': getattr(o, 'portal_type', o.meta_type),
- 'folderish': o.isPrincipiaFolderish }
-
-
- def cd(self, path):
- if type(path) is not StringType:
- path = '/'.join(path.getPhysicalPath())
-
- cwd = self.pwd()
- x = cwd.unrestrictedTraverse(path)
- if x is None:
- raise KeyError("Can't cd to %s" % path)
- x is None
- print '%s -> %s' % (self.pwd().getId(), x.getId())
- self._pwd = x
-
-
- def ls(self, x = None):
- if type(x) is StringType:
- cwd = self.pwd()
- x = cwd.unrestrictedTraverse(x)
-
- if x is None:
- x = self.pwd()
-
- if x.isPrincipiaFolderish:
- return [ self.objectInfo(o) for id, o in x.objectItems() ]
- return self.objectInfo(x)
-
-
- zope_debug = None
-
- def ipy_set_trace():
- import IPython
- IPython.Debugger.Pdb().set_trace()
-
-
- def main():
- global zope_debug
- ip = ipapi.get()
- o = ip.options
- SOFTWARE_HOME = os.environ.get('SOFTWARE_HOME')
- sys.path.append(SOFTWARE_HOME)
- print 'SOFTWARE_HOME=%s\n' % SOFTWARE_HOME
- zope_debug = ZopeDebug()
- import pdb
- pdb.set_trace = ipy_set_trace
- o.banner = 'ZOPE Py %s IPy %s\n' % (sys.version.split('\n')[0], Release.version)
- print ','.join([] % [](_[1]))
- ip.user_ns.update(zope_debug.namespace)
-
- main()
-