Exemplo n.º 1
0
    def _load_manifest(self, manifest_filename):
        implicit_exts = ['', '.yaml', '.yml']
        log.debug("Loading project manifest from {} {}".format(manifest_filename, implicit_exts))
        resolved_manifest_filename = self.loader.find_file(manifest_filename, implicit_ext=implicit_exts)
        if resolved_manifest_filename is None:
            raise Error('Cannot find manifest file {}'.format(manifest_filename))
        with open(resolved_manifest_filename, 'r') as f:
            mapping = marked_load(f)

        return mapping
Exemplo n.º 2
0
    def __init__(self,
                 mapping=None,
                 file_name=None,
                 loader=None,
                 concept_path=[]):
        assert loader is not None
        self.loader = loader

        self.concept_path = concept_path
        if mapping:
            self.file_name = file_name
            self.mapping = mapping
        else:
            assert isinstance(file_name, string_types)

            extensions = ['', '.yml', '.yaml']
            fn = self.loader.find_file(file_name, self.concept_path,
                                       extensions)

            if not fn:
                raise IOError(
                    'Cannot find concept file {} in concept path {} (local path:{})'
                    .format("{}[{}]".format(file_name, '|'.join(extensions)),
                            self.concept_path,
                            self.loader.mixed_to_local_path(
                                self.concept_path)))

            with open(fn, 'r') as f:
                mapping = marked_load(f)
                nodetype_name = os.path.basename(fn)
                nodetype_name = nodetype_name.split('.')[0]
                if 'name' in mapping:
                    if mapping['name'] != nodetype_name:
                        raise NodeTypeSyntaxError(
                            "Name attribute does not match file name: {} != {}"
                            .format(mapping['name'], nodetype_name),
                            filename=fn)
                else:
                    mapping['name'] = nodetype_name

            self.file_name = fn
            self.mapping = mapping

        # sanity/syntax check
        if 'name' not in self.mapping:
            raise NodeTypeSyntaxError("Missing 'name' field",
                                      filename=self.mapping['file_name'])

        if 'properties' not in self.mapping:
            raise NodeTypeSyntaxError("Missing 'properties' field",
                                      filename=self.mapping['file_name'])
Exemplo n.º 3
0
    def __init__(self, mapping=None, file_name=None, loader=None, concept_path=[]):
        assert loader is not None
        self.loader = loader

        self.concept_path = concept_path
        if mapping:
            self.file_name = file_name
            self.mapping = mapping
        else:
            assert isinstance(file_name, string_types)

            extensions = ['', '.yml', '.yaml']
            fn = self.loader.find_file(file_name, self.concept_path, extensions)

            if not fn:
                raise IOError('Cannot find concept file {} in concept path {} (local path:{})'.format("{}[{}]".format(file_name, '|'.join(extensions)), self.concept_path, self.loader.mixed_to_local_path(self.concept_path)))

            with open(fn, 'r') as f:
                mapping = marked_load(f)
                nodetype_name = os.path.basename(fn)
                nodetype_name = nodetype_name.split('.')[0]
                if 'name' in mapping:
                    if mapping['name'] != nodetype_name:
                        raise NodeTypeSyntaxError("Name attribute does not match file name: {} != {}".format(mapping['name'], nodetype_name), filename=fn)
                else:
                    mapping['name'] = nodetype_name

            self.file_name = fn
            self.mapping = mapping

        # sanity/syntax check
        if 'name' not in self.mapping:
            raise NodeTypeSyntaxError("Missing 'name' field", filename=self.mapping['file_name'])

        if 'properties' not in self.mapping:
            raise NodeTypeSyntaxError("Missing 'properties' field", filename=self.mapping['file_name'])