Initial implementation of repo generation tool
This commit is contained in:
@@ -14,13 +14,22 @@ import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def report(msg):
|
||||
# if __name__ == '__main__':
|
||||
print("blenderpack:", msg)
|
||||
REQUIRED_KEYS = set(['name', 'blender'])
|
||||
SCHEMA_VERSION = 1
|
||||
|
||||
def report(msg):
|
||||
print("blenderpack:", msg, file=sys.stderr)
|
||||
|
||||
def fatal_report(msg, code=1, ex=None):
|
||||
if __name__ == '__main__':
|
||||
# report("fatal: %s" % msg)
|
||||
log.fatal(msg)
|
||||
exit(code)
|
||||
elif ex is not None:
|
||||
raise Exception(msg) from ex
|
||||
else:
|
||||
raise RuntimeError("blenderpack: Unhandled fatal exception: %s" % msg)
|
||||
|
||||
def fatal_report(msg, code=1):
|
||||
report(msg)
|
||||
exit(code)
|
||||
|
||||
def fetch(url):
|
||||
# TODO: do conditional request
|
||||
@@ -81,13 +90,42 @@ def extract_blinfo(path):
|
||||
|
||||
|
||||
|
||||
def make_repo(path):
|
||||
"""Make repo.json for files in directory 'path'"""
|
||||
# try:
|
||||
for addon in os.listdir(path):
|
||||
extract_blinfo(os.path.join(path, addon))
|
||||
# except FileNotFoundError:
|
||||
# fatal_report("No such file or directory: '%s'" % path)
|
||||
def make_repo(outpath):
|
||||
"""Make repo.json for files in directory 'outpath'"""
|
||||
|
||||
repo_data = {}
|
||||
package_data = []
|
||||
|
||||
try:
|
||||
for addon in os.listdir(outpath):
|
||||
package_datum = {}
|
||||
addon_path = os.path.join(outpath, addon)
|
||||
|
||||
try:
|
||||
bl_info = extract_blinfo(addon_path)
|
||||
if not bl_info:
|
||||
raise Exception("No bl_info found in %s" % addon)
|
||||
except Exception as err:
|
||||
fatal_report('Could not extract bl_info from {}: {}'.format(addon_path, err))
|
||||
|
||||
if not REQUIRED_KEYS.issubset(set(bl_info)):
|
||||
fatal_report(
|
||||
"Required key(s) '{}' not found in bl_info of '{}'".format(
|
||||
"', '".join(REQUIRED_KEYS.difference(set(bl_info))), addon),
|
||||
ex=Exception()
|
||||
)
|
||||
|
||||
package_datum['bl_info'] = bl_info
|
||||
package_datum['type'] = 'addon'
|
||||
package_data.append(package_datum)
|
||||
|
||||
repo_data['packages'] = package_data
|
||||
with open(os.path.join(outpath, "repo.json"), 'w', encoding='utf-8') as repo_file:
|
||||
json.dump(repo_data, repo_file, indent=4, sort_keys=True)
|
||||
|
||||
|
||||
except FileNotFoundError:
|
||||
fatal_report("No such file or directory: '%s'" % outpath)
|
||||
|
||||
|
||||
|
||||
|
@@ -36,7 +36,9 @@ class test_blenderpack_make_repo(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
# def test_validpath(self):
|
||||
# blenderpack.make_repo(os.path.join('test_helpers', 'addons'))
|
||||
def test_make_repo_valid(self):
|
||||
blenderpack.make_repo(os.path.join(self.helper_path, 'addons'))
|
||||
|
||||
|
||||
def test_make_repo_from_nonexistent(self):
|
||||
blenderpack.make_repo(os.path.join(self.helper_path, 'addons'))
|
||||
|
Reference in New Issue
Block a user