def parse_mains_conf(text, line_number):
    mains = []

    def path_line_parser(line):
        mains.append(EntryPointConfiguration.parse(line))

    parse(text, path_line_parser, line_number)
    return mains
def parse_deps_conf(text, line_number):
    dependencies = []

    def parse_dependencies(line):
        dep = DependentConfiguration.parse(line)
        dependencies.append(dep)

    parse(text,  parse_dependencies, line_number)
    return dependencies
示例#3
0
def parse_deps_conf(text, line_number):
    dependencies = []

    def parse_dependencies(line):
        dep = DependentConfiguration.parse(line)
        dependencies.append(dep)

    parse(text, parse_dependencies, line_number)
    return dependencies
示例#4
0
    def _parse(self):
        sections = self._find_sections()

        parent = sections.get('parent')
        if parent:
            self.parent = parent_loads(parent.content, parent.line)
        self._old_parent = self.parent

        reqs = sections.get('requirements')
        if reqs:
            self.requirements = BlockVersionTable.loads(
                reqs.content, reqs.line)
        self._old_requirements = self.requirements.copy()

        # self.include_mapping = IncludesMapping.loads(includes)
        deps = sections.get('dependencies')
        if deps:
            self.dependencies = parse_deps_conf(deps.content, deps.line)

        hooks = sections.get('hooks')
        if hooks:
            hooks_deps = parse_deps_conf(hooks.content, hooks.line)
            self.dependencies.extend(hooks_deps)

        mains = sections.get('mains')
        if mains:
            self.mains = parse_mains_conf(mains.content, mains.line)

        tests = sections.get('tests')
        if tests:

            def test_line_parser(line):
                self.tests.append(line)

            parse(tests.content, test_line_parser, tests.line)

        paths = sections.get('paths')
        if paths:

            def path_line_parser(line):
                self.paths.append(line)

            parse(paths.content, path_line_parser, paths.line)

        data = sections.get('data')
        if data:
            self.data = parse_deps_conf(data.content, data.line)

        includes = sections.get('includes')
        if includes:
            self.includes = IncludesMapping.loads(includes.content,
                                                  includes.line)
示例#5
0
    def loads(cls, text, line):
        result = cls()

        def path_line_parser(line):
            try:
                pattern, path = line.split(":")
                pattern = pattern.strip()
                path = path.strip().rstrip("/")
                result.append(IncludeMap(pattern, path))
            except:
                raise BiiException("Incorrect include map: %s" % line)

        parse(text, path_line_parser, line)
        return result
示例#6
0
    def loads(cls, text, line):
        result = cls()

        def path_line_parser(line):
            try:
                pattern, path = line.split(":")
                pattern = pattern.strip()
                path = path.strip().rstrip("/")
                result.append(IncludeMap(pattern, path))
            except:
                raise BiiException("Incorrect include map: %s" % line)

        parse(text, path_line_parser, line)
        return result
示例#7
0
    def _parse(self):
        sections = self._find_sections()

        parent = sections.get('parent')
        if parent:
            self.parent = parent_loads(parent.content, parent.line)
        self._old_parent = self.parent

        reqs = sections.get('requirements')
        if reqs:
            self.requirements = BlockVersionTable.loads(reqs.content, reqs.line)
        self._old_requirements = self.requirements.copy()

        # self.include_mapping = IncludesMapping.loads(includes)
        deps = sections.get('dependencies')
        if deps:
            self.dependencies = parse_deps_conf(deps.content, deps.line)

        hooks = sections.get('hooks')
        if hooks:
            hooks_deps = parse_deps_conf(hooks.content, hooks.line)
            self.dependencies.extend(hooks_deps)

        mains = sections.get('mains')
        if mains:
            self.mains = parse_mains_conf(mains.content, mains.line)

        tests = sections.get('tests')
        if tests:
            def test_line_parser(line):
                self.tests.append(line)
            parse(tests.content, test_line_parser, tests.line)

        paths = sections.get('paths')
        if paths:
            def path_line_parser(line):
                self.paths.append(line)
            parse(paths.content, path_line_parser, paths.line)

        data = sections.get('data')
        if data:
            self.data = parse_deps_conf(data.content, data.line)

        includes = sections.get('includes')
        if includes:
            self.includes = IncludesMapping.loads(includes.content, includes.line)
示例#8
0
    def loads(cls, text):
        """ gets a Policy from a text string
        """
        result = cls()

        def policies_line_parser(line):
            try:
                pattern, path = line.split(":")
                pattern = pattern.strip()
                tag = VersionTag.loads(path.strip())
                result.append(Rule(pattern, tag))
            except:
                raise BiiException("Incorrect rule in policies.bii: %s" % line)

        parse(text, policies_line_parser, 0)
        if not result:
            raise BiiException("Empty policies.bii, cannot find")
        return result
示例#9
0
    def loads(cls, text):
        """ gets a Policy from a text string
        """
        result = cls()

        def policies_line_parser(line):
            try:
                pattern, path = line.split(":")
                pattern = pattern.strip()
                tag = VersionTag.loads(path.strip())
                result.append(Rule(pattern, tag))
            except:
                raise BiiException("Incorrect rule in policies.bii: %s" % line)

        parse(text, policies_line_parser, 0)
        if not result:
            raise BiiException("Empty policies.bii, cannot find")
        return result
示例#10
0
    def loads(cls, text, line_number=0):
        """ loads from text a table, the text might have comments with #
        raises BiiException in case of file error, conflicts or duplicated dependencies
        return: BlockVersionTable
        """
        result = cls()
        if not text:
            return result

        def table_line_parser(line):
            version = BlockVersion.loads(line)
            if version.block_name in result:
                raise BiiException('Duplicate dependency "%s"' %
                                   version.to_pretty())
            result.add_version(version)

        parse(text, table_line_parser, line_number)
        return result
示例#11
0
def parse_layout_conf(text, project_root):
    """ parses a layout.bii file, with the format:
    lib: mylib
    deps: dependencies
    ...
    """
    current_layout = default_layout.copy()

    def parse_dependencies(line):
        tokens = line.strip().split(':', 1)
        if len(tokens) != 2:
            raise ConfigurationFileError(
                'Every entry in layout should be NAME: RELATIVE PATH')
        name, value = tokens
        if name not in default_layout:
            raise ConfigurationFileError('Unknown layout entry %s' % name)
        # relative path between tmp and project with the project name as dest folder
        if "$TMP" in value:
            try:
                tmp_rel_folder = os.path.join(
                    os.path.relpath(tempfile.gettempdir(), project_root),
                    os.path.basename(project_root)).replace('\\', '/')
            except Exception:
                raise ConfigurationFileError(
                    "Unable to compute relative path to $TMP folder "
                    "in layout.bii\nYou are probably in another drive "
                    "to your tmp folder")
            value = value.replace("$TMP", tmp_rel_folder)
        value = value.strip()
        if value == "/" or value.lower() == "false":
            value = ""
        if name == ROOT_BLOCK:
            value = BlockName(value)
        current_layout[name] = value

    parse(text, parse_dependencies)
    # Lets make sure nothing else is inside the edited blocks folder
    src_dir = current_layout[SRC_DIR]
    for name, path in current_layout.iteritems():
        if name not in [SRC_DIR, AUTO_ROOT_BLOCK, ROOT_BLOCK
                        ] and path.startswith(src_dir):
            raise ConfigurationFileError(
                'Layout: Please do not locate %s inside blocks' % name)
    return current_layout
示例#12
0
def parent_loads(text, line_number):
    """ return a BlockVersion if found, or None. If no time is present, return -1 as timestep
    raise BiiException on parse errors
    """
    result = []

    def parents_line_parser(line):
        if line.startswith('*'):
            line = line[1:]

        version = BlockVersion.loads(line)
        if result:
            raise BiiException('Impossible to have two main parents')

        result.append(version)
    parse(text, parents_line_parser, line_number)
    if result and result[0].time is None:
        return BlockVersion(result[0].block, -1)
    return result[0] if result else None
示例#13
0
def parse_layout_conf(text, project_root):
    """ parses a layout.bii file, with the format:
    lib: mylib
    deps: dependencies
    ...
    """
    current_layout = default_layout.copy()

    def parse_dependencies(line):
        tokens = line.strip().split(':', 1)
        if len(tokens) != 2:
            raise ConfigurationFileError('Every entry in layout should be NAME: RELATIVE PATH')
        name, value = tokens
        if name not in default_layout:
            raise ConfigurationFileError('Unknown layout entry %s' % name)
        # relative path between tmp and project with the project name as dest folder
        if "$TMP" in value:
            try:
                tmp_rel_folder = os.path.join(os.path.relpath(tempfile.gettempdir(), project_root),
                                              os.path.basename(project_root)).replace('\\', '/')
            except Exception:
                raise ConfigurationFileError("Unable to compute relative path to $TMP folder "
                                             "in layout.bii\nYou are probably in another drive "
                                             "to your tmp folder")
            value = value.replace("$TMP", tmp_rel_folder)
        value = value.strip()
        if value == "/" or value.lower() == "false":
            value = ""
        if name == ROOT_BLOCK:
            value = BlockName(value)
        current_layout[name] = value

    parse(text,  parse_dependencies)
    # Lets make sure nothing else is inside the edited blocks folder
    src_dir = current_layout[SRC_DIR]
    for name, path in current_layout.iteritems():
        if name not in [SRC_DIR, AUTO_ROOT_BLOCK, ROOT_BLOCK] and path.startswith(src_dir):
            raise ConfigurationFileError('Layout: Please do not locate %s inside blocks' % name)
    return current_layout