Пример #1
0
    def main(cls, argv=None, package_file=None):
        parser = cls.create_option_parser()

        cls.add_main_options(parser)

        cls.add_additional_options(parser)

        (options, args) = parser.parse_args(args=argv)

        config = configparser.SafeConfigParser()
        if options.config_file:
            config.read(options.config_file)
        if not config.has_section(CONFIG_SECTION_NAME):
            config.add_section(CONFIG_SECTION_NAME)

        cls.merge_options_and_config(config, options, args)
        if options.init_config_file:
            if not options.config_file:
                parser.error("no config file specified - cannot initialise config file")
            f = open(options.config_file, "w")
            with f:
                config.write(f)
                return

        cls.check_args(config, options, args, parser, package_file)

        meta_data = cls.create_meta_data(options, args, parser)

        packager = cls(package_file=package_file or options.package_file,
                       entry_point_process=options.entry_point_process, meta_data=meta_data, editor=options.editor)
        for a in args:
            packager.add_bpmn_files_by_glob(a)
        packager.create_package()

        return packager
Пример #2
0
    def deserialize_workflow_spec(self, s_state, filename=None):
        """
        :param s_state: a byte-string with the contents of the packaged workflow archive, or a file-like object.
        :param filename: the name of the package file.
        """
        if isinstance(s_state, (str, bytes)):
            s_state = BytesIO(s_state)

        package_zip = zipfile.ZipFile(s_state,
                                      "r",
                                      compression=zipfile.ZIP_DEFLATED)
        config = configparser.SafeConfigParser()
        ini_fp = TextIOWrapper(package_zip.open(Packager.METADATA_FILE),
                               encoding="UTF-8")
        try:
            config.readfp(ini_fp)
        finally:
            ini_fp.close()

        parser_class = BpmnParser

        try:
            parser_class_module = config.get('MetaData',
                                             'parser_class_module',
                                             fallback=None)
        except TypeError:
            # unfortunately the fallback= does not exist on python 2
            parser_class_module = config.get('MetaData', 'parser_class_module',
                                             None)

        if parser_class_module:
            mod = __import__(parser_class_module,
                             fromlist=[config.get('MetaData', 'parser_class')])
            parser_class = getattr(mod, config.get('MetaData', 'parser_class'))

        parser = parser_class()

        for info in package_zip.infolist():
            parts = os.path.split(info.filename)
            if len(parts) == 2 and not parts[0] and parts[1].lower().endswith(
                    '.bpmn'):
                #It is in the root of the ZIP and is a BPMN file
                try:
                    svg = package_zip.read(info.filename[:-5] + '.svg')
                except KeyError as e:
                    svg = None

                bpmn_fp = package_zip.open(info)
                try:
                    bpmn = ET.parse(bpmn_fp)
                finally:
                    bpmn_fp.close()

                parser.add_bpmn_xml(bpmn,
                                    svg=svg,
                                    filename='%s:%s' %
                                    (filename, info.filename))

        return parser.get_spec(config.get('MetaData', 'entry_point_process'))
Пример #3
0
    def write_manifest(self):
        """
        Write the manifest content to the zip file. It must be a predictable order.
        """
        config = configparser.SafeConfigParser()

        config.add_section('Manifest')

        for f in sorted(self.manifest.keys()):
            config.set('Manifest', f.replace('\\', '/').lower(), self.manifest[f])

        ini = StringIO()
        config.write(ini)
        self.manifest_data = ini.getvalue()
        self.package_zip.writestr(self.MANIFEST_FILE, self.manifest_data)
Пример #4
0
    def write_meta_data(self):
        """
        Writes the metadata.ini file to the archive.
        """
        config = configparser.SafeConfigParser()

        config.add_section('MetaData')
        config.set('MetaData', 'entry_point_process', self.wf_spec.name)
        if self.editor:
            config.set('MetaData', 'editor', self.editor)

        for k, v in self.meta_data:
            config.set('MetaData', k, v)

        if not self.PARSER_CLASS == BpmnParser:
            config.set('MetaData', 'parser_class_module', inspect.getmodule(self.PARSER_CLASS).__name__)
            config.set('MetaData', 'parser_class', self.PARSER_CLASS.__name__)

        ini = StringIO()
        config.write(ini)
        self.write_to_package_zip(self.METADATA_FILE, ini.getvalue())