def __call__(self, context): terms = [] for conf_id in configuration_registry.listConfigurationIds(): conf = configuration_registry.getConfiguration(conf_id) terms.append( SimpleVocabulary.createTerm(conf_id, conf_id, conf['title'])) return SimpleVocabulary(terms)
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 pipelines_list(context): items = [] pids = configuration_registry.listConfigurationIds() for pid in pids: pipeline = configuration_registry.getConfiguration(pid) items.append((pipeline['title'], pipeline['id'])) return SimpleVocabulary.fromItems(items)
def __call__(self, context): terms = [] for conf_id in configuration_registry.listConfigurationIds(): conf = configuration_registry.getConfiguration(conf_id) terms.append(SimpleVocabulary.createTerm( conf_id, conf_id, conf['title']) ) return SimpleVocabulary(terms)
def __call__(self): pipeline_id = 'import-chm-terms' pipelines = configuration_registry.listConfigurationIds() if pipeline_id is not None and pipeline_id in pipelines: transmogrifier = Transmogrifier(self.context) transmogrifier(pipeline_id) pipeline = configuration_registry.getConfiguration(pipeline_id) return 'done' return 'invalid pipeline'
def __call__(self): alsoProvides(self.request, IDisableCSRFProtection) pipeline_id = 'importp4content' pipelines = configuration_registry.listConfigurationIds() if pipeline_id is not None and pipeline_id in pipelines: transmogrifier = Transmogrifier(self.context) transmogrifier(pipeline_id) return 'done' return 'invalid pipeline'
def __call__(self, context): terms = [] for conf_id in configuration_registry.listConfigurationIds(): conf_file = _load_config(conf_id) for section_id in conf_file.keys(): section = conf_file[section_id] if section.get("blueprint", "") in SOURCE_SECTIONS: conf = configuration_registry.getConfiguration(conf_id) terms.append(SimpleVocabulary.createTerm(conf_id, conf_id, conf["title"])) break return SimpleVocabulary(terms)
def __call__(self, context): terms = [] for conf_id in configuration_registry.listConfigurationIds(): conf_file = _load_config(conf_id) for section_id in conf_file.keys(): section = conf_file[section_id] if section.get('blueprint', '') in SOURCE_SECTIONS: conf = configuration_registry.getConfiguration(conf_id) terms.append(SimpleVocabulary.createTerm( conf_id, conf_id, conf['title'])) break return SimpleVocabulary(terms)
def __call__(self, context): terms = [] for conf_id in configuration_registry.listConfigurationIds(): print conf_id conf_file = _load_config(conf_id) for section_id in conf_file.keys(): section = conf_file[section_id] if section.get('blueprint', '') == 'plone.app.transmogrifier.atschemaupdater': conf = configuration_registry.getConfiguration(conf_id) terms.append(SimpleVocabulary.createTerm( conf_id, conf_id, conf['title'])) break return SimpleVocabulary(terms)
def handleRunAndNext(self, action): data, errors = self.extractData() if errors: return False self._run(data) configs = configuration_registry.listConfigurationIds() current_config = data.get('config') if configs.index(current_config) + 2 > len(configs): # This was the last config self._redirect('@@jsonmigrator', current_config) else: next_config = configs[configs.index(current_config) + 1] self._redirect('@@jsonmigrator-run', next_config)
def testConfigZCMLDefaults(self): xmlconfig.string('''\ <configure xmlns:transmogrifier="http://namespaces.plone.org/transmogrifier" i18n_domain="collective.transmogrifier"> <transmogrifier:registerConfig name="collective.transmogrifier.tests.configname" configuration="filename.cfg" /> </configure>''', context=self.context) self.context.execute_actions() self.assertEqual(configuration_registry.listConfigurationIds(), (u'collective.transmogrifier.tests.configname',)) self.assertEqual( configuration_registry.getConfiguration( u'collective.transmogrifier.tests.configname'), dict(id=u'collective.transmogrifier.tests.configname', title=u'Pipeline configuration ' u"'collective.transmogrifier.tests.configname'", description=u'', configuration=os.path.join(os.getcwd(), 'filename.cfg')))
def handle_action(self, action): """ Processes the form and runs the selected pipeline. """ data, errors = self.extractData() if errors: self.status = self.formErorrsMessage return pipeline_id = data.get('pipeline', None) pipelines = configuration_registry.listConfigurationIds() if pipeline_id is not None and pipeline_id in pipelines: transmogrifier = Transmogrifier(self.context) transmogrifier(pipeline_id) pipeline = configuration_registry.getConfiguration(pipeline_id) IStatusMessage(self.request).addStatusMessage('{0} {1}' .format(pipeline['title'], _('successfully executed.')), 'info') self.request.response.redirect(self.context.absolute_url()) else: raise ActionExecutionError(Invalid('{0}: {1}' .format(_(u'Invalid pipeline'), pipeline_id)))
def testConfigZCMLDefaults(self): zcml.load_string('''\ <configure xmlns:transmogrifier="http://namespaces.plone.org/transmogrifier" i18n_domain="collective.transmogrifier"> <transmogrifier:registerConfig name="collective.transmogrifier.tests.configname" configuration="filename.cfg" /> </configure>''') self.assertEqual(configuration_registry.listConfigurationIds(), (u'collective.transmogrifier.tests.configname', )) path = os.path.split(collective.transmogrifier.__file__)[0] self.assertEqual( configuration_registry.getConfiguration( u'collective.transmogrifier.tests.configname'), dict(id=u'collective.transmogrifier.tests.configname', title=u'Pipeline configuration ' u"'collective.transmogrifier.tests.configname'", description=u'', configuration=os.path.join(path, 'filename.cfg')))
def testConfigZCMLDefaults(self): zcml.load_string('''\ <configure xmlns:transmogrifier="http://namespaces.plone.org/transmogrifier" i18n_domain="collective.transmogrifier"> <transmogrifier:registerConfig name="collective.transmogrifier.tests.configname" configuration="filename.cfg" /> </configure>''') self.assertEqual(configuration_registry.listConfigurationIds(), (u'collective.transmogrifier.tests.configname',)) path = os.path.split(collective.transmogrifier.__file__)[0] self.assertEqual( configuration_registry.getConfiguration( u'collective.transmogrifier.tests.configname'), dict(id=u'collective.transmogrifier.tests.configname', title=u'Pipeline configuration ' u"'collective.transmogrifier.tests.configname'", description=u'', configuration=os.path.join(path, 'filename.cfg')))
def run_migration(self, *args): call = args[0] if len(call) > 2: pipeline_id = call[2] for plonesite in self.objectValues("Plone Site"): setSite(plonesite) plonesite = spoofRequest(plonesite) if pipeline_id in configuration_registry.listConfigurationIds(): transmogrifier = Transmogrifier(plonesite) overrides = {} if len(call) >= 4: json_path = call[3] overrides["jsonsource"] = {"path": json_path} transmogrifier(pipeline_id, **overrides) transaction.commit() print("All set!") else: print("This migration id is invalid.") else: print("You need to tell me the migration id to run")
def handle_action(self, action): """ Processes the form and runs the selected pipeline. """ data, errors = self.extractData() if errors: self.status = self.formErorrsMessage return pipeline_id = data.get('pipeline', None) pipelines = configuration_registry.listConfigurationIds() if pipeline_id is not None and pipeline_id in pipelines: transmogrifier = Transmogrifier(self.context) transmogrifier(pipeline_id) pipeline = configuration_registry.getConfiguration(pipeline_id) IStatusMessage(self.request).addStatusMessage( '{0} {1}'.format(pipeline['title'], _('successfully executed.')), 'info') self.request.response.redirect(self.context.absolute_url()) else: raise ActionExecutionError( Invalid('{0}: {1}'.format(_(u'Invalid pipeline'), pipeline_id)))
def testEmptyZCML(self): zcml.load_string('''\ <configure xmlns:transmogrifier="http://namespaces.plone.org/transmogrifier"> </configure>''') self.assertEqual(configuration_registry.listConfigurationIds(), ())
def testEmptyZCML(self): xmlconfig.string('''\ <configure xmlns:transmogrifier="http://namespaces.plone.org/transmogrifier"> </configure>''', context=self.context) self.context.execute_actions() self.assertEqual(configuration_registry.listConfigurationIds(), ())