Exemple #1
0
    def __init__(self, config, do_load):
        self._log = logging.getLogger('crosspm')
        self._config = config  # type: Config
        self.cache = config.cache
        self.solid = config.solid
        self.common_parser = Parser('common', {}, config)
        self._root_package = Package('<root>', 0,
                                     {self._config.name_column: '<root>'},
                                     self, None, self.common_parser)

        if not config.deps_path:
            config.deps_path = \
                config.deps_file_name if config.deps_file_name else CROSSPM_DEPENDENCY_FILENAME
        deps_path = config.deps_path
        if deps_path.__class__ is DependenciesContent:
            # HACK
            pass
            self._deps_path = deps_path
        else:
            deps_path = config.deps_path.strip().strip('"').strip("'")
            self._deps_path = os.path.realpath(os.path.expanduser(deps_path))

        if not config.depslock_path:
            config.depslock_path = \
                config.deps_lock_file_name if config.deps_lock_file_name else CROSSPM_DEPENDENCY_LOCK_FILENAME
        depslock_path = config.depslock_path
        if depslock_path.__class__ is DependenciesContent:
            # HACK
            self._depslock_path = depslock_path
        else:
            depslock_path = depslock_path.strip().strip('"').strip("'")
            self._depslock_path = os.path.realpath(
                os.path.expanduser(depslock_path))

        self.do_load = do_load
Exemple #2
0
    def init_config(self):
        root = self._output_config.get('root', '')
        if isinstance(root, str):
            self._output_config['type'] = PLAIN
        elif isinstance(root, (dict, set)):
            self._output_config['type'] = DICT
            root = [x for x in root]
            self._output_config['root'] = root[0] if len(root) > 0 else ''
        elif isinstance(root, (list, tuple)):
            self._output_config['type'] = LIST
            self._output_config['root'] = root[0] if len(root) > 0 else ''

        key = self._output_config.get('key', '')
        key0 = None

        if 'columns' in self._output_config:
            self._columns = []
            for item in self._output_config['columns']:
                if not item.get('value', ''):
                    item['value'] = '{}'
                if not item.get('name', ''):
                    item['name'] = '{}'
                if not item.get('column', ''):
                    item['column'] = ''
                    for cl in [
                            y for y in [
                                x[0] for x in Parser.split_with_regexp(
                                    '{.*?}', item['name']) if x[1]
                            ] if y
                    ]:
                        col = cl.split(':')[0]
                        if col:
                            item['column'] = col
                            break
                if item['column']:
                    self._columns.append(item['column'])
                    if key == item['column']:
                        key0 = ''
                    elif key0 is None:
                        key0 = item['column']

        if key0:
            key = key0
        self._output_config['key'] = key

        if self._columns:
            if self._name_column and self._name_column not in self._columns:
                self._columns.append(self._name_column)
        else:
            if not self._name_column:
                self._name_column = 'package'
        if 'value' not in self._output_config:
            self._output_config['value'] = ''
Exemple #3
0
 def init_parsers(self, parsers):
     if 'common' not in parsers:
         parsers['common'] = {}
     for k, v in parsers.items():
         if k not in self._parsers:
             v.update({_k: _v for _k, _v in parsers['common'].items() if _k not in v})
             self._parsers[k] = Parser(k, v, self)
         else:
             code = CROSSPM_ERRORCODE_CONFIG_FORMAT_ERROR
             msg = 'Config file contains multiple definitions of the same parser: [{}]'.format(k)
             self._log.exception(msg)
             raise CrosspmException(code, msg)
     if len(self._parsers) == 0:
         code = CROSSPM_ERRORCODE_CONFIG_FORMAT_ERROR
         msg = 'Config file does not contain parsers! Unable to process any further.'
         self._log.exception(msg)
         raise CrosspmException(code, msg)