Example #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
Example #2
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))
Example #3
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
Example #4
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()
Example #5
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())
Example #6
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()
Example #7
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()