def __main__(): # Enable logging logging.basicConfig(level=logging.INFO) # Parse cli arguments arguments = docopt(__doc__) # Parse and evaluate configuration and plugins config = ConfigurationMachine() registerCommonDirectives(config) xmlconfig.include(config, package=collective.transmogrifier, file='meta.zcml') xmlconfig.include(config, package=collective.transmogrifier, file='configure.zcml') config.execute_actions() if arguments.get('--list'): blueprints = dict(getUtilitiesFor(ISectionBlueprint)) pipelines = map(configuration_registry.getConfiguration, configuration_registry.listConfigurationIds()) print """ Available blueprints -------------------- {0:s} Available pipelines ------------------- {1:s} """.format('\n'.join(sorted(blueprints.keys())), '\n'.join(['{0:s}\n {1:s}: {2:s}'.format( p['id'], p['title'], p['description']) for p in pipelines])) return # Load optional overrides overrides = {} overrides_path = arguments.get('--overrides') if overrides_path and not os.path.isabs(overrides_path): overrides_path = os.path.join(os.getcwd(), overrides_path) if overrides_path: parser = ConfigParser.RawConfigParser() parser.optionxform = str # case sensitive with open(overrides_path) as fp: parser.readfp(fp) overrides.update(dict(((section, dict(parser.items(section))) for section in parser.sections()))) # Initialize optional context context_path = arguments.get('--context') if context_path is None: context = dict() else: context_module_path, context_class_name = context_path.rsplit('.', 1) context_module = importlib.import_module(context_module_path) context = getattr(context_module, context_class_name)() # Transmogrify for pipeline in arguments.get('<pipeline>'): ITransmogrifier(context)(pipeline, **overrides)
def setUp(cls): # Aio HTTP app cls.aioapp = make_app(settings=TESTING_SETTINGS) # Plone App Object cls.app = getUtility(IApplication, name='root') cls.db = cls.app['plone'] include(cls.app.app.config, 'testing.zcml', sys.modules['plone.server']) cls.app.app.config.execute_actions() load_cached_schema()
def includeZCMLGroup(_context, info, filename, override=False): includable_zcml = info[filename] zcml_context = repr(_context.info) for dotted_name in includable_zcml: includable_package = resolve(dotted_name) if override: includeOverrides(_context, filename, includable_package) else: include(_context, filename, includable_package)
def zcml_configure(name, package): """ Given a ZCML filename as ``name`` and a Python package as ``package`` which the filename should be relative to, load the ZCML into the current ZCML registry. """ context = ConfigurationMachine() xmlconfig.registerCommonDirectives(context) context.package = package xmlconfig.include(context, name, package) context.execute_actions(clear=False) # the raison d'etre return context.actions
def loadProducts(_context, file=None): if file is None: # set the default file = 'configure.zcml' # now load the files if they exist for product in findProducts(): zcml = os.path.join(os.path.dirname(product.__file__), file) if os.path.isfile(zcml): try: xmlconfig.include(_context, zcml, package=product) except: # Yes, really, *any* kind of error. handleBrokenProduct(product)
def loadProducts(_context, file=None, files=None, package=None): if file is None: # set the default file = 'configure.zcml' if files is not None or package is not None: raise ValueError("Neither the files or package argument is supported.") # now load the files if they exist for product in findProducts(): zcml = os.path.join(os.path.dirname(product.__file__), file) if os.path.isfile(zcml): xmlconfig.include(_context, zcml, package=product)
def loadProducts(_context): products = findProducts() # first load meta.zcml files for product in products: zcml = os.path.join(os.path.dirname(product.__file__), "meta.zcml") if os.path.isfile(zcml): xmlconfig.include(_context, zcml, package=product) # now load their configure.zcml for product in products: zcml = os.path.join(os.path.dirname(product.__file__), "configure.zcml") if os.path.isfile(zcml): xmlconfig.include(_context, zcml, package=product)
def test_registry_actions_can_be_pickled_and_unpickled(self): import repoze.lemonade.tests.fixtureapp as package from zope.configuration import xmlconfig from zope.configuration import config context = config.ConfigurationMachine() xmlconfig.registerCommonDirectives(context) context.package = package xmlconfig.include(context, 'configure.zcml', package) context.execute_actions(clear=False) actions = context.actions import cPickle dumped = cPickle.dumps(actions, -1) new = cPickle.loads(dumped) self.assertEqual(len(actions), len(new))
def load_zcml(*args): """We rely on grok to load the configuration for our modules, but we depend on some libraries which have only zcml based configuration, thus we need to load only those we need.""" from zope.configuration.config import ConfigurationMachine from zope.configuration import xmlconfig context = ConfigurationMachine() xmlconfig.registerCommonDirectives(context) for i in args: xmlconfig.include(context, "configure.zcml", context.resolve(i)) context.execute_actions()
def includeZCMLGroup(_context, info, filename, override=False): includable_zcml = info[filename] # ^^ a key error would mean that we are trying to include a group of ZCML # with a filename that wasn't ever searched for. that *should* be an error zcml_context = repr(_context.info) for dotted_name in includable_zcml: log.debug('including file %s from package %s at %s', filename, dotted_name, zcml_context) for dotted_name in includable_zcml: includable_package = resolve(dotted_name) if override: includeOverrides(_context, filename, includable_package) else: include(_context, filename, includable_package)
def setUpZope(self, app, configurationContext): super(TestFixture, self).setUpZope(app, configurationContext) # Create some dummy site configuration to use config = getConfiguration() config.product_config = getattr(config, 'product_config', {}) config.product_config['tutorweb.quizdb'] = { 'coin-rpc-host': 'ut-rpchost', 'coin-rpc-port': '0818118181', 'coin-rpc-user': '******', 'coin-rpc-pass': '******', 'coin-rpc-walletpass': '******', } import tutorweb.quizdb xmlconfig.include(configurationContext, 'configure.zcml', tutorweb.quizdb) self.createTempDatabase(configurationContext) configurationContext.execute_actions()
def load_application(module, root, settings): app = root.app # zcml try: include(app.config, 'configure.zcml', module) except FileNotFoundError: # addons do not need to have zcml pass # includeme function if hasattr(module, 'includeme'): args = [root] if len(inspect.getargspec(module.includeme).args) == 2: args.append(settings) module.includeme(*args) # app_settings if hasattr(module, 'app_settings') and app_settings != module.app_settings: update_app_settings(module.app_settings) # services configure.load_all_configurations(app.config, module.__name__)
def load_application(module, root, settings): app = root.app # zcml try: include(app.config, 'configure.zcml', module) except (FileNotFoundError, NotADirectoryError): # addons do not need to have zcml pass # includeme function if hasattr(module, 'includeme'): args = [root] if len(inspect.getargspec(module.includeme).args) == 2: args.append(settings) module.includeme(*args) # app_settings if hasattr(module, 'app_settings') and app_settings != module.app_settings: update_app_settings(module.app_settings) # services configure.load_all_configurations(app.config, module.__name__)
def load_zcml_file(context, module_name, package=None, zcml="configure.zcml", override=False): filename = get_zcml_file(module_name, zcml) if not filename: return if package is None and context.package is not None: package = context.package if override: logger.debug( f"Loading {module_name}:{zcml} from {filename} in override mode.") # The package as third argument seems not needed because we have an absolute file name. # But it *is* needed when that file loads other relative files. includeOverrides(context, filename, package) else: logger.debug(f"Loading {module_name}:{zcml} from {filename}") include(context, filename, package)
def loadProducts(_context): products = findProducts() # first load meta.zcml files for product in products: zcml = os.path.join(os.path.dirname(product.__file__), 'meta.zcml') if os.path.isfile(zcml): try: xmlconfig.include(_context, zcml, package=product) except: # Yes, really, *any* kind of error. handleBrokenProduct(product) # now load their configure.zcml for product in products: zcml = os.path.join(os.path.dirname(product.__file__), 'configure.zcml') if os.path.isfile(zcml): try: xmlconfig.include(_context, zcml, package=product) except: # Yes, really, *any* kind of error. handleBrokenProduct(product)
def configure(arguments): # Enable venuasianconfiguration if HAS_VENUSIANCONFIGURATION: import venusianconfiguration venusianconfiguration.enable() # BBB: Support Zope's global configuration context if HAS_ZOPE: try: import Zope2.App.zcml config = Zope2.App.zcml._context or ConfigurationMachine() except (ImportError, AttributeError): config = ConfigurationMachine() else: config = ConfigurationMachine() # Parse and evaluate configuration and plugins registerCommonDirectives(config) import transmogrifier xmlconfig.include(config, package=transmogrifier, file='meta.zcml') xmlconfig.include(config, package=transmogrifier, file='configure.zcml') # Resolve includes for include in set(arguments.get('--include')): package, filename = parse_include(include) if package and filename: package = importlib.import_module(package) xmlconfig.include(config, package=package, file=filename) elif package and HAS_VENUSIANCONFIGURATION: # Support including single module in the current working directory import venusianconfiguration venusianconfiguration.venusianscan(package, config) config.execute_actions()
def load(_context, target): include = xmlconfig.include for ep in pkr.iter_entry_points('topp.zcmlloader'): if ep.name != target: continue dotted_name = ep.module_name for zcmlgroup in ('configure.zcml', 'meta.zcml'): filename = pkr.resource_filename(dotted_name, zcmlgroup) if not os.path.isfile(filename): continue dep_package = ep.load() if zcmlgroup == 'overrides.zcml': include = xcmlconfig.includeOverrides xmlconfig.include(_context, file=filename, package=dep_package) print 'Found configuration file %s: <include package="%s" file="%s" />' % (filename, dotted_name, zcmlgroup) for zcmlgroup in ('overrides.zcml',): filename = pkr.resource_filename(dotted_name, zcmlgroup) if not os.path.isfile(filename): continue dep_package = ep.load() xmlconfig.includeOverrides(_context, file=filename, package=dep_package) print 'Found configuration file %s: <includeOverrides package="%s" file="%s" />' % (filename, dotted_name, zcmlgroup)
def includeAllDependenciesDirective(_context, package, exclude=(), extras=()): dist = distributionForPackage(package) info = ZCMLInfo(['configure.zcml', 'meta.zcml', 'overrides.zcml', 'exclude.zcml']) DependencyFinder(dist).includableInfo( ['configure.zcml', 'meta.zcml', 'overrides.zcml', 'exclude.zcml'], info, None, exclude, extras) includeZCMLGroup(_context, info, 'meta.zcml') includeZCMLGroup(_context, info, 'exclude.zcml') # fix zope.app.xxx dependencies data = info['configure.zcml'] if 'zope.app.appsetup' in data: data.remove('zope.app.appsetup') data.insert(0, 'zope.app.appsetup') if 'zope.app.zcmlfiles' in data: includable_package = resolve('zope.app.zcmlfiles') include(_context, 'menus.zcml', includable_package) includeZCMLGroup(_context, info, 'configure.zcml') includeZCMLGroup(_context, info, 'overrides.zcml', True)
def setUpZope(self, app, configurationContext): import tutorweb.content import tutorweb.content.tests.mockviews import collective.alias xmlconfig.include(configurationContext, 'meta.zcml', tutorweb.content) xmlconfig.include(configurationContext, 'configure.zcml', tutorweb.content) xmlconfig.include(configurationContext, 'configure.zcml', tutorweb.content.tests.mockviews) xmlconfig.includeOverrides(configurationContext, 'overrides.zcml', tutorweb.content) xmlconfig.include(configurationContext, 'configure.zcml', collective.alias) configurationContext.execute_actions() config = getConfiguration() if not hasattr(config, 'product_config'): config.product_config = {} config.product_config['tutorweb.content'] = { 'settings-documentation': os.path.join(os.path.dirname(__file__), 'example_settings.rst'), } # https://github.com/plone/plone.app.event/issues/81#issuecomment-23930996 installProduct(app, 'Products.DateRecurringIndex')
def parseZCML(package, filename='configure.zcml'): context = xmlconfig._getContext() xmlconfig.include(context, filename, package) context.execute_actions()
def setUpZope(self, app, configurationContext): import tutorweb.content xmlconfig.include(configurationContext, 'meta.zcml', tutorweb.content) xmlconfig.include(configurationContext, 'configure.zcml', tutorweb.content) xmlconfig.includeOverrides(configurationContext, 'overrides.zcml', tutorweb.content) configurationContext.execute_actions()
def _callFUT(self, *args, **kw): from zope.configuration.xmlconfig import include return include(*args, **kw)
def load_include(_context, _include): config = _include['config'] if 'package' in config: config['package'] = resolve_or_get( resolve_module_path(config['package'])) xmlconfig.include(_context, **config)
def setUpZope(self, app, configurationContext): import collective.qna xmlconfig.include(configurationContext, 'configure.zcml', collective.qna) configurationContext.execute_actions()
def parseZCML(package, file='configure.zcml'): context = xmlconfig._getContext() xmlconfig.include(context, file, package) context.execute_actions()
def setUpZope(self, app, configurationContext): import ibme.persondirectory xmlconfig.include(configurationContext, 'configure.zcml', ibme.persondirectory) configurationContext.execute_actions()
def parseZCML(package=package): context = xmlconfig._getContext() xmlconfig.include(context, 'configure.zcml', package) context.execute_actions()