def start_http(address, port): import sys from ZServer import asyncore from ZServer import zhttp_server, zhttp_handler import socket import Zope # Sigh, make product initialization happen try: Zope.startup() except: # Zope > 2.6 pass from ZServer import setNumberOfThreads setNumberOfThreads(4) try: hs = zhttp_server( ip=address, port=port, resolver=None, logger_object=None) except socket.error, why: if why[0] == 98: # address in use raise port_err % {'port':port, 'socktype':'TCP', 'protocol':'HTTP', 'switch':'-w'} raise
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 setUp(self): """ """ import Zope Zope.startup() self.connection = Zope.DB.open() get_transaction().begin() try: self.root = makerequest.makerequest(self.connection.root()['Application']) except: print "error1" self.tearDown() raise
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 __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', ['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 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 live(self): LOG('QueuedCatalog', INFO, 'Set up to process queue entries') 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 = application.unrestrictedTraverse( queue_catalog_path) queue_catalog.process() except: LOG('QueuedCatalog', ERROR, 'Queue processing failed', error=sys.exc_info()) else: LOG('QueuedCatalog', INFO, 'Processed queue') 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 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 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() addConfiguredSite(app, 'testing', 'default', snapshot=False) self.root = app.testing
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): 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 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 test_suite(): import Zope try: Zope.startup() except AttributeError: # Zope <= 2.6.0 pass from Products.CMFCore.tests.base.utils import build_test_suite suite = unittest.TestSuite() packages = PACKAGES_UNDER_TEST or CMF_PACKAGES for package_name, required in packages: dotted = 'Products.%s.tests' % package_name suite.addTest(build_test_suite(dotted, ['test_all'], required=required)) return suite
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 test_suite(): import Zope try: Zope.startup() except AttributeError: # Zope <= 2.6.0 pass from Products.CMFCore.tests.base.utils import build_test_suite suite = unittest.TestSuite() packages = PACKAGES_UNDER_TEST or CMF_PACKAGES for package_name, required in packages: dotted = 'Products.%s.tests' % package_name suite.addTest( build_test_suite( dotted , [ 'test_all' ] , required=required ) ) return suite
def test_suite(): import Zope if hasattr(Zope,'startup'): Zope.startup() suite = TestSuite() from test_AcquireUsage import test_suite suite.addTest(test_suite()) from test_Creation import test_suite suite.addTest(test_suite()) from test_PythonScriptUsage import test_suite suite.addTest(test_suite()) from test_ContainedUsage import test_suite suite.addTest(test_suite()) from test_SQLUsage import test_suite suite.addTest(test_suite()) from test_SubclassUsage import test_suite suite.addTest(test_suite()) from test_Unconfigured import test_suite suite.addTest(test_suite()) from test_Broken import test_suite suite.addTest(test_suite()) from test_User import test_suite suite.addTest(test_suite()) return suite
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()
# 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. # ############################################################################## """Tests for CMFStaging. $Id$ """ import unittest import Testing import Zope Zope.startup() from Products.CMFStaging.tests.testLockTool import test_suite as lock_tests from Products.CMFStaging.tests.testVersions import test_suite as version_tests from Products.CMFStaging.tests.testStaging import test_suite as staging_tests def suite(): suite = unittest.TestSuite() suite.addTest(lock_tests()) suite.addTest(version_tests()) suite.addTest(staging_tests()) return suite def test_suite(): # Just to silence the top-level test.py return None
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 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 ): if hasattr(Zope, 'startup'): Zope.startup() get_transaction().begin() self.connection = Zope.DB.open() self.root = self.connection.root()[ 'Application' ]
def setUp(self): get_transaction().begin() self._policy = UnitTestSecurityPolicy() SecurityManager.setSecurityPolicy(self._policy) self.root = Zope.app()
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',
def setUp(self): if hasattr(Zope, 'startup'): Zope.startup() get_transaction().begin() self.connection = Zope.DB.open() self.root = self.connection.root()['Application']
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 setUp( self ): get_transaction().begin() self.root = Zope.app()
def setUp( self ): get_transaction().begin() self._policy = UnitTestSecurityPolicy() SecurityManager.setSecurityPolicy(self._policy) self.root = Zope.app() newSecurityManager( None, UnitTestUser().__of__( self.root ) )