def write_workflow(self, specification_path, output_formatter=None): specification = self._get_specification( specification_path, output_formatter=output_formatter) if not specification: return False generator = getUtility(IWorkflowGenerator) try: generator(self._workflow_id(specification_path), specification) except ConflictError: raise except Exception, exc: if not output_formatter: raise getSite().error_log.raising(sys.exc_info()) output_formatter( 'error', _(u'error_while_generating_workflow', default=u'${id}: Error while generating' u' the workflow: ${msg}', mapping={ 'msg': str(exc).decode('utf-8'), 'id': self._workflow_id(specification_path) })) return False
def write_workflow(self, specification_path, output_formatter=None): specification = self._get_specification( specification_path, output_formatter=output_formatter) if not specification: return False generator = getUtility(IWorkflowGenerator) try: generator(self._workflow_id(specification_path), specification) except ConflictError: raise except Exception, exc: if not output_formatter: raise getSite().error_log.raising(sys.exc_info()) output_formatter( 'error', _(u'error_while_generating_workflow', default=u'${id}: Error while generating' u' the workflow: ${msg}', mapping={'msg': str(exc).decode('utf-8'), 'id': self._workflow_id(specification_path)})) return False
def update_security(self): wftool = getToolByName(self.context, 'portal_workflow') updated_objects = wftool.updateRoleMappings() IStatusMessage(self.request).add( _(u'info_security_updated', default=u'Security update: ${amount} objects updated.', mapping={'amount': updated_objects}))
def _generate_table_headers(self, spec, workflow): """Generates and returns the table headers as list of cell values (string). """ headers = [_(u'sharing_description_action', u'Action')] generator = getUtility(IWorkflowGenerator) generator.workflow_id = workflow.id for status in spec.states.values(): headers.append(self._translate(generator._status_id(status), default=status.title)) return headers
def _generate_table_headers(self, spec, workflow): """Generates and returns the table headers as list of cell values (string). """ headers = [_(u'sharing_description_action', u'Action')] generator = getUtility(IWorkflowGenerator) generator.workflow_id = workflow.id for status in spec.states.values(): # ftw.lawgiver<1.6.1 used to translate the review state ID. # For backwards compatibility use that as fallback. old_translation = self._translate(generator._status_id(status), default=status.title) # Plone translates the review state title. correct_translation = self._translate(status.title, default=old_translation) headers.append(correct_translation) return headers
def _load_specification(self): parser = getUtility(IWorkflowSpecificationParser) path = self.get_spec_path() with open(path) as specfile: try: return parser(specfile, path=path) except Exception, exc: getSite().error_log.raising(sys.exc_info()) IStatusMessage(self.request).add(_( u'error_parsing_error', default=u'The specification file could not be' u' parsed: ${error}', mapping={'error': str(exc).decode('utf-8')}), type='error') return None
def _load_specification(self): parser = getUtility(IWorkflowSpecificationParser) path = self.get_spec_path() with open(path) as specfile: try: return parser(specfile, path=path) except Exception, exc: getSite().error_log.raising(sys.exc_info()) IStatusMessage(self.request).add( _(u'error_parsing_error', default=u'The specification file could not be' u' parsed: ${error}', mapping={'error': str(exc).decode('utf-8')}), type='error') return None
def write_workflow(self): generator = getUtility(IWorkflowGenerator) try: generator(self.workflow_name(), self.specification) except ConflictError: raise except Exception, exc: getSite().error_log.raising(sys.exc_info()) IStatusMessage(self.request).add( _(u'error_while_generating_workflow', default=u'Error while generating the workflow: ${msg}', mapping={'msg': str(exc)}), type='error') return False
def update_translations(self, specification_path, output_formatter=None): specification = self._get_specification( specification_path, output_formatter=output_formatter) if not specification: return False builder = I18nBuilder(specification_path) builder.generate(specification.language.code) if output_formatter: output_formatter( 'info', _(u'info_locales_updated', default=u'${id}: The translations were updated in your' u' locales directory. You should now run bin/i18n-build', mapping={'id': self._workflow_id(specification_path)})) return True
def write_workflow(self): generator = getUtility(IWorkflowGenerator) try: generator(self.workflow_name(), self.specification) except ConflictError: raise except Exception, exc: getSite().error_log.raising(sys.exc_info()) IStatusMessage(self.request).add(_( u'error_while_generating_workflow', default=u'Error while generating the workflow: ${msg}', mapping={'msg': str(exc)}), type='error') return False
def _get_specification(self, specification_path, output_formatter=None): parser = getUtility(IWorkflowSpecificationParser) try: with open(specification_path) as specfile: return parser(specfile, path=specification_path) except ConflictError: raise except Exception, exc: if not output_formatter: raise getSite().error_log.raising(sys.exc_info()) output_formatter( 'error', _(u'error_parsing_error', default=u'${id}: The specification file could not be' u' parsed: ${error}', mapping={'error': str(exc).decode('utf-8'), 'id': self._workflow_id(specification_path)})) return None
def write_and_import_workflow(self): if self.is_destructive() and not self.is_confirmed(): return self.render_confirmation() if not self.write_workflow(): return self.reload() setup_tool = getToolByName(self.context, 'portal_setup') profile_id = self._find_profile_name_for_workflow() import_context = setup_tool._getImportContext(profile_id, None, None) workflow = self._get_or_create_workflow_obj() parent_path = 'workflows/' importObjects(workflow, parent_path, import_context) IStatusMessage(self.request).add( _(u'info_workflow_imported', default=u'Workflow ${wfname} successfully imported.', mapping={'wfname': self.workflow_name()})) return self.reload()
def write_and_import_workflow(self): if self.is_destructive() and not self.is_confirmed(): return self.render_confirmation() if not self.write_workflow(): return self.reload() setup_tool = getToolByName(self.context, 'portal_setup') profile_id = self._find_profile_name_for_workflow() import_context = setup_tool._getImportContext( profile_id, None, None) workflow = self._get_or_create_workflow_obj() parent_path = 'workflows/' importObjects(workflow, parent_path, import_context) IStatusMessage(self.request).add( _(u'info_workflow_imported', default=u'Workflow ${wfname} successfully imported.', mapping={'wfname': self.workflow_name()})) return self.reload()
def _get_specification(self, specification_path, output_formatter=None): parser = getUtility(IWorkflowSpecificationParser) try: with open(specification_path) as specfile: return parser(specfile, path=specification_path) except ConflictError: raise except Exception, exc: if not output_formatter: raise getSite().error_log.raising(sys.exc_info()) output_formatter( 'error', _(u'error_parsing_error', default=u'${id}: The specification file could not be' u' parsed: ${error}', mapping={ 'error': str(exc).decode('utf-8'), 'id': self._workflow_id(specification_path) })) return None
def update_all_specifications(self, output_formatter=None): discovery = getMultiAdapter((getSite(), getSite().REQUEST), IWorkflowSpecificationDiscovery) result = [] for specification_path in discovery.discover(): if not in_development(specification_path): if output_formatter: output_formatter( 'warning', _(u'warning_skipped_released_spec', default=u'${id}: Skipping released specification.', mapping={ 'id': self._workflow_id(specification_path)})) continue self.write_workflow(specification_path, output_formatter=output_formatter) self.update_translations(specification_path, output_formatter=output_formatter) result.append(specification_path) return result
def update_all_specifications(self, output_formatter=None): discovery = getMultiAdapter((getSite(), getSite().REQUEST), IWorkflowSpecificationDiscovery) result = [] for specification_path in discovery.discover(): if not in_development(specification_path): if output_formatter: output_formatter( 'warning', _(u'warning_skipped_released_spec', default=u'${id}: Skipping released specification.', mapping={ 'id': self._workflow_id(specification_path) })) continue self.write_workflow(specification_path, output_formatter=output_formatter) self.update_translations(specification_path, output_formatter=output_formatter) result.append(specification_path) return result
IStatusMessage(self.request).add( _(u'error_while_generating_workflow', default=u'Error while generating the workflow: ${msg}', mapping={'msg': str(exc)}), type='error') return False else: with open(self.get_definition_path(), 'w+') as result_file: generator.write(result_file) IStatusMessage(self.request).add( _(u'info_workflow_generated', default=u'The workflow was generated to ${path}.', mapping={'path': self.get_definition_path()})) return True def write_and_import_workflow(self): if self.is_destructive() and not self.is_confirmed(): return self.render_confirmation() if not self.write_workflow(): return self.reload() setup_tool = getToolByName(self.context, 'portal_setup') profile_id = self._find_profile_name_for_workflow() import_context = setup_tool._getImportContext( profile_id, None, None)
IStatusMessage(self.request).add(_( u'error_while_generating_workflow', default=u'Error while generating the workflow: ${msg}', mapping={'msg': str(exc)}), type='error') return False else: with open(self.get_definition_path(), 'w+') as result_file: generator.write(result_file) IStatusMessage(self.request).add( _(u'info_workflow_generated', default=u'The workflow was generated to ${path}.', mapping={'path': self.get_definition_path()})) return True def write_and_import_workflow(self): if self.is_destructive() and not self.is_confirmed(): return self.render_confirmation() if not self.write_workflow(): return self.reload() setup_tool = getToolByName(self.context, 'portal_setup') profile_id = self._find_profile_name_for_workflow() import_context = setup_tool._getImportContext(profile_id, None, None)
class Updater(object): implements(IUpdater) def update_all_specifications(self, output_formatter=None): discovery = getMultiAdapter((getSite(), getSite().REQUEST), IWorkflowSpecificationDiscovery) result = [] for specification_path in discovery.discover(): if not in_development(specification_path): if output_formatter: output_formatter( 'warning', _(u'warning_skipped_released_spec', default=u'${id}: Skipping released specification.', mapping={ 'id': self._workflow_id(specification_path) })) continue self.write_workflow(specification_path, output_formatter=output_formatter) self.update_translations(specification_path, output_formatter=output_formatter) result.append(specification_path) return result def update_all_specifications_with_upgrade_step(self, output_formatter=None): if not FTW_UPGRADE_INSTALLED: raise UpgradeStepCreationError('ftw.upgrade is not installed.') by_packages = defaultdict(list) for specification_path in self.update_all_specifications( output_formatter=output_formatter): pkg_path = (Path(specification_path).joinpath( '..', '..', '..', '..', '..').abspath()) by_packages[pkg_path].append(Path(specification_path)) for pkg_path, spec_paths in by_packages.items(): upgrades_path = pkg_path.joinpath('upgrades') if not upgrades_path.isdir(): raise UpgradeStepCreationError( 'Missing folder at {!r}'.format(upgrades_path)) wf_names_by_reindex_flag = {False: [], True: []} upgrade_dir = ( UpgradeStepCreator(upgrades_path).create('Update workflows.')) for spec_path in spec_paths: def_path = spec_path.joinpath('..', 'definition.xml').abspath() wf_name = spec_path.parent.name target_dir = upgrade_dir.joinpath('workflows', wf_name) target_dir.makedirs() def_path.copy(target_dir.joinpath('definition.xml')) wf_names_by_reindex_flag[self._has_view_permission_changed( def_path)].append(str(wf_name)) upgrade_module = upgrade_dir.joinpath('upgrade.py') for flag, wf_names in wf_names_by_reindex_flag.items(): if not wf_names: continue upgrade_module.write_bytes( upgrade_module.bytes() + ' self.update_workflow_security(\n' ' [\'{}\'],\n' ' reindex_security={!r})\n'.format( ('\',\n \'').join(wf_names), flag)) def write_workflow(self, specification_path, output_formatter=None): specification = self._get_specification( specification_path, output_formatter=output_formatter) if not specification: return False generator = getUtility(IWorkflowGenerator) try: generator(self._workflow_id(specification_path), specification) except ConflictError: raise except Exception, exc: if not output_formatter: raise getSite().error_log.raising(sys.exc_info()) output_formatter( 'error', _(u'error_while_generating_workflow', default=u'${id}: Error while generating' u' the workflow: ${msg}', mapping={ 'msg': str(exc).decode('utf-8'), 'id': self._workflow_id(specification_path) })) return False with open(self._definition_path(specification_path), 'w+') as wf_file: generator.write(wf_file) if output_formatter: output_formatter( 'info', _(u'info_workflow_generated', default=u'${id}: The workflow was generated to ${path}.', mapping={ 'path': self._definition_path(specification_path), 'id': self._workflow_id(specification_path) })) return True