Handle libraries without manifests

This commit is contained in:
Ivan Kravets
2017-01-28 17:06:20 +02:00
parent a4d8749e44
commit 8a7d255361
4 changed files with 62 additions and 35 deletions

View File

@ -125,7 +125,8 @@ def print_lib_item(item):
click.echo("=" * len(item['name']))
if "id" in item:
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()
for key in ("version", "homepage", "license", "keywords"):
@ -223,8 +224,8 @@ def lib_search(query, json_output, page, noninteractive, **filters):
break
result = get_api_result(
"/v2/lib/search",
dict(
query=" ".join(query), page=int(result['page']) + 1),
{"query": " ".join(query),
"page": int(result['page']) + 1},
cache_valid="3d")
@ -256,7 +257,11 @@ def get_builtin_libs(storage_names=None):
if storage_names and storage['name'] not in storage_names:
continue
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

View File

@ -17,8 +17,9 @@
import json
import os
import re
from glob import glob
from hashlib import md5
from os.path import join
from os.path import isdir, join
import arrow
import click
@ -42,30 +43,23 @@ class LibraryManager(BasePkgManager):
"module.json"
]
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
def get_manifest_path(self, pkg_dir):
path = BasePkgManager.get_manifest_path(self, pkg_dir)
if path:
return path
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
# if library without manifest, returns first source file
src_dir = join(util.glob_escape(pkg_dir))
if isdir(join(pkg_dir, "src")):
src_dir = join(src_dir, "src")
chs_files = glob(join(src_dir, "*.[chS]"))
if chs_files:
return chs_files[0]
cpp_files = glob(join(src_dir, "*.cpp"))
if cpp_files:
return cpp_files[0]
with open(join(pkg_dir, self.manifest_names[0]), "w") as fp:
json.dump(manifest, fp)
return pkg_dir
return None
def load_manifest(self, path):
manifest = BasePkgManager.load_manifest(self, path)
@ -75,15 +69,13 @@ class LibraryManager(BasePkgManager):
# if Arudino library.properties
if "sentence" in manifest:
manifest['frameworks'] = ["arduino"]
manifest['description'] = manifest['sentence']
del manifest['sentence']
if "author" in manifest:
manifest['authors'] = [{"name": manifest['author']}]
del manifest['author']
if "sentence" in manifest:
manifest['description'] = manifest['sentence']
del manifest['sentence']
if "keywords" not in manifest:
keywords = []
for keyword in re.split(r"[\s/]+",
@ -131,6 +123,31 @@ class LibraryManager(BasePkgManager):
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
def normalize_dependencies(dependencies):
if not dependencies:

View File

@ -155,18 +155,23 @@ class PkgInstallerMixin(object):
if isfile(path) and path.endswith(self.VCS_MANIFEST_NAME):
pkg_dir = dirname(dirname(path))
manifest = {}
if path.endswith(".json"):
manifest = util.load_json(path)
else:
manifest = {}
elif path.endswith(".properties"):
with codecs.open(path, encoding="utf-8") as fp:
for line in fp.readlines():
if "=" not in line:
continue
key, value = line.split("=", 1)
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
def check_pkg_structure(self, pkg_dir):

View File

@ -560,7 +560,7 @@ class PlatformBase(PlatformPackagesMixin, PlatformRunMixin):
if not isdir(libcore_dir):
continue
storages.append({
"name": "%s-%s" % (opts['package'], item),
"name": "%s-core-%s" % (opts['package'], item),
"path": libcore_dir
})