Get all tests for make_repo.py passing
This commit is contained in:
37
make_repo.py
37
make_repo.py
@@ -18,15 +18,14 @@ class BadAddon(Exception):
|
||||
|
||||
def iter_addons(path: Path) -> (Path, dict):
|
||||
"""
|
||||
Generator, yields (path, bl_info) of blender addons in `path` (non recursive).
|
||||
Generator, yields (path, bl_info) of blender addons in `path`.
|
||||
"""
|
||||
pass
|
||||
# for item in addons_dir.iterdir():
|
||||
# base = item.name
|
||||
#
|
||||
# yield (base, fname, '.zip')
|
||||
# else:
|
||||
# yield (base, item.path, '.py')
|
||||
for item in path.iterdir():
|
||||
try:
|
||||
yield(item, extract_blinfo(item))
|
||||
except BadAddon as err:
|
||||
log.debug("Skipping '{}': {}".format(item.name, err))
|
||||
|
||||
def parse_blinfo(source: str) -> dict:
|
||||
"""Parse a python file and return its bl_info dict, if there is one (else return None)"""
|
||||
@@ -80,16 +79,19 @@ def extract_blinfo(item: Path) -> dict:
|
||||
for fname in z.namelist():
|
||||
# TODO: zips with multiple bl_infos might be a problem,
|
||||
# not sure how such cases should be handled (if at all)
|
||||
# for now we just break after the first one
|
||||
if fname.endswith('__init__.py'):
|
||||
try:
|
||||
blinfo = parse_blinfo(z.read(fname))
|
||||
break
|
||||
except BadAddon:
|
||||
continue
|
||||
raise BadAddon("Zipfile '%s' doesn't contain any readable bl_info dict" % item)
|
||||
if blinfo is None:
|
||||
raise BadAddon("Zipfile '%s' doesn't contain a readable bl_info dict" % item)
|
||||
|
||||
except zipfile.BadZipFile:
|
||||
# Assume file is
|
||||
# If it's not a valid zip, assume file is just a normal file
|
||||
# TODO: this probably blows up inelegantly on corrupted zips
|
||||
with item.open() as f:
|
||||
blinfo = parse_blinfo(f.read())
|
||||
|
||||
@@ -101,24 +103,17 @@ def extract_blinfo(item: Path) -> dict:
|
||||
|
||||
|
||||
|
||||
def make_repo(repopath: Path):
|
||||
"""Make repo.json for files in directory 'repopath'"""
|
||||
def make_repo(path: Path):
|
||||
"""Make repo.json for files in directory 'path'"""
|
||||
|
||||
repo_data = {}
|
||||
package_data = []
|
||||
|
||||
if not repopath.is_dir():
|
||||
raise FileNotFoundError(repopath)
|
||||
if not path.is_dir():
|
||||
raise FileNotFoundError(path)
|
||||
|
||||
for addon_path in repopath.iterdir():
|
||||
for addon, bl_info in iter_addons(path):
|
||||
package_datum = {}
|
||||
addon = addon_path.name
|
||||
|
||||
try:
|
||||
bl_info = extract_blinfo(addon_path)
|
||||
except BadAddon as err:
|
||||
log.warning('Could not extract bl_info from {}: {}'.format(addon_path, err))
|
||||
continue
|
||||
|
||||
if not REQUIRED_KEYS.issubset(set(bl_info)):
|
||||
log.warning(
|
||||
|
Reference in New Issue
Block a user