예제 #1
0
    def find_source_root(self, src):
        if self.manifest_uri:
            mp = (ManifestParserFactory.new_from_file(self.manifest_uri[5:])
                  if self.manifest_uri.startswith("file:") else
                  ManifestParserFactory.new_from_url(self.manifest_uri))
            manifest = ManifestSchema().load_manifest(mp.as_dict())
            include = manifest.get("export", {}).get("include", [])
            if len(include) == 1:
                if not os.path.isdir(os.path.join(src, include[0])):
                    raise PackageException(
                        "Non existing `include` directory `%s` in a package" %
                        include[0])
                return os.path.join(src, include[0])

        for root, _, __ in os.walk(src):
            if ManifestFileType.from_dir(root):
                return root

        return src
예제 #2
0
def lib_register(config_url):
    if not config_url.startswith("http://") and not config_url.startswith("https://"):
        raise exception.InvalidLibConfURL(config_url)

    # Validate manifest
    ManifestSchema().load_manifest(
        ManifestParserFactory.new_from_url(config_url).as_dict()
    )

    result = util.get_api_result("/lib/register", data=dict(config_url=config_url))
    if "message" in result and result["message"]:
        click.secho(
            result["message"],
            fg="green" if "successed" in result and result["successed"] else "red",
        )
예제 #3
0
 def load_manifest(self, src):
     path = src.path if isinstance(src, PackageItem) else src
     cache_key = "load_manifest-%s" % path
     result = self.memcache_get(cache_key)
     if result:
         return result
     candidates = ([
         os.path.join(path, name) for name in self.manifest_names
     ] if os.path.isdir(path) else [path])
     for item in candidates:
         if not os.path.isfile(item):
             continue
         try:
             result = ManifestParserFactory.new_from_file(item).as_dict()
             self.memcache_set(cache_key, result)
             return result
         except ManifestException as e:
             if not PlatformioCLI.in_silence():
                 self.print_message(str(e), fg="yellow")
     raise MissingPackageManifestError(", ".join(self.manifest_names))
예제 #4
0
    def load_manifest(self, pkg_dir):  # pylint: disable=too-many-branches
        cache_key = "load_manifest-%s" % pkg_dir
        result = self.cache_get(cache_key)
        if result:
            return result

        manifest = {}
        src_manifest = None
        manifest_path = self.get_manifest_path(pkg_dir)
        src_manifest_path = self.get_src_manifest_path(pkg_dir)
        if src_manifest_path:
            src_manifest = fs.load_json(src_manifest_path)

        if not manifest_path and not src_manifest_path:
            return None

        try:
            manifest = ManifestParserFactory.new_from_file(
                manifest_path).as_dict()
        except ManifestException:
            pass

        if src_manifest:
            if "version" in src_manifest:
                manifest["version"] = src_manifest["version"]
            manifest["__src_url"] = src_manifest["url"]
            # handle a custom package name
            autogen_name = self.parse_pkg_uri(manifest["__src_url"])[0]
            if "name" not in manifest or autogen_name != src_manifest["name"]:
                manifest["name"] = src_manifest["name"]

        if "name" not in manifest:
            manifest["name"] = basename(pkg_dir)
        if "version" not in manifest:
            manifest["version"] = "0.0.0"

        manifest["__pkg_dir"] = realpath(pkg_dir)
        self.cache_set(cache_key, manifest)
        return manifest
예제 #5
0
    def install(  # pylint: disable=arguments-differ
        self,
        name,
        requirements=None,
        silent=False,
        after_update=False,
        interactive=False,
        force=False,
    ):
        _name, _requirements, _url = self.parse_pkg_uri(name, requirements)
        if not _url:
            name = "id=%d" % self.search_lib_id(
                {
                    "name": _name,
                    "requirements": _requirements
                },
                silent=silent,
                interactive=interactive,
            )
            requirements = _requirements
        pkg_dir = BasePkgManager.install(
            self,
            name,
            requirements,
            silent=silent,
            after_update=after_update,
            force=force,
        )

        if not pkg_dir:
            return None

        manifest = None
        try:
            manifest = ManifestParserFactory.new_from_dir(pkg_dir).as_dict()
        except ManifestException:
            pass
        if not manifest or not manifest.get("dependencies"):
            return pkg_dir

        if not silent:
            click.secho("Installing dependencies", fg="yellow")

        builtin_lib_storages = None
        for filters in manifest["dependencies"]:
            assert "name" in filters

            # avoid circle dependencies
            if not self.INSTALL_HISTORY:
                self.INSTALL_HISTORY = []
            history_key = str(filters)
            if history_key in self.INSTALL_HISTORY:
                continue
            self.INSTALL_HISTORY.append(history_key)

            if any(s in filters.get("version", "") for s in ("\\", "/")):
                self.install(
                    "{name}={version}".format(**filters),
                    silent=silent,
                    after_update=after_update,
                    interactive=interactive,
                    force=force,
                )
            else:
                try:
                    lib_id = self.search_lib_id(filters, silent, interactive)
                except exception.LibNotFound as e:
                    if builtin_lib_storages is None:
                        builtin_lib_storages = get_builtin_libs()
                    if not silent or is_builtin_lib(builtin_lib_storages,
                                                    filters["name"]):
                        click.secho("Warning! %s" % e, fg="yellow")
                    continue

                if filters.get("version"):
                    self.install(
                        lib_id,
                        filters.get("version"),
                        silent=silent,
                        after_update=after_update,
                        interactive=interactive,
                        force=force,
                    )
                else:
                    self.install(
                        lib_id,
                        silent=silent,
                        after_update=after_update,
                        interactive=interactive,
                        force=force,
                    )
        return pkg_dir
예제 #6
0
 def load_manifest(src):
     mp = ManifestParserFactory.new_from_dir(src)
     return ManifestSchema().load_manifest(mp.as_dict())
예제 #7
0
 def load_manifest(self):
     manifest_path = join(self.path, "library.json")
     if not isfile(manifest_path):
         return {}
     return ManifestParserFactory.new_from_file(manifest_path).as_dict()
예제 #8
0
# Copyright (c) 2014-present PlatformIO <*****@*****.**>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from platformio.package.manifest.parser import ManifestParserFactory
from platformio.package.manifest.schema import ManifestSchema

mp = ManifestParserFactory.new_from_file('library.json')
parsed = ManifestSchema().load_manifest(mp.as_dict())
예제 #9
0
 def load_manifest(self):
     manifest_path = os.path.join(self.path, "module.json")
     if not os.path.isfile(manifest_path):
         return {}
     return ManifestParserFactory.new_from_file(manifest_path).as_dict()
예제 #10
0
 def load_manifest(self):
     manifest_path = os.path.join(self.path, "library.properties")
     if not os.path.isfile(manifest_path):
         return {}
     return ManifestParserFactory.new_from_file(manifest_path).as_dict()