Repo generation: log and keep going on error
* Delete old report() functions, use logging instead * Skip addons which have problems (but give a warning)
This commit is contained in:
@@ -17,33 +17,19 @@ log = logging.getLogger(__name__)
|
|||||||
REQUIRED_KEYS = set(['name', 'blender', 'version'])
|
REQUIRED_KEYS = set(['name', 'blender', 'version'])
|
||||||
SCHEMA_VERSION = 1
|
SCHEMA_VERSION = 1
|
||||||
|
|
||||||
def report(msg):
|
class BadAddon(Exception):
|
||||||
print("blenderpack:", msg, file=sys.stderr)
|
pass
|
||||||
|
|
||||||
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 fetch(url):
|
def fetch(url):
|
||||||
# TODO: do conditional request
|
# TODO: do conditional request
|
||||||
re = requests.get(url)
|
re = requests.get(url)
|
||||||
print(re.json())
|
print(re.json())
|
||||||
|
|
||||||
def parse_blinfo(source, addon_name="unknown"):
|
|
||||||
|
def parse_blinfo(source: str) -> dict:
|
||||||
"""Parse a python file and return its bl_info dict, if there is one (else return None)"""
|
"""Parse a python file and return its bl_info dict, if there is one (else return None)"""
|
||||||
|
|
||||||
try:
|
tree = ast.parse(source)
|
||||||
tree = ast.parse(source)
|
|
||||||
except SyntaxError as ex:
|
|
||||||
log.warning('Skipping addon: SyntaxError in %s: %s', addon_name, ex)
|
|
||||||
return None
|
|
||||||
|
|
||||||
for body in tree.body:
|
for body in tree.body:
|
||||||
if body.__class__ != ast.Assign:
|
if body.__class__ != ast.Assign:
|
||||||
@@ -55,15 +41,14 @@ def parse_blinfo(source, addon_name="unknown"):
|
|||||||
|
|
||||||
return ast.literal_eval(body.value)
|
return ast.literal_eval(body.value)
|
||||||
|
|
||||||
log.warning('Unable to find bl_info dict in %s', addon_name)
|
raise BadAddon('No bl_info found')
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def extract_blinfo(path):
|
def extract_blinfo(path):
|
||||||
"""Extract bl_info dict from addon at path (can be single file, module, or zip)"""
|
"""Extract bl_info dict from addon at path (can be single file, module, or zip)"""
|
||||||
|
|
||||||
source = None
|
source = None
|
||||||
# get last component of path, even with trailing slash
|
# get last component of path, including when the path ends with trailing slash
|
||||||
addon_name = os.path.split(path.rstrip(os.path.sep))[1]
|
addon_name = os.path.split(path.rstrip(os.path.sep))[1]
|
||||||
|
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
@@ -86,7 +71,7 @@ def extract_blinfo(path):
|
|||||||
if source == None:
|
if source == None:
|
||||||
raise RuntimeError("Could not read addon '%s'" % addon_name)
|
raise RuntimeError("Could not read addon '%s'" % addon_name)
|
||||||
|
|
||||||
return parse_blinfo(source, addon_name)
|
return parse_blinfo(source)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -96,36 +81,33 @@ def make_repo(outpath):
|
|||||||
repo_data = {}
|
repo_data = {}
|
||||||
package_data = []
|
package_data = []
|
||||||
|
|
||||||
try:
|
if not os.path.exists(outpath):
|
||||||
for addon in os.listdir(outpath):
|
raise FileNotFoundError
|
||||||
package_datum = {}
|
|
||||||
addon_path = os.path.join(outpath, addon)
|
|
||||||
|
|
||||||
try:
|
for addon in os.listdir(outpath):
|
||||||
bl_info = extract_blinfo(addon_path)
|
package_datum = {}
|
||||||
if not bl_info:
|
addon_path = os.path.join(outpath, addon)
|
||||||
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)):
|
try:
|
||||||
fatal_report(
|
bl_info = extract_blinfo(addon_path)
|
||||||
"Required key(s) '{}' not found in bl_info of '{}'".format(
|
except BadAddon as err:
|
||||||
"', '".join(REQUIRED_KEYS.difference(set(bl_info))), addon),
|
log.warning('Could not extract bl_info from {}: {}'.format(addon_path, err))
|
||||||
ex=Exception()
|
continue
|
||||||
)
|
|
||||||
|
|
||||||
package_datum['bl_info'] = bl_info
|
if not REQUIRED_KEYS.issubset(set(bl_info)):
|
||||||
package_datum['type'] = 'addon'
|
log.warning(
|
||||||
package_data.append(package_datum)
|
"Required key(s) '{}' not found in bl_info of '{}'".format(
|
||||||
|
"', '".join(REQUIRED_KEYS.difference(set(bl_info))), addon)
|
||||||
|
)
|
||||||
|
|
||||||
repo_data['packages'] = package_data
|
package_datum['bl_info'] = bl_info
|
||||||
with open(os.path.join(outpath, "repo.json"), 'w', encoding='utf-8') as repo_file:
|
package_datum['type'] = 'addon'
|
||||||
json.dump(repo_data, repo_file, indent=4, sort_keys=True)
|
package_data.append(package_datum)
|
||||||
|
|
||||||
|
repo_data['packages'] = package_data
|
||||||
|
|
||||||
except FileNotFoundError:
|
with open(os.path.join(outpath, "repo.json"), 'w', encoding='utf-8') as repo_file:
|
||||||
fatal_report("No such file or directory: '%s'" % outpath)
|
json.dump(repo_data, repo_file, indent=4, sort_keys=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import os.path
|
import os.path
|
||||||
|
import json
|
||||||
import blenderpack
|
import blenderpack
|
||||||
|
|
||||||
class test_blenderpack_make_repo(unittest.TestCase):
|
class test_blenderpack_make_repo(unittest.TestCase):
|
||||||
|
@@ -1,70 +0,0 @@
|
|||||||
{
|
|
||||||
"packages": [
|
|
||||||
{
|
|
||||||
"bl_info": {
|
|
||||||
"author": "Multiple Authors",
|
|
||||||
"blender": [
|
|
||||||
2,
|
|
||||||
76,
|
|
||||||
0
|
|
||||||
],
|
|
||||||
"category": "Add Curve",
|
|
||||||
"description": "Add extra curve object types",
|
|
||||||
"location": "View3D > Add > Curve > Extra Objects",
|
|
||||||
"name": "Extra Objects",
|
|
||||||
"version": [
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
2
|
|
||||||
],
|
|
||||||
"warning": "",
|
|
||||||
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Curve_Objects"
|
|
||||||
},
|
|
||||||
"type": "addon"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"bl_info": {
|
|
||||||
"author": "testscreenings, PKHG, TrumanBlending",
|
|
||||||
"blender": [
|
|
||||||
2,
|
|
||||||
59,
|
|
||||||
0
|
|
||||||
],
|
|
||||||
"category": "Add Curve",
|
|
||||||
"description": "Adds generated ivy to a mesh object starting at the 3D cursor",
|
|
||||||
"location": "View3D > Add > Curve",
|
|
||||||
"name": "IvyGen",
|
|
||||||
"version": [
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
2
|
|
||||||
],
|
|
||||||
"warning": "",
|
|
||||||
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Ivy_Gen"
|
|
||||||
},
|
|
||||||
"type": "addon"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"bl_info": {
|
|
||||||
"author": "Multiple Authors",
|
|
||||||
"blender": [
|
|
||||||
2,
|
|
||||||
76,
|
|
||||||
0
|
|
||||||
],
|
|
||||||
"category": "Add Curve",
|
|
||||||
"description": "Add extra curve object types",
|
|
||||||
"location": "View3D > Add > Curve > Extra Objects",
|
|
||||||
"name": "Extra Objects",
|
|
||||||
"version": [
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
2
|
|
||||||
],
|
|
||||||
"warning": "",
|
|
||||||
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Curve_Objects"
|
|
||||||
},
|
|
||||||
"type": "addon"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
Reference in New Issue
Block a user