diff options
author | gandalf3 <gandalf3@blendermonkey.com> | 2017-08-29 07:49:16 +0300 |
---|---|---|
committer | gandalf3 <gandalf3@blendermonkey.com> | 2017-08-29 07:49:16 +0300 |
commit | 94c48c8f9238901589e801f5bf4b8c28fc0f6049 (patch) | |
tree | a49e2d943ff784e62f30371cdd0a4afdfd9ee374 /release | |
parent | 684d870dc46bdd8fb77a616483a36aff255f50a1 (diff) |
Simplify package list refreshing
Currently no need for caching system, just regenerate it when asked
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/bpkg/__init__.py | 27 | ||||
-rw-r--r-- | release/scripts/startup/bl_operators/package.py | 20 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_userpref.py | 14 |
3 files changed, 27 insertions, 34 deletions
diff --git a/release/scripts/modules/bpkg/__init__.py b/release/scripts/modules/bpkg/__init__.py index 4b1ef156c68..1971ae18ad1 100644 --- a/release/scripts/modules/bpkg/__init__.py +++ b/release/scripts/modules/bpkg/__init__.py @@ -11,8 +11,8 @@ from pathlib import Path from collections import OrderedDict import logging -_tag_reindex = True -_packages = {} +# global package list, use refresh_packages() to refresh +packages = {} def get_repo_storage_path() -> Path: """Return Path to the directory in which downloaded repository indices are @@ -68,8 +68,8 @@ def _build_packagelist() -> dict: # {{{ masterlist = {} display.pkg_errors.clear() - installed_packages = get_installed_packages(refresh=True) - known_repositories = get_repositories() + installed_packages = get_installed_packages(refresh=True)# {{{ + known_repositories = get_repositories()# }}} for repo in known_repositories: for pkg in repo.packages: @@ -90,17 +90,8 @@ def _build_packagelist() -> dict: # {{{ return masterlist # }}} -def tag_reindex(): - """Set flag for rebuilding package list""" - global _tag_reindex - _tag_reindex = True - -def list_packages(): - """Return same dict as _build_packagelist, but only re-build it when tag_reindex == True""" - global _packages - global _tag_reindex - if _tag_reindex: - _packages = _build_packagelist() - _tag_reindex = False - - return _packages +def refresh_packages(): + """Update bpkg.packages""" + global packages + packages = _build_packagelist() + return packages diff --git a/release/scripts/startup/bl_operators/package.py b/release/scripts/startup/bl_operators/package.py index ee32c31dac1..233f31b5992 100644 --- a/release/scripts/startup/bl_operators/package.py +++ b/release/scripts/startup/bl_operators/package.py @@ -189,7 +189,7 @@ else: messages.Aborted: self._subproc_aborted, } - package = bpkg.list_packages()[self.package_name].get_latest_version() + package = bpkg.packages[self.package_name].get_latest_version() import pathlib @@ -216,7 +216,7 @@ else: def _subproc_success(self, success: messages.Success): self.report({'INFO'}, 'Package installed successfully') - bpkg.tag_reindex() + bpkg.refresh_packages() bpy.context.area.tag_redraw() self.quit() @@ -262,7 +262,7 @@ else: import pathlib install_path = pathlib.Path(bpy.utils.user_resource('SCRIPTS', 'addons', create=True)) - package = bpkg.list_packages()[self.package_name].get_latest_version() + package = bpkg.packages[self.package_name].get_latest_version() proc = mp_context.Process(target=subproc.uninstall_package, args=(self.pipe_subproc, package, install_path)) @@ -275,8 +275,8 @@ else: def _subproc_success(self, success: messages.Success): self.report({'INFO'}, 'Package uninstalled successfully') + bpkg.refresh_packages() bpy.context.area.tag_redraw() - bpkg.tag_reindex() self.quit() def report_process_died(self): @@ -301,8 +301,8 @@ else: wm = context.window_manager self.repositories = wm.package_repositories if len(self.repositories) == 0: - bpkg.tag_reindex() - return {'CANCELLED'} + bpkg.refresh_packages() + return {'FINISHED'} PACKAGE_OT_refresh._running = True return super().invoke(context, event) @@ -362,7 +362,7 @@ else: def _subproc_success(self, success: messages.Success): self.report({'INFO'}, 'Finished refreshing lists') bpkg.refresh_repository_props() - bpkg.tag_reindex() + bpkg.refresh_packages() self.quit() def _subproc_aborted(self, aborted: messages.Aborted): @@ -522,7 +522,7 @@ else: def execute(self, context): import addon_utils - metapkg = bpkg.list_packages()[self.package_name] + metapkg = bpkg.packages[self.package_name] if not metapkg.installed: @@ -561,7 +561,7 @@ else: ) def execute(self, context): - package = bpkg.list_packages()[self.package_name].get_display_version() + package = bpkg.packages[self.package_name].get_display_version() if not package.module_name: self.log.error("Can't disable package without a module name") @@ -569,7 +569,7 @@ else: ret = bpy.ops.wm.addon_disable(package.module_name) if ret == {'FINISHED'}: - bpkg.list_packages()[self.package_name].enabled = False + bpkg.packages[self.package_name].enabled = False return ret classes = ( diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py index 5528e4a1469..b26f7bf5abc 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -1637,15 +1637,17 @@ class USERPREF_PT_packages(Panel): row.scale_y = 10 + # Things which only should be run once; initialize repository props and + # packages TODO: keeping it here in draw() means it's lazy loaded, + # perhaps it might be better to do asynchronously on startup if not USERPREF_PT_packages._started: USERPREF_PT_packages._started = True bpkg.refresh_repository_props() + bpkg.refresh_packages() + # Enable all repositories by default wm.package_repository_filter = set(repo['name'] for repo in wm.package_repositories) - # TODO: read repositories and installed packages synchronously for now - packages = bpkg.list_packages() - - if len(packages) == 0: + if len(bpkg.packages) == 0: center_message(pkgzone, "No packages found") return @@ -1665,11 +1667,11 @@ class USERPREF_PT_packages(Panel): 'repository': wm.package_repository_filter, 'installstate': wm.package_state_filter, } - bpkg.display.displayed_packages = filter_packages(filters, packages) + bpkg.display.displayed_packages = filter_packages(filters, bpkg.packages) for pkgname in bpkg.display.displayed_packages: row = pkgzone.row() - draw_package(packages[pkgname], row) + draw_package(bpkg.packages[pkgname], row) class USERPREF_PT_addons(Panel): |