Include installed packages in listing

This commit is contained in:
Ellwood Zwovic
2017-07-19 22:24:27 -07:00
parent 2414743a83
commit 31ce5f7015
2 changed files with 205 additions and 54 deletions

View File

@@ -141,10 +141,13 @@ class Package:
Stores package methods and metadata
"""
log = logging.getLogger(__name__ + ".Repository")
log = logging.getLogger(__name__ + ".Package")
def __init__(self, package_dict:dict = None):
self.from_dict(package_dict)
self.bl_info = {}
self.url = ""
self.files = []
self.set_from_dict(package_dict)
def to_dict(self) -> dict:
"""
@@ -153,18 +156,61 @@ class Package:
return {
'bl_info': self.bl_info,
'url': self.url,
'files': self.files,
}
def from_dict(self, package_dict: dict):
def set_from_dict(self, package_dict: dict):
"""
Get attributes from a dict such as produced by `to_dict`
"""
if package_dict is None:
package_dict = {}
for attr in ('files', 'url', 'bl_info'):
if package_dict.get(attr) is not None:
setattr(self, attr, package_dict[attr])
for attr in ('name', 'url', 'bl_info'):
setattr(self, attr, package_dict.get(attr))
#bl_info convenience getters
def get_name() -> str:
"""Get name from bl_info"""
return self.bl_info['name']
def get_description() -> str:
"""Get description from bl_info"""
return self.bl_info['description']
# @classmethod
# def from_dict(cls, package_dict: dict):
# """
# Return a Package with values from dict
# """
# pkg = cls()
# pkg.set_from_dict(package_dict)
@classmethod
def from_blinfo(cls, blinfo: dict):
"""
Return a Package with bl_info filled in
"""
return cls({'bl_info': blinfo})
@classmethod
def from_module(cls, module):
"""
Return a Package object from an addon module
"""
from pathlib import Path
filepath = Path(module.__file__)
if filepath.name == '__init__.py':
filepath = filepath.parent
pkg = cls()
pkg.files = [filepath]
try:
pkg.bl_info = module.bl_info
except AttributeError as err:
raise BadAddon("Module does not appear to be an addon; no bl_info attribute") from err
return pkg
class Repository:
@@ -526,6 +572,7 @@ def refresh(pipe_to_blender, storage_path: pathlib.Path, repository_url: str):
repo.to_file(repo_path) # TODO: this always writes even if repo wasn't changed
pipe_to_blender.send(RepositoryResult(repo.to_dict(sort=True, ids=True)))
pipe_to_blender.send(Success())
def load(pipe_to_blender, storage_path: pathlib.Path):
"""Reads the stored repository and sends the result to blender"""