zope.app.appsetup-3.16.0/0000755000175000017500000000000011520276664015056 5ustar ctheunectheunezope.app.appsetup-3.16.0/src/0000755000175000017500000000000011520276664015645 5ustar ctheunectheunezope.app.appsetup-3.16.0/src/zope/0000755000175000017500000000000011520276664016622 5ustar ctheunectheunezope.app.appsetup-3.16.0/src/zope/app/0000755000175000017500000000000011520276664017402 5ustar ctheunectheunezope.app.appsetup-3.16.0/src/zope/app/appsetup/0000755000175000017500000000000011520276664021243 5ustar ctheunectheunezope.app.appsetup-3.16.0/src/zope/app/appsetup/schema/0000755000175000017500000000000011520276664022503 5ustar ctheunectheunezope.app.appsetup-3.16.0/src/zope/app/appsetup/schema/productconfig.xml0000644000175000017500000000272711520276623026076 0ustar ctheunectheune Base type for component-specific configuration sections. Specific products should implement configuration sections by defining sections types that implement this abstract type and using their own schema component to define meaningful settings. Component-specific configuration, expressed as arbitrary name-value pairs. Component-specific configuration stanzas. Products may use the <product-config> section type, or may supply a component.xml which defines section types with their own schemas. All sections for this multisection will be collected together into the 'product_config' attribute of the configuration object. zope.app.appsetup-3.16.0/src/zope/app/appsetup/schema/schema.xml0000644000175000017500000000471611520276623024470 0ustar ctheunectheune Zope 3 Application Server configuration schema. This schema describes the configuration options available to a site administrator via the zope.conf configuration file for the Zope application server. Application database. At least one database must be specified. The first will be used as the main database. At most one of the databases can be unnamed. All of the databases specified will be part of a multi-database. See the ZODB documentation of multi-databases for details of how this is useful.
Configuration for the eventlog.
Additional loggers for specific subsystems The name of the top-level ZCML file that defines the component configuration used for this site. This specifies additional paths directories which are inserted into the beginning of Python's module search path. The set of directories specified is inserted into the beginning of the module search path in the order which they are specified here. Note that the processing of this directive may happen too late under some circumstances; it is recommended that you use the PYTHONPATH environment variable if using this directive doesn't work for you. $softwarehome/src Switches the Developer Mode on and off. In developer mode, the web UI will provide useful utilities for developers to work on Zope 3 applications. devmode on off
zope.app.appsetup-3.16.0/src/zope/app/appsetup/testdata/0000755000175000017500000000000011520276664023054 5ustar ctheunectheunezope.app.appsetup-3.16.0/src/zope/app/appsetup/testdata/pythonstartup0000644000175000017500000000003711520276623025736 0ustar ctheunectheuneimport sys sys.ps1 = 'debug> ' zope.app.appsetup-3.16.0/src/zope/app/appsetup/testdata/site.zcml0000644000175000017500000000072611520276623024707 0ustar ctheunectheune zope.app.appsetup-3.16.0/src/zope/app/appsetup/testdata/test.conf0000644000175000017500000000014311520276623024673 0ustar ctheunectheunesite-definition site.zcml zope.app.appsetup-3.16.0/src/zope/app/appsetup/testpackage/0000755000175000017500000000000011520276664023536 5ustar ctheunectheunezope.app.appsetup-3.16.0/src/zope/app/appsetup/testpackage/__init__.py0000644000175000017500000000003711520276623025642 0ustar ctheunectheune# This is a cool test package. zope.app.appsetup-3.16.0/src/zope/app/appsetup/testpackage/ftesting.zcml0000644000175000017500000000031411520276623026241 0ustar ctheunectheune zope.app.appsetup-3.16.0/src/zope/app/appsetup/testpackage/testobject.py0000644000175000017500000000010611520276623026246 0ustar ctheunectheune import persistent class TestObject(persistent.Persistent): pass zope.app.appsetup-3.16.0/src/zope/app/appsetup/testproduct/0000755000175000017500000000000011520276664023623 5ustar ctheunectheunezope.app.appsetup-3.16.0/src/zope/app/appsetup/testproduct/__init__.py0000644000175000017500000000076411520276623025736 0ustar ctheunectheune"""\ Sample section data type for product configuration tests. """ import ZConfig.components.basic.mapping import zope.app.appsetup.product def sampleProductConfig(section): mapping = ZConfig.components.basic.mapping.mapping(section) mapping["product-name"] = section.getSectionName() # Since this is a product config, we need a product configuration object, # not a bare mapping: return zope.app.appsetup.product.FauxConfiguration( mapping["product-name"], mapping) zope.app.appsetup-3.16.0/src/zope/app/appsetup/testproduct/component.xml0000644000175000017500000000043211520276623026341 0ustar ctheunectheune zope.app.appsetup-3.16.0/src/zope/app/appsetup/__init__.py0000644000175000017500000000174511520276623023356 0ustar ctheunectheune############################################################################## # # Copyright (c) 2004 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # 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. # ############################################################################## """Zope Application Server setup package $Id: __init__.py 113108 2010-06-04 11:53:16Z janwijbrand $ """ __docformat__ = 'restructuredtext' from zope.app.appsetup.appsetup import config, database #BBB from zope.app.appsetup.interfaces import IDatabaseOpenedEvent, DatabaseOpened from zope.app.appsetup.interfaces import IProcessStartingEvent, ProcessStarting zope.app.appsetup-3.16.0/src/zope/app/appsetup/appsetup.py0000644000175000017500000001622611520276623023460 0ustar ctheunectheune############################################################################## # # Copyright (c) 2002 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # 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. # ############################################################################## """Code to initialize the application server $Id: appsetup.py 113108 2010-06-04 11:53:16Z janwijbrand $ """ __docformat__ = 'restructuredtext' import ZODB.ActivityMonitor import ZODB.interfaces import zope.interface import zope.component import zope.component.hooks from zope.security.interfaces import IParticipation from zope.security.management import system_user import zope.processlifetime class SystemConfigurationParticipation(object): zope.interface.implements(IParticipation) principal = system_user interaction = None _configured = False def config(file, features=(), execute=True): r"""Execute the ZCML configuration file. This procedure defines the global site setup. Optionally you can also provide a list of features that are inserted in the configuration context before the execution is started. Let's create a trivial sample ZCML file. >>> import tempfile >>> fn = tempfile.mktemp('.zcml') >>> zcml = open(fn, 'w') >>> zcml.write(''' ... ... ... ... ... ... ... ''') >>> zcml.close() We can now pass the file into the `config()` function: # End an old interaction first >>> from zope.security.management import endInteraction >>> endInteraction() >>> context = config(fn, features=('myFeature2', 'myFeature3')) >>> context.hasFeature('myFeature') True >>> context.hasFeature('myFeature2') True >>> context.hasFeature('myFeature3') True >>> context.hasFeature('myFeature4') True Further, we should have access to the configuration file name and context now: >>> getConfigSource() is fn True >>> getConfigContext() is context True Let's now clean up by removing the temporary file: >>> import os >>> os.remove(fn) """ global _configured global __config_source __config_source = file if _configured: return from zope.configuration import xmlconfig, config # Set user to system_user, so we can do anything we want from zope.security.management import newInteraction newInteraction(SystemConfigurationParticipation()) # Hook up custom component architecture calls zope.component.hooks.setHooks() # Load server-independent site config context = config.ConfigurationMachine() xmlconfig.registerCommonDirectives(context) for feature in features: context.provideFeature(feature) context = xmlconfig.file(file, context=context, execute=execute) # Reset user from zope.security.management import endInteraction endInteraction() _configured = execute global __config_context __config_context = context return context def database(db): """Load ZODB database from Python module or FileStorage file""" if type(db) is str: # Database name if db.endswith('.py'): # Python source, exec it globals = {} execfile(db, globals) if 'DB' in globals: db = globals['DB'] else: storage = globals['Storage'] from ZODB.DB import DB db = DB(storage, cache_size=4000) elif db.endswith(".fs"): from ZODB.FileStorage import FileStorage from ZODB.DB import DB storage = FileStorage(db) db = DB(storage, cache_size=4000) # The following will fail unless the application has been configured. from zope.event import notify notify(zope.processlifetime.DatabaseOpened(db)) return db def multi_database(database_factories): """Set up a multi-database from an iterable of database factories Return a sequence of databases, and a mapping of from database name to database. >>> class DB: ... def __init__(self, number): ... self.number = number ... def __repr__(self): ... return "DB(%s)" % self.number ... def getActivityMonitor(self): ... return self._activity_monitor ... def setActivityMonitor(self, am): ... self._activity_monitor = am >>> class Factory: ... def __init__(self, name, number): ... self.name = name ... self.number = number ... def open(self): ... return DB(self.number) >>> s, m = multi_database( ... [Factory(None, 3), Factory('y', 2), Factory('x', 1)]) >>> list(s) [DB(3), DB(2), DB(1)] >>> [d.database_name for d in s] ['', 'y', 'x'] >>> [d.databases is m for d in s] [True, True, True] >>> items = m.items() >>> items.sort() >>> items [('', DB(3)), ('x', DB(1)), ('y', DB(2))] Each of the databases is registered as an IDatabase utility: >>> from zope import component >>> [(component.getUtility(ZODB.interfaces.IDatabase, name) is m[name]) ... for name in m] [True, True, True] And has an activity monitor: >>> [isinstance(db.getActivityMonitor(), ... ZODB.ActivityMonitor.ActivityMonitor) ... for db in m.values()] [True, True, True] """ databases = {} result = [] for factory in database_factories: name = factory.name or '' if name in databases: raise ValueError("Duplicate database name: %r" % name) db = factory.open() db.databases = databases db.database_name = name databases[name] = db # Grrr bug in ZODB. Database doesn't declare that it implements # IDatabase. if not ZODB.interfaces.IDatabase.providedBy(db): zope.interface.directlyProvides(db, ZODB.interfaces.IDatabase) zope.component.provideUtility(db, ZODB.interfaces.IDatabase, name) db.setActivityMonitor(ZODB.ActivityMonitor.ActivityMonitor()) result.append(db) return result, databases __config_context = None def getConfigContext(): return __config_context __config_source = None def getConfigSource(): return __config_source def reset(): global _configured _configured = False global __config_source __config_source = None global __config_context __config_context = None try: import zope.testing.cleanup except ImportError: pass else: zope.testing.cleanup.addCleanUp(reset) zope.app.appsetup-3.16.0/src/zope/app/appsetup/bootstrap.py0000644000175000017500000001513111520276623023626 0ustar ctheunectheune############################################################################## # # Copyright (c) 2002, 2004 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # 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. # ############################################################################## """Bootstrap code. This module contains code to bootstrap a Zope3 instance. For example it makes sure a root folder exists and creates one if necessary. $Id: bootstrap.py 113108 2010-06-04 11:53:16Z janwijbrand $ """ __docformat__ = 'restructuredtext' import logging import transaction import warnings import zope.component.interfaces import zope.event import zope.lifecycleevent import zope.processlifetime from zope.app.publication.zopepublication import ZopePublication from zope.container.interfaces import INameChooser from zope.security.management import getSecurityPolicy from zope.security.simplepolicies import ParanoidSecurityPolicy from zope.site import site from zope.site.folder import rootFolder from zope.traversing.api import traverse _marker = object() def ensureObject(root_folder, object_name, object_type, object_factory, asObject=_marker): """Check that there's a basic object in the site manager. If not, add one. Return the name abdded, if we added an object, otherwise None. """ if asObject is not _marker: warnings.warn("asObject argument is deprecated and will be " "removed in Zope 3.6", DeprecationWarning, 2) package = getSiteManagerDefault(root_folder) valid_objects = [ name for name in package if object_type.providedBy(package[name]) ] if valid_objects: return None name = object_name obj = object_factory() package[name] = obj return obj def ensureUtility(root_folder, interface, utility_type, utility_factory, name='', asObject=_marker, **kw): """Add a utility to the top site manager Returns the name added or ``None`` if nothing was added. """ if asObject is not _marker: warnings.warn("asObject argument is deprecated and will be " "removed in Zope 3.6", DeprecationWarning, 2) sm = root_folder.getSiteManager() utils = [reg for reg in sm.registeredUtilities() if (reg.provided.isOrExtends(interface) and reg.name == name)] if len(utils) == 0: return addConfigureUtility( root_folder, interface, utility_type, utility_factory, name, asObject, **kw ) else: return None def addConfigureUtility( root_folder, interface, utility_type, utility_factory, name='', asObject=_marker, **kw): """Add and configure a utility to the root folder.""" if asObject is not _marker: warnings.warn("asObject argument is deprecated and will be " "removed in Zope 3.6", DeprecationWarning, 2) utility = addUtility(root_folder, utility_type, utility_factory, **kw) root_folder.getSiteManager().registerUtility(utility, interface, name) return utility def addUtility(root_folder, utility_type, utility_factory, asObject=_marker, **kw): """ Add a Utility to the root folder's site manager. The utility is added to the default package and activated. """ if asObject is not _marker: warnings.warn("asObject argument is deprecated and will be " "removed in Zope 3.6", DeprecationWarning, 2) package = getSiteManagerDefault(root_folder) chooser = INameChooser(package) utility = utility_factory() name = chooser.chooseName(utility_type, utility) package[name] = utility # the utility might have been location-proxied; we need the name # information (__name__) so let's get it back again from the # container utility = package[name] # Set additional attributes on the utility for k, v in kw.iteritems(): setattr(utility, k, v) return utility def getSiteManagerDefault(root_folder): package = traverse(root_folder.getSiteManager(), 'default') return package def getInformationFromEvent(event): """ Extracts information from the event Return a tuple containing - db - connection open from the db - root connection object - the root_folder object """ db = event.database connection = db.open() root = connection.root() root_folder = root.get(ZopePublication.root_name, None) return db, connection, root, root_folder ###################################################################### ###################################################################### def bootStrapSubscriber(event): """The actual subscriber to the bootstrap IDataBaseOpenedEvent Boostrap a Zope3 instance given a database object This first checks if the root folder exists and has a site manager. If it exists, nothing else is changed. If no root folder exists, one is added. """ db, connection, root, root_folder = getInformationFromEvent(event) if root_folder is None: # ugh... we depend on the root folder implementation root_folder = rootFolder() zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(root_folder)) root[ZopePublication.root_name] = root_folder if not zope.component.interfaces.ISite.providedBy(root_folder): site_manager = site.LocalSiteManager(root_folder) root_folder.setSiteManager(site_manager) transaction.commit() connection.close() zope.event.notify(zope.processlifetime.DatabaseOpenedWithRoot(db)) ######################################################################## ######################################################################## def checkSecurityPolicy(event): """Warn if the configured security policy is ParanoidSecurityPolicy Between Zope X3 3.0 and Zope 3.1, the security policy configuration was refactored and now it needs to be included from site.zcml. """ if getSecurityPolicy() is ParanoidSecurityPolicy: logging.getLogger('zope.app.appsetup').warn( 'Security policy is not configured.\n' 'Please make sure that securitypolicy.zcml is included' ' in site.zcml immediately\n' 'before principals.zcml') zope.app.appsetup-3.16.0/src/zope/app/appsetup/bootstrap.txt0000644000175000017500000000526211520276623024021 0ustar ctheunectheuneBootstrap helpers ================= The bootstrap helpers provide a number of functions that help with bootstrapping. The bootStrapSubscriber function makes sure that there is a root object. It subscribes to DatabaseOpened events: >>> from zope.app.appsetup import bootstrap >>> import zope.processlifetime >>> from ZODB.tests import util >>> db = util.DB() >>> bootstrap.bootStrapSubscriber(zope.processlifetime.DatabaseOpened(db)) The subscriber makes sure that there is a root folder: >>> from zope.app.publication.zopepublication import ZopePublication >>> conn = db.open() >>> root = conn.root()[ZopePublication.root_name] >>> sm = root.getSiteManager() >>> conn.close() A DatabaseOpenedWithRoot is generated with the database. >>> from zope.component.eventtesting import getEvents >>> [event] = getEvents(zope.processlifetime.IDatabaseOpenedWithRoot) >>> event.database is db True Generally, startup code that expects the root object and site to have been created will want to subscribe to this event, not IDataBaseOpenedEvent. The subscriber generates the event whether or not the root had to be set up: >>> bootstrap.bootStrapSubscriber(zope.processlifetime.DatabaseOpened(db)) >>> [e, event] = getEvents(zope.processlifetime.IDatabaseOpenedWithRoot) >>> event.database is db True Check the Security Policy ------------------------- When the security policy got refactored to be really pluggable, the inclusion of the security policy configuration was moved to the very top level, to site.zcml. This happened in r24770, after ZopeX3 3.0 was released, but before 3.1. Now the maintainers of existing 3.0 sites need to manually update their site.zcml to include securitypolicy.zcml while upgrading to 3.1. See also http://www.zope.org/Collectors/Zope3-dev/381 . >>> from zope.testing.loggingsupport import InstalledHandler >>> handler = InstalledHandler('zope.app.appsetup') If the security policy is unset from the default ParanoidSecurityPolicy, we get a warning: >>> from zope.app.appsetup.bootstrap import checkSecurityPolicy >>> event = object() >>> checkSecurityPolicy(event) >>> print handler zope.app.appsetup WARNING Security policy is not configured. Please make sure that securitypolicy.zcml is included in site.zcml immediately before principals.zcml However, if any non-default security policy is installed, no warning is emitted: >>> from zope.security.management import setSecurityPolicy >>> defaultPolicy = setSecurityPolicy(object()) >>> handler.clear() >>> checkSecurityPolicy(event) >>> print handler Clean up: >>> handler.uninstall() zope.app.appsetup-3.16.0/src/zope/app/appsetup/configure.zcml0000644000175000017500000000105711520276623024111 0ustar ctheunectheune zope.app.appsetup-3.16.0/src/zope/app/appsetup/controller.py0000644000175000017500000000316111520276623023774 0ustar ctheunectheune############################################################################## # # Copyright (c) 2004 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # 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. # ############################################################################## """Top-level controller for 'zopectl'. """ import os import zdaemon.zdctl INSTANCE_HOME = os.path.dirname( os.path.dirname(os.path.dirname(zdaemon.__file__))) class ZopectlCmd(zdaemon.zdctl.ZDCmd): def do_debug(self, rest): cmdline = os.path.join(INSTANCE_HOME, 'bin', 'debugzope') os.system(cmdline) def help_debug(self): print "debug -- Initialize the Zope application, providing a" print " debugger object at an interactive Python prompt." def do_run(self, arg): cmdline = "%s %s" % ( os.path.join(INSTANCE_HOME, 'bin', 'scriptzope'), arg) os.system(cmdline) def help_run(self): print "run