forked from platformio/platformio-core
Handle libraries without manifests
This commit is contained in:
@ -125,7 +125,8 @@ def print_lib_item(item):
|
|||||||
click.echo("=" * len(item['name']))
|
click.echo("=" * len(item['name']))
|
||||||
if "id" in item:
|
if "id" in item:
|
||||||
click.secho("#ID: %d" % item['id'], bold=True)
|
click.secho("#ID: %d" % item['id'], bold=True)
|
||||||
click.echo(item.get("description", item.get("url", "")))
|
if "description" in item or "url" in item:
|
||||||
|
click.echo(item.get("description", item.get("url", "")))
|
||||||
click.echo()
|
click.echo()
|
||||||
|
|
||||||
for key in ("version", "homepage", "license", "keywords"):
|
for key in ("version", "homepage", "license", "keywords"):
|
||||||
@ -223,8 +224,8 @@ def lib_search(query, json_output, page, noninteractive, **filters):
|
|||||||
break
|
break
|
||||||
result = get_api_result(
|
result = get_api_result(
|
||||||
"/v2/lib/search",
|
"/v2/lib/search",
|
||||||
dict(
|
{"query": " ".join(query),
|
||||||
query=" ".join(query), page=int(result['page']) + 1),
|
"page": int(result['page']) + 1},
|
||||||
cache_valid="3d")
|
cache_valid="3d")
|
||||||
|
|
||||||
|
|
||||||
@ -256,7 +257,11 @@ def get_builtin_libs(storage_names=None):
|
|||||||
if storage_names and storage['name'] not in storage_names:
|
if storage_names and storage['name'] not in storage_names:
|
||||||
continue
|
continue
|
||||||
lm = LibraryManager(storage['path'])
|
lm = LibraryManager(storage['path'])
|
||||||
items.append(dict(name=storage['name'], items=lm.get_installed()))
|
items.append({
|
||||||
|
"name": storage['name'],
|
||||||
|
"path": storage['path'],
|
||||||
|
"items": lm.get_installed()
|
||||||
|
})
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,8 +17,9 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from glob import glob
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from os.path import join
|
from os.path import isdir, join
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
import click
|
import click
|
||||||
@ -42,30 +43,23 @@ class LibraryManager(BasePkgManager):
|
|||||||
"module.json"
|
"module.json"
|
||||||
]
|
]
|
||||||
|
|
||||||
def check_pkg_structure(self, pkg_dir):
|
def get_manifest_path(self, pkg_dir):
|
||||||
try:
|
path = BasePkgManager.get_manifest_path(self, pkg_dir)
|
||||||
return BasePkgManager.check_pkg_structure(self, pkg_dir)
|
if path:
|
||||||
except exception.MissingPackageManifest:
|
return path
|
||||||
# we will generate manifest automatically
|
|
||||||
# if library doesn't contain any
|
|
||||||
pass
|
|
||||||
|
|
||||||
manifest = {
|
# if library without manifest, returns first source file
|
||||||
"name": "Library_" + md5(pkg_dir).hexdigest()[:5],
|
src_dir = join(util.glob_escape(pkg_dir))
|
||||||
"version": "0.0.0"
|
if isdir(join(pkg_dir, "src")):
|
||||||
}
|
src_dir = join(src_dir, "src")
|
||||||
for root, dirs, files in os.walk(pkg_dir):
|
chs_files = glob(join(src_dir, "*.[chS]"))
|
||||||
if len(dirs) == 1 and not files:
|
if chs_files:
|
||||||
manifest['name'] = dirs[0]
|
return chs_files[0]
|
||||||
continue
|
cpp_files = glob(join(src_dir, "*.cpp"))
|
||||||
if dirs or files:
|
if cpp_files:
|
||||||
pkg_dir = root
|
return cpp_files[0]
|
||||||
break
|
|
||||||
|
|
||||||
with open(join(pkg_dir, self.manifest_names[0]), "w") as fp:
|
return None
|
||||||
json.dump(manifest, fp)
|
|
||||||
|
|
||||||
return pkg_dir
|
|
||||||
|
|
||||||
def load_manifest(self, path):
|
def load_manifest(self, path):
|
||||||
manifest = BasePkgManager.load_manifest(self, path)
|
manifest = BasePkgManager.load_manifest(self, path)
|
||||||
@ -75,15 +69,13 @@ class LibraryManager(BasePkgManager):
|
|||||||
# if Arudino library.properties
|
# if Arudino library.properties
|
||||||
if "sentence" in manifest:
|
if "sentence" in manifest:
|
||||||
manifest['frameworks'] = ["arduino"]
|
manifest['frameworks'] = ["arduino"]
|
||||||
|
manifest['description'] = manifest['sentence']
|
||||||
|
del manifest['sentence']
|
||||||
|
|
||||||
if "author" in manifest:
|
if "author" in manifest:
|
||||||
manifest['authors'] = [{"name": manifest['author']}]
|
manifest['authors'] = [{"name": manifest['author']}]
|
||||||
del manifest['author']
|
del manifest['author']
|
||||||
|
|
||||||
if "sentence" in manifest:
|
|
||||||
manifest['description'] = manifest['sentence']
|
|
||||||
del manifest['sentence']
|
|
||||||
|
|
||||||
if "keywords" not in manifest:
|
if "keywords" not in manifest:
|
||||||
keywords = []
|
keywords = []
|
||||||
for keyword in re.split(r"[\s/]+",
|
for keyword in re.split(r"[\s/]+",
|
||||||
@ -131,6 +123,31 @@ class LibraryManager(BasePkgManager):
|
|||||||
|
|
||||||
return manifest
|
return manifest
|
||||||
|
|
||||||
|
def check_pkg_structure(self, pkg_dir):
|
||||||
|
try:
|
||||||
|
return BasePkgManager.check_pkg_structure(self, pkg_dir)
|
||||||
|
except exception.MissingPackageManifest:
|
||||||
|
# we will generate manifest automatically
|
||||||
|
# if library doesn't contain any
|
||||||
|
pass
|
||||||
|
|
||||||
|
manifest = {
|
||||||
|
"name": "Library_" + md5(pkg_dir).hexdigest()[:5],
|
||||||
|
"version": "0.0.0"
|
||||||
|
}
|
||||||
|
for root, dirs, files in os.walk(pkg_dir):
|
||||||
|
if len(dirs) == 1 and not files:
|
||||||
|
manifest['name'] = dirs[0]
|
||||||
|
continue
|
||||||
|
if dirs or files:
|
||||||
|
pkg_dir = root
|
||||||
|
break
|
||||||
|
|
||||||
|
with open(join(pkg_dir, self.manifest_names[0]), "w") as fp:
|
||||||
|
json.dump(manifest, fp)
|
||||||
|
|
||||||
|
return pkg_dir
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def normalize_dependencies(dependencies):
|
def normalize_dependencies(dependencies):
|
||||||
if not dependencies:
|
if not dependencies:
|
||||||
|
@ -155,18 +155,23 @@ class PkgInstallerMixin(object):
|
|||||||
if isfile(path) and path.endswith(self.VCS_MANIFEST_NAME):
|
if isfile(path) and path.endswith(self.VCS_MANIFEST_NAME):
|
||||||
pkg_dir = dirname(dirname(path))
|
pkg_dir = dirname(dirname(path))
|
||||||
|
|
||||||
|
manifest = {}
|
||||||
if path.endswith(".json"):
|
if path.endswith(".json"):
|
||||||
manifest = util.load_json(path)
|
manifest = util.load_json(path)
|
||||||
else:
|
elif path.endswith(".properties"):
|
||||||
manifest = {}
|
|
||||||
with codecs.open(path, encoding="utf-8") as fp:
|
with codecs.open(path, encoding="utf-8") as fp:
|
||||||
for line in fp.readlines():
|
for line in fp.readlines():
|
||||||
if "=" not in line:
|
if "=" not in line:
|
||||||
continue
|
continue
|
||||||
key, value = line.split("=", 1)
|
key, value = line.split("=", 1)
|
||||||
manifest[key.strip()] = value.strip()
|
manifest[key.strip()] = value.strip()
|
||||||
manifest['__pkg_dir'] = pkg_dir
|
else:
|
||||||
|
if "name" not in manifest:
|
||||||
|
manifest['name'] = basename(pkg_dir)
|
||||||
|
if "version" not in manifest:
|
||||||
|
manifest['version'] = "0.0.0"
|
||||||
|
|
||||||
|
manifest['__pkg_dir'] = pkg_dir
|
||||||
return manifest
|
return manifest
|
||||||
|
|
||||||
def check_pkg_structure(self, pkg_dir):
|
def check_pkg_structure(self, pkg_dir):
|
||||||
|
@ -560,7 +560,7 @@ class PlatformBase(PlatformPackagesMixin, PlatformRunMixin):
|
|||||||
if not isdir(libcore_dir):
|
if not isdir(libcore_dir):
|
||||||
continue
|
continue
|
||||||
storages.append({
|
storages.append({
|
||||||
"name": "%s-%s" % (opts['package'], item),
|
"name": "%s-core-%s" % (opts['package'], item),
|
||||||
"path": libcore_dir
|
"path": libcore_dir
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user