コード例 #1
0
ファイル: bii_config.py プロジェクト: luckcc/bii-common
    def _find_sections(self):
        pattern = re.compile("^\[([a-z]{2,50})\]")
        current_lines = []
        sections = {}
        Section = namedtuple("Section", "line content headline")
        parsed_sections = set()
        for i, line in enumerate(self._text.splitlines()):
            m = pattern.match(line)
            if m:
                group = m.group(1)
                if group not in BiiConfig.sections:
                    raise ConfigurationFileError(
                        "%d: Unrecognized section '%s'" % (i + 1, group))
                if group in parsed_sections:
                    raise ConfigurationFileError(
                        "%d: Duplicated section '%s'" % (i + 1, group))
                parsed_sections.add(group)
                current_lines = []
                sections[group] = Section(i + 1, current_lines, line)
            else:
                current_lines.append(line)

        return {
            name: Section(line, '\n'.join(lines), headline)
            for name, (line, lines, headline) in sections.iteritems()
        }
コード例 #2
0
 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
コード例 #3
0
ファイル: arduinosettings.py プロジェクト: luckcc/bii-common
 def deserialize(cls, data):
     try:
         d = smart_deserialize(cls, data)
     except ValueError as error:
         raise ConfigurationFileError("Error parsing settings.bii %s %s" %
                                      (os.linesep, error))
     return d
コード例 #4
0
 def evaluate(self, settings):
     aux = {}
     exec self.code in aux
     f = aux['virtual']
     tokens = self.name.rsplit('/', 1)
     try:
         evaluated = f(settings)
         return BlockCellName('%s/%s/%s' % (tokens[0], evaluated, tokens[1]))
     except Exception as e:
         raise ConfigurationFileError("Error evaluating virtual resource %s, %s. "
                                      "Check virtual.bii and try again" % (self.ID, e))
コード例 #5
0
ファイル: closure.py プロジェクト: luckcc/bii-common
 def bii_config(self):
     bii_configs = {}
     for block_cell_name, (resource, _) in self.iteritems():
         if block_cell_name.cell_name == 'biicode.conf':
             try:
                 content_ = resource.content.load.text
                 bii_config = BiiConfig(content_)
             except ConfigurationFileError as e:
                 raise ConfigurationFileError('%s: Line %s'
                                              % (block_cell_name, str(e)))
             bii_configs[block_cell_name.block_name] = bii_config
     return bii_configs
コード例 #6
0
ファイル: conf_file_parser.py プロジェクト: luckcc/bii-common
def parse(text, line_parser, base_line_number=0):
    """Parse configuration file. parse_tokens method should be written on to provide behavior
    depending on each case.
    Comments with # and blank lines are skipped
    Params:
        text: string to be parsed on a per line basis
    """
    for i, line in enumerate(text.splitlines()):
        line = line.strip()
        if not line or line.startswith('#'):  # Blank and comment lines
            continue
        tokens = line.split('#', 1)
        line = tokens[0]
        if '<<<' in line or '===' in line or '>>>' in line:
            raise ConfigurationFileError('%d: merge conflict' %
                                         (i + 1 + base_line_number))

        try:
            line_parser(line)
        except Exception as e:
            raise ConfigurationFileError('%d: Parse error: \n\t%s' %
                                         (i + 1 + base_line_number, str(e)))
コード例 #7
0
 def config(self):
     if self._config is None:
         try:
             res = self._resources[BIICODE_FILE]
             content = res.content.load.bytes
         except KeyError:
             content = None
         try:
             self._config = BiiConfig(content)
         except ConfigurationFileError as e:
             raise ConfigurationFileError('%s/biicode.conf: Line %s' %
                                          (self.block_name, str(e)))
     return self._config
コード例 #8
0
 def loads(cls, data):
     """Load Settings from a yaml file."""
     try:
         settings = yaml_loads(cls, data) or cls()
     except ScannerError as e:
         raise ConfigurationFileError(str(e))
     # Migration to 2.3 new toolchain settings. Remove July 2015
     if settings.cpp.generator:
         settings.cmake.generator = settings.cpp.generator
         settings.cpp = CPPSettings()
     if settings.arduino.generator:
         settings.cmake.generator = settings.arduino.generator
         settings.arduino.generator = None
     return settings
コード例 #9
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
コード例 #10
0
    def parse(cls, line):
        tokens = line.strip().split()
        if len(tokens) < 2:
            raise ConfigurationFileError('line is missing elements')
        pattern = tokens[0]
        action = tokens[1]
        if action not in ('+-='):
            action = pattern[0]
            if action not in ('+-='):
                action = '+'
            else:
                pattern = pattern[1:]
            deps = tokens[1:]
        else:
            deps = tokens[2:]

        dependencies = set()
        for token in deps:
            if token == 'NULL':
                break
            dependencies.add(DependencyConfiguration.parse(token))
        obj = cls(pattern, action, dependencies)
        return obj