Partial expanded view implementation
Not all metadata is correctly displayed yet
This commit is contained in:
@@ -175,8 +175,11 @@ class Repository:
|
||||
log = logging.getLogger(__name__ + ".Repository")
|
||||
|
||||
def __init__(self, url=None):
|
||||
if url is None:
|
||||
url = ""
|
||||
self.set_from_dict({'url': url})
|
||||
self.log.debug("Initializing repository: %s", self.to_dict())
|
||||
self.log.debug("Own URL is '%s'", self.url)
|
||||
|
||||
# def cleanse_packagelist(self):
|
||||
# """Remove empty packages (no bl_info), packages with no name"""
|
||||
@@ -241,14 +244,21 @@ class Repository:
|
||||
self.set_from_dict(repodict)
|
||||
|
||||
|
||||
def to_dict(self, sort=False) -> dict:
|
||||
def to_dict(self, sort=False, ids=False) -> dict:
|
||||
"""
|
||||
Return a dict representation of the repository
|
||||
"""
|
||||
packages = [p.to_dict() for p in self.packages]
|
||||
|
||||
if sort:
|
||||
packages.sort(key=lambda p: p['bl_info']['name'].lower())
|
||||
|
||||
if ids:
|
||||
for pkg in packages:
|
||||
self.log.debug(pkg['url'], pkg['bl_info']['name'], self.name, self.url)
|
||||
# hash may be too big for a C int
|
||||
pkg['id'] = str(hash(pkg['url'] + pkg['bl_info']['name'] + self.name + self.url))
|
||||
|
||||
return {
|
||||
'name': self.name,
|
||||
'packages': packages,
|
||||
@@ -260,10 +270,23 @@ class Repository:
|
||||
"""
|
||||
Get repository attributes from a dict such as produced by `to_dict`
|
||||
"""
|
||||
self.name = repodict.get('name', "")
|
||||
self.url = repodict.get('url', "")
|
||||
self.packages = [Package(pkg) for pkg in repodict.get('packages', [])]
|
||||
self._headers = repodict.get('_headers', {})
|
||||
|
||||
def initialize(item, value):
|
||||
if item is None:
|
||||
return value
|
||||
else:
|
||||
return item
|
||||
|
||||
#Be certain to initialize everything; downloaded packagelist might contain null values
|
||||
name = initialize(repodict.get('name'), "")
|
||||
url = initialize(repodict.get('url'), "")
|
||||
packages = initialize(repodict.get('packages'), [])
|
||||
headers = initialize(repodict.get('_headers'), {})
|
||||
|
||||
self.name = name
|
||||
self.url = url
|
||||
self.packages = [Package(pkg) for pkg in packages]
|
||||
self._headers = headers
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, repodict: dict):
|
||||
@@ -466,6 +489,12 @@ def download_and_install(pipe_to_blender, package_url: str, install_path: pathli
|
||||
log.exception("Failed to install package: %s", err)
|
||||
pipe_to_blender.send(InstallError(err))
|
||||
|
||||
def _load_repo(storage_path: pathlib.Path) -> Repository:
|
||||
"""Reads the stored repositories"""
|
||||
|
||||
repo_path = storage_path / 'repo.json'
|
||||
return Repository.from_file(repo_path)
|
||||
|
||||
def refresh(pipe_to_blender, storage_path: pathlib.Path, repository_url: str):
|
||||
"""Retrieves and stores the given repository"""
|
||||
|
||||
@@ -489,10 +518,17 @@ def refresh(pipe_to_blender, storage_path: pathlib.Path, repository_url: str):
|
||||
return
|
||||
|
||||
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)))
|
||||
pipe_to_blender.send(RepositoryResult(repo.to_dict(sort=True, ids=True)))
|
||||
|
||||
def load(pipe_to_blender, storage_path: pathlib.Path):
|
||||
"""Reads the stored repository"""
|
||||
"""Reads the stored repository and sends the result to blender"""
|
||||
|
||||
try:
|
||||
repo = _load_repo(storage_path)
|
||||
pipe_to_blender.send(RepositoryResult(repo.to_dict(sort=True, ids=True)))
|
||||
except BadRepository as err:
|
||||
pipe_to_blender.send(SubprocError("Failed to read repository: %s" % err))
|
||||
|
||||
|
||||
def debug_hang():
|
||||
"""Hangs for an hour. For testing purposes only."""
|
||||
|
Reference in New Issue
Block a user