def main(): from optparse import OptionParser import Zope gc.enable() app = Zope.app() parser = OptionParser() parser.add_option('-u', '--user', dest='username', default='admin') parser.add_option('-p', '--path', dest='path', default='') parser.add_option('-o', '--output', dest='output', default='') parser.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False) parser.add_option('-i', '--ignore', dest='ignored_types', action='store', default=IGNORED_TYPES, help="Provide comma separated List of Portal Types " "to ignore") parser.add_option('-b', '--batch_size', dest='batch_size', default=0) parser.add_option('-s', '--batch_start', dest='batch_start', default=0) options, args = parser.parse_args() options.app = app if isinstance(options.ignored_types, basestring): options.ignored_types = options.ignored_types.split(',') options.batch_start = int(options.batch_start) options.batch_size = int(options.batch_size) export_site(app, options) transaction.commit()
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") print "CONFIG_FILE=", configfile print "INSTANCE_HOME=", self.instancehome self.configfile = configfile try: from Zope2 import configure except ImportError: from Zope import configure configure(configfile) try: import Zope2 app = Zope2.app() except ImportError: import Zope app = Zope.app() from Testing.makerequest import makerequest self.app = makerequest(app) try: self._make_permissive() print "Permissive security installed" except: print "Permissive security NOT installed" self._pwd = self.portal or self.app try: from zope.component import getSiteManager from zope.component import getGlobalSiteManager try: from zope.app.component.hooks import setSite except ImportError: from zope.component.hooks import setSite if self.portal is not None: setSite(self.portal) gsm = getGlobalSiteManager() sm = getSiteManager() if sm is gsm: print "ERROR SETTING SITE!" except: # XXX: What exceptions is this supposed to catch? pass
def setUp(self): get_transaction().begin() self.app = makerequest(Zope.app()) # Log in as a god :-) newSecurityManager(None, UnrestrictedUser('god', 'god', [], '')) app = self.app app.REQUEST.set('URL1', 'http://foo/sorcerertest/test') try: app._delObject('CalendarTest') except AttributeError: pass app.manage_addProduct['CMFDefault'].manage_addCMFSite('CalendarTest') self.Site = app.CalendarTest manage_addExternalMethod(app.CalendarTest, id='install_events', title="Install Events", module="CMFCalendar.Install", function="install") ExMethod = app.restrictedTraverse('/CalendarTest/install_events') ExMethod() self.Tool = app.restrictedTraverse('/CalendarTest/portal_calendar') # sessioning bodge until we find out how to do this properly self.have_session = hasattr(app, 'session_data_manager') if self.have_session: app.REQUEST.set_lazy('SESSION', app.session_data_manager.getSessionData)
def setUp(self): get_transaction().begin() self.app = makerequest(Zope.app()) # Log in as a god :-) newSecurityManager( None, UnrestrictedUser('god', 'god', ['Manager'], '') ) app = self.app app.REQUEST.set('URL1','http://foo/sorcerertest/test') try: app._delObject('CalendarTest') except AttributeError: pass app.manage_addProduct['CMFDefault'].manage_addCMFSite('CalendarTest') self.Site = app.CalendarTest manage_addExternalMethod(app.CalendarTest, id='install_events', title="Install Events", module="CMFCalendar.Install", function="install") ExMethod = app.restrictedTraverse('/CalendarTest/install_events') ExMethod() self.Tool = app.restrictedTraverse('/CalendarTest/portal_calendar') # sessioning bodge until we find out how to do this properly self.have_session = hasattr( app, 'session_data_manager' ) if self.have_session: app.REQUEST.set_lazy( 'SESSION' , app.session_data_manager.getSessionData )
def setUp(self): # Set up an application with a repository, 3 stages, the tools, # and a little content in the repository. # Note that you don't actually need a CMF site to use staging! ;-) app = Zope.app() self.app = app self.conn = app._p_jar if hasattr(app, 'testroot'): app._delObject('testroot') app.manage_addProduct['OFSP'].manage_addFolder('testroot') self.root = app.testroot zvc = self.root.manage_addProduct['ZopeVersionControl'] zvc.addRepository('VersionRepository') self.root.manage_addProduct['OFSP'].manage_addFolder('Stages') self.stages = self.root.Stages self.stages.manage_addProduct['OFSP'].manage_addFolder('Development') self.stages.manage_addProduct['OFSP'].manage_addFolder('Review') self.stages.manage_addProduct['OFSP'].manage_addFolder('Production') self.root.manage_addProduct['CMFStaging'].manage_addTool( StagingTool.meta_type) dev_stage = self.stages.Development dev_stage.manage_addProduct['OFSP'].manage_addFolder('c1') dev_stage.manage_addProduct['OFSP'].manage_addFolder('c2') dev_stage.manage_addProduct['OFSP'].manage_addFolder('nonv') self.dev_stage = dev_stage self.review_stage = self.stages.Review self.prod_stage = self.stages.Production repo = self.root.VersionRepository repo.applyVersionControl(dev_stage.c1) repo.applyVersionControl(dev_stage.c2)
def setUp(self): # Set up an application with a repository, 3 stages, the tools, # and a little content in the repository. # Note that you don't actually need a CMF site to use staging! ;-) app = Zope.app() self.app = app self.conn = app._p_jar if hasattr(app, 'testroot'): app._delObject('testroot') app.manage_addProduct['OFSP'].manage_addFolder('testroot') self.root = app.testroot zvc = self.root.manage_addProduct['ZopeVersionControl'] zvc.addRepository('VersionRepository') self.root.manage_addProduct['OFSP'].manage_addFolder('Stages') self.stages = self.root.Stages self.stages.manage_addProduct['OFSP'].manage_addFolder('Development') self.stages.manage_addProduct['OFSP'].manage_addFolder('Review') self.stages.manage_addProduct['OFSP'].manage_addFolder('Production') self.root.manage_addProduct['CMFStaging'].manage_addTool( StagingTool.meta_type) self.root.portal_staging._stages = ( ('dev', 'Development', 'Stages/Development'), ('review', 'Review', 'Stages/Review'), ('prod', 'Production', 'Stages/Production'), ) dev_stage = self.stages.Development dev_stage.manage_addProduct['OFSP'].manage_addFolder('nonv') self.dev_stage = dev_stage self.review_stage = self.stages.Review self.prod_stage = self.stages.Production self._addContent() user = TestUser('sally') newSecurityManager(None, user.__of__(self.root.acl_users))
def live(self): while 1: sleep(self._interval) for queue_catalog_path in self._queue_catalog_paths: try: application = Zope.app() except: LOG('QueuedCatalog', PANIC, "Couldn't connect to database", error=sys.exc_info()) break # No point in doing any more paths right now else: try: queue_catalog = app.unrestrictedTraverse( queue_catalog_path) queue_catalog.process() except: LOG('QueuedCatalog', ERROR, 'Queue processing failed', error=sys.exc_info()) application._p_jar.close()
def main(): from optparse import OptionParser from AccessControl.SecurityManagement import newSecurityManager import Zope gc.enable() app = Zope.app() parser = OptionParser() parser.add_option('-u', '--user', dest='username', default='admin') parser.add_option('-p', '--path', dest='path', default='') parser.add_option('-o', '--output', dest='output', default='') parser.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False) parser.add_option('-i', '--ignore', dest='ignored_types', action='store', default=IGNORED_TYPES, help="Provide comma separated List of Portal Types " \ "to ignore") options, args = parser.parse_args() options.app = app if isinstance(options.ignored_types, basestring): options.ignored_types = options.ignored_types.split(',') export_site(app, options) transaction.commit()
def hist(n): import Zope app=Zope.app() import cPickle pickler=cPickle.Pickler(open("h%s.hist" % n, 'w')) h=app.cat._catalog.indexes['PrincipiaSearchSource'].histogram() pickler.dump(list(h.items()))
def setUp( self ): get_transaction().begin() # Set up a scratch CMFSite app = Zope.app() manage_addCMFSite( app, 'testing' ) self.root = app.testing
def setUp(self): get_transaction().begin() # Set up a scratch CMFSite app = Zope.app() addConfiguredSite(app, 'testing', 'default', snapshot=False) self.root = app.testing
def setUp( self ): get_transaction().begin() # Set up a scratch CMFSite app = Zope.app() addConfiguredSite(app, 'testing', 'default', snapshot=False) self.root = app.testing
def setUp(self): app = Zope.app() self.app = app app.real_cat = ZCatalog('real_cat') app.real_cat.addIndex('id', 'FieldIndex') app.real_cat.addIndex('meta_type', 'FieldIndex') app.queue_cat = QueueCatalog(3) # 3 buckets app.queue_cat.id = 'queue_cat' app.queue_cat.manage_edit(location='/real_cat', immediate_indexes=['id'])
def base(): try: os.unlink('../../var/Data.fs') except: pass import Zope app=Zope.app() if len(sys.argv) > 3: max = atoi(sys.argv[3]) else: max = -1 print do(Zope.DB, loadmail, (app, 'mail', sys.argv[2], 1, max)) Zope.DB.close()
def connect_to_zodb(self): #connect to ZODB try: print '\tConnect to ZODB...\n' Zope.configure(os.environ['CONFIG_FILE']) self.root = Zope.app() self.root = self.makerequest() self.login_to_zodb() except Exception, error: #failed to connect to ZODB self.exit_script('\tFailed to connect to ZODB: %s.\n' % str(error))
def initmaili(n): import Zope app=Zope.app() try: import Products.BTreeFolder.BTreeFolder except: app.manage_addFolder(n) else: Products.BTreeFolder.BTreeFolder.manage_addBTreeFolder(app, n) get_transaction().commit() app._p_jar.close()
def setUp(self): app = Zope.app() self.app = app if hasattr(app, 'testroot'): app._delObject('testroot') app.manage_addProduct['OFSP'].manage_addFolder('testroot') self.root = app.testroot zvc = self.root.manage_addProduct['ZopeVersionControl'] zvc.addRepository('VersionRepository') setattr(self.root, VersionsTool.id, VersionsTool()) self.tool = getattr(self.root, VersionsTool.id) self.root.content = Folder() self.root.content.id = 'content'
def setUp(self): get_transaction().begin() self._policy = UnitTestSecurityPolicy() SecurityManager.setSecurityPolicy(self._policy) self.root = Zope.app() self.root._setObject('portal_discussion', DiscussionTool()) self.discussion_tool = self.root.portal_discussion self.root._setObject('portal_catalog', CatalogTool()) self.catalog_tool = self.root.portal_catalog self.root._setObject('portal_url', URLTool()) self.url_tool = self.root.portal_url self.root._setObject('portal_workflow', WorkflowTool()) self.workflow_tool = self.root.portal_workflow self.root._setObject('portal_types', TypesTool()) types_tool = self.types_tool = self.root.portal_types
def setUp(self): app = Zope.app() self.app = app if hasattr(app, 'testroot'): app._delObject('testroot') app.manage_addProduct['OFSP'].manage_addFolder('testroot') self.root = app.testroot setattr(self.root, LockTool.id, LockTool()) self.tool = getattr(self.root, LockTool.id) self.root.content = Folder() self.root.content.id = 'content' user = TestUser('sally') newSecurityManager(None, user.__of__(self.root.acl_users)) self.user = user
def setUp(self): self.app = makerequest(Zope.app()) try: self.app._delObject('catalogtest') except AttributeError: pass self.app.manage_addFolder('catalogtest') zcatalog = ZCatalog.ZCatalog('catalog', 'a catalog') self.app.catalogtest._setObject('catalog', zcatalog) c = self.app.catalogtest.catalog for x in ('title', 'to', 'from', 'date', 'raw'): try: c.manage_delIndex([x]) except: pass c.manage_addIndex('title', 'TextIndex') c.manage_addIndex('to', 'TextIndex') c.manage_addIndex('from', 'TextIndex') c.manage_addIndex('date', 'FieldIndex') c.manage_addIndex('raw', 'TextIndex')
def main(): from optparse import OptionParser from AccessControl.SecurityManagement import newSecurityManager import Zope gc.enable() app = Zope.app() parser = OptionParser() parser.add_option('-u', '--user', dest='username', default='admin') parser.add_option('-p', '--path', dest='path', default='') parser.add_option('-o', '--output', dest='output', default='') parser.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False) options, args = parser.parse_args() options.app = app export_site(app, options) transaction.commit()
def setUp(self): app = Zope.app() self.app = app if hasattr(app, 'testroot'): app._delObject('testroot') app.manage_addProduct['OFSP'].manage_addFolder('testroot') self.root = app.testroot zvc = self.root.manage_addProduct['ZopeVersionControl'] zvc.addRepository('VersionRepository') setattr(self.root, VersionsTool.id, VersionsTool()) self.tool = getattr(self.root, VersionsTool.id) self.root.content = Folder() self.root.content.id = 'content' user = TestUser('sally') newSecurityManager(None, user.__of__(self.root.acl_users))
def setUp(self): get_transaction().begin() self._policy = UnitTestSecurityPolicy() SecurityManager.setSecurityPolicy(self._policy) root = self.root = Zope.app() env = {'SERVER_NAME': 'http://localhost', 'SERVER_PORT': '80'} root.REQUEST = ZPublisher.HTTPRequest.HTTPRequest(None, env, None) root.addDummy = addDummy root._setObject('portal_types', TypesTool()) tool = root.portal_types FTI = FactoryTypeInformation tool._setObject( 'Dummy', FTI('Dummy', meta_type=DummyContent.meta_type, product='OFSP', factory='addDTMLDocument'))
def setUp( self ): get_transaction().begin() self._policy = UnitTestSecurityPolicy() SecurityManager.setSecurityPolicy(self._policy) root = self.root = Zope.app() env = { 'SERVER_NAME' : 'http://localhost' , 'SERVER_PORT' : '80' } root.REQUEST = ZPublisher.HTTPRequest.HTTPRequest( None, env, None ) root.addDummy = addDummy root._setObject( 'portal_types', TypesTool() ) tool = root.portal_types FTI = FactoryTypeInformation tool._setObject( 'Dummy' , FTI( 'Dummy' , meta_type=DummyContent.meta_type , product='OFSP' , factory='addDTMLDocument' ) )
def index(): os.environ['STUPID_LOG_FILE']='' os.environ['STUPID_LOG_SEVERITY']='-111' import Zope, Products.ZCatalog.ZCatalog import AccessControl.SecurityManagement, AccessControl.SpecialUsers app=Zope.app() Products.ZCatalog.ZCatalog.manage_addZCatalog(app, 'cat', '') try: app.cat.threshold = atoi(sys.argv[2]) except IndexError: app.cat.threashold = 1000 from Products.ZCTextIndex.ZCTextIndex \ import PLexicon from Products.ZCTextIndex.Lexicon \ import Splitter, CaseNormalizer app.cat._setObject('lex', PLexicon('lex', '', Splitter(), CaseNormalizer()) ) class extra: doc_attr = 'PrincipiaSearchSource' lexicon_id = 'lex' index_type = 'Okapi BM25 Rank' app.cat.addIndex('PrincipiaSearchSource', 'ZCTextIndex', extra) get_transaction().commit() system = AccessControl.SpecialUsers.system AccessControl.SecurityManagement.newSecurityManager(None, system) r=RE() r.PARENTS=[app.cat, app] print do(Zope.DB, indexf, (app,)) #hist(sys.argv[2]) Zope.DB.close()
def setUp( self ): get_transaction().begin() self.root = Zope.app()
def edit(): import Zope, thread nedit, ndel, nins = atoi(sys.argv[2]), atoi(sys.argv[3]), atoi(sys.argv[4]) try: threads=atoi(sys.argv[5]) except: threads=1 wait=0 else: try: wait=atof(sys.argv[6]) except: wait=0.25 wait = wait * 2 if threads==1: start_new_thread=apply else: start_new_thread=thread.start_new_thread db=Zope.DB app=Zope.app() number_of_messages=app.mail.number_of_messages app._p_jar.close() size=db.getSize() mem=VmSize() t=time.time() c=time.clock() alledits={} argss=[] for i in range(threads): lock=thread.allocate_lock() if threads > 1: lock.acquire() def returnf(t, c, size, mem, r, lock=lock): print c, r lock.release() else: def returnf(t, c, size, mem, r, lock=lock): print c, r edits=[0] while len(edits) <= nedit: edit=whrandom.randint(0, number_of_messages) if not alledits.has_key(edit): alledits[edit]=1 edits.append(edit) #print edits argss.append((lock, (edits, wait, ndel, nins), returnf)) for lock, args, returnf in argss: start_new_thread(do, (Zope.DB, incedit, args, returnf)) for lock, args, returnf in argss: lock.acquire() t=time.time() - t c=time.clock() - c size=db.getSize()-size mem=VmSize()-mem print t, c, size, mem #hist("e%s" % (threads)) Zope.DB.close()
def setUp(self): get_transaction().begin() self._policy = UnitTestSecurityPolicy() SecurityManager.setSecurityPolicy(self._policy) self.root = Zope.app()
import ZODB,Globals import OFS.Application import unittest import Zope from CMFOpenflow.CMFOpenflowTool import CMFOpenflowTool from CMFOpenflow.instance import instance from CMFOpenflow.workitem import workitem from CMFOpenflow.process import process from CMFOpenflow.activity import activity from CMFOpenflow.transition import transition Zope.app().Control_Panel.initialize_cache() class routingSimpleTestCase(unittest.TestCase): def setUp(self): # Create an OpenFlow folder self.of = CMFOpenflowTool('of') # Create a Process Definition with two activity (Begin, End) and one transition. self.of.addProcess(id='begin_end', BeginEnd=1) self.pd = getattr(self.of, 'begin_end') self.pd.addTransition(id='begin_end', From='Begin', To='End') getattr(self.pd, 'Begin').edit(kind='standard') getattr(self.pd, 'End').edit(kind='standard') # Create a Process Instance of the Process definition mentioned above pid = self.of.addInstance('begin_end', 'test', 'testComment', 'TestTitle', 0) self.pi = getattr(self.of, pid)
def setUp(self): self.app = makerequest(Zope.app()) get_transaction().begin() self.mbox = MailArchiveFolder(MBOX, '', MBOX_PATH, 0, '', '') self.app._setObject(MBOX, self.mbox)
def checkCatalog(path,indexes): """ perform some consistency checks on a ZCatalog instance""" root = Zope.app() try: catalog = root.unrestrictedTraverse(path) except AttributeError: print 'Error: catalog object not found' sys.exit(1) # get Catalog instance _cat = catalog._catalog # check Catalog internal BTrees l_data = list(_cat.data.keys()) l_data.sort() l_uids = list(_cat.uids.values()) l_uids.sort() l_paths = list(_cat.data.keys()) l_paths.sort() print "Checking catalog internal BTrees" print "\tINFO: Mapping data: %d entries" % len(l_data) print "\tINFO: Mapping uids: %d entries" % len(l_uids) print "\tINFO: Mapping paths: %d entries" % len(l_paths) if l_data == l_uids: print "\tOK: Mapping data equals Mapping uids" else: print "\tERR: Mapping data does not equal Mapping uids" if l_data == l_paths: print "\tOK: Mapping data equals Maaping paths" else: print "\tERR: Mapping data does not equal Maaping paths" # check BTrees of indexes for id,idx in _cat.indexes.items(): if indexes and not idx.meta_type in indexes: continue print "Checking index '%s' (type: %s)" % (id, idx.meta_type) if idx.meta_type in ['FieldIndex','KeywordIndex']: # check forward entries RIDS = IISet() for key, rids in idx._index.items(): if isinstance(rids,IntType): RIDS.insert( rids ) else: map(RIDS.insert , rids.keys()) diff = difference(RIDS, IISet(_cat.data.keys())) if len(diff)!=0: print '\tERR: Problem with forward entries' print '\tERR: too much forward entries:', diff else: print '\tOK: Forward entries (%d entries)' % (len(RIDS)) elif idx.meta_type in ['PathIndex']: RIDS = IISet() for rids in map(None,idx._index.values()): map(RIDS.insert , rids.values()[0]) diff = difference(RIDS, IISet(_cat.data.keys())) if len(diff)!=0: print '\tERR: Problem with forward entries' print '\tERR: too much forward entries:', diff else: print '\tOK: Forward entries (%d entries)' % (len(RIDS)) if idx.meta_type in ['FieldIndex','KeywordIndex','PathIndex']: # check backward entries RIDS = IISet(idx._unindex.keys()) diff = difference(RIDS, IISet(_cat.data.keys())) if len(diff)!=0: print '\tERR: Problem with backward entries' print '\tERR: too much backward entries:', diff else: print '\tOK: Backward entries (%d entries)' % (len(RIDS))
def setUp( self ): get_transaction().begin() self._policy = UnitTestSecurityPolicy() SecurityManager.setSecurityPolicy(self._policy) self.root = Zope.app() newSecurityManager( None, UnitTestUser().__of__( self.root ) )
from Products.CMFWiki.CMFWikiPage \ import CMFWikiPage, addCMFWikiFolder, addCMFWikiPage from Acquisition import aq_base, aq_parent, aq_inner from OFS import SimpleItem from Products.ZWiki import ZWikiPage from ZPublisher.Request import Request from ZPublisher.Response import Response from types import StringType old_folder_suffix = '_old_ZWiki' new_folder_suffix = '_new_CMFWiki' DIRNM = os.path.split(__file__)[0] app = Zope.app() IGNORE_PGS = ['HelpPage', 'HowDoIEdit', 'HowDoINavigate', 'RegulatingYourPages', 'StructuredText', 'StructuredTextExample', 'StructuredTextRules', 'TextFormattingRules', 'WikiName', 'WikiWikiWeb', 'ZWiki', 'ZWikiLinks', 'ZWikiWeb', 'editform',