예제 #1
0
 def new_from_file(path, remote_url=False):
     if not path or not os.path.isfile(path):
         raise ManifestParserError("Manifest file does not exist %s" % path)
     for t in get_class_attributes(ManifestFileType).values():
         if path.endswith(t):
             return ManifestParserFactory.new(get_file_contents(path), t,
                                              remote_url)
     raise ManifestParserError("Unknown manifest file type %s" % path)
예제 #2
0
    def _parse_dependencies(raw):
        # compatibility with legacy dependency format
        if isinstance(raw, dict) and "name" in raw:
            raw = [raw]

        if isinstance(raw, dict):
            result = []
            for name, version in raw.items():
                if "/" in name:
                    owner, name = name.split("/", 1)
                    result.append(dict(owner=owner, name=name,
                                       version=version))
                else:
                    result.append(dict(name=name, version=version))
            return result

        if isinstance(raw, list):
            for i, dependency in enumerate(raw):
                if isinstance(dependency, dict):
                    for k, v in dependency.items():
                        if k not in ("platforms", "frameworks", "authors"):
                            continue
                        raw[i][k] = util.items_to_list(v)
                else:
                    raw[i] = {"name": dependency}
            return raw
        raise ManifestParserError(
            "Invalid dependencies format, should be list or dictionary")
예제 #3
0
    def new_from_dir(path, remote_url=None):
        assert os.path.isdir(path), "Invalid directory %s" % path

        type_from_uri = ManifestFileType.from_uri(
            remote_url) if remote_url else None
        if type_from_uri and os.path.isfile(os.path.join(path, type_from_uri)):
            return ManifestParserFactory.new(
                get_file_contents(os.path.join(path, type_from_uri)),
                type_from_uri,
                remote_url=remote_url,
                package_dir=path,
            )

        file_order = [
            ManifestFileType.PLATFORM_JSON,
            ManifestFileType.LIBRARY_JSON,
            ManifestFileType.LIBRARY_PROPERTIES,
            ManifestFileType.MODULE_JSON,
            ManifestFileType.PACKAGE_JSON,
        ]
        for t in file_order:
            if not os.path.isfile(os.path.join(path, t)):
                continue
            return ManifestParserFactory.new(
                get_file_contents(os.path.join(path, t)),
                t,
                remote_url=remote_url,
                package_dir=path,
            )
        raise ManifestParserError(
            "Unknown manifest file type in %s directory" % path)
예제 #4
0
 def new(contents, type, remote_url=None, package_dir=None):
     # pylint: disable=redefined-builtin
     clsname = ManifestParserFactory.type_to_clsname(type)
     if clsname not in globals():
         raise ManifestParserError("Unknown manifest file type %s" %
                                   clsname)
     return globals()[clsname](contents, remote_url, package_dir)
예제 #5
0
 def _parse_dependencies(raw):
     if isinstance(raw, dict):
         return [
             dict(name=name, version=version, frameworks=["mbed"])
             for name, version in raw.items()
         ]
     raise ManifestParserError(
         "Invalid dependencies format, should be a dictionary")
예제 #6
0
    def __init__(self, contents, remote_url=None, package_dir=None):
        self.remote_url = remote_url
        self.package_dir = package_dir
        try:
            self._data = self.parse(contents)
        except Exception as e:
            raise ManifestParserError("Could not parse manifest -> %s" % e)
        self._data = self.parse_examples(self._data)

        # remove None fields
        for key in list(self._data.keys()):
            if self._data[key] is None:
                del self._data[key]
예제 #7
0
    def _parse_dependencies(raw):
        # compatibility with legacy dependency format
        if isinstance(raw, dict) and "name" in raw:
            raw = [raw]

        if isinstance(raw, dict):
            return [dict(name=name, version=version) for name, version in raw.items()]
        if isinstance(raw, list):
            for i, dependency in enumerate(raw):
                assert isinstance(dependency, dict)
                for k, v in dependency.items():
                    if k not in ("platforms", "frameworks", "authors"):
                        continue
                    if "*" in v:
                        del raw[i][k]
                    raw[i][k] = util.items_to_list(v)
            return raw
        raise ManifestParserError(
            "Invalid dependencies format, should be list or dictionary"
        )
예제 #8
0
 def _parse_platforms(properties):
     result = []
     platforms_map = {
         "avr": "atmelavr",
         "sam": "atmelsam",
         "samd": "atmelsam",
         "esp8266": "espressif8266",
         "esp32": "espressif32",
         "arc32": "intel_arc32",
         "stm32": "ststm32",
     }
     for arch in properties.get("architectures", "").split(","):
         if "particle-" in arch:
             raise ManifestParserError("Particle is not supported yet")
         arch = arch.strip()
         if not arch:
             continue
         if arch == "*":
             return ["*"]
         if arch in platforms_map:
             result.append(platforms_map[arch])
     return result