Move 'all_packages' list out of the panel class
This is used for more than drawing, so it doesn't belong on the panel.
This commit is contained in:
@@ -31,6 +31,9 @@ else:
|
||||
import bpy
|
||||
from collections import OrderedDict
|
||||
|
||||
# global list of all known packages, indexed by name
|
||||
_packages = OrderedDict()
|
||||
|
||||
class ConsolidatedPackage:
|
||||
"""
|
||||
Stores a grouping of different versions of the same package
|
||||
@@ -41,7 +44,6 @@ class ConsolidatedPackage:
|
||||
def __init__(self, pkg=None):
|
||||
self.versions = []
|
||||
self.expanded = False
|
||||
self.installed = False
|
||||
|
||||
if pkg is not None:
|
||||
self.add_version(pkg)
|
||||
@@ -298,7 +300,7 @@ class PACKAGE_OT_uninstall(SubprocMixin, bpy.types.Operator):
|
||||
install_path = pathlib.Path(bpy.utils.user_resource('SCRIPTS', 'addons', create=True))
|
||||
|
||||
# TODO: only drawing-related package data should be stored on the panel. Maybe move this to a global..?
|
||||
package = USERPREF_PT_packages.all_packages[self.package_name].get_latest_version()
|
||||
package = _packages[self.package_name].get_latest_version()
|
||||
|
||||
proc = multiprocessing.Process(target=subproc.uninstall,
|
||||
args=(self.pipe_subproc, package, install_path))
|
||||
@@ -332,8 +334,11 @@ def get_packages_from_disk(refresh=False) -> list:
|
||||
def get_packages_from_repo() -> list:
|
||||
"""Get list of packages from cached repository lists (does not refresh them from server)"""
|
||||
import pathlib
|
||||
storage_path = pathlib.Path(bpy.utils.user_resource('CONFIG', 'packages', create=True))
|
||||
repo = subproc._load_repo(storage_path)
|
||||
storage_path = pathlib.Path(bpy.utils.user_resource('CONFIG', 'packages', create=True)) / 'repo.json'
|
||||
try:
|
||||
repo = bpkg.Repository.from_file(storage_path)
|
||||
except FileNotFoundError:
|
||||
return []
|
||||
for pkg in repo.packages:
|
||||
pkg.repository = repo.name
|
||||
return repo.packages
|
||||
@@ -348,7 +353,7 @@ class PACKAGE_OT_refresh_packages(bpy.types.Operator):
|
||||
def execute(self, context):
|
||||
installed_packages = get_packages_from_disk(refresh=True)
|
||||
available_packages = get_packages_from_repo()
|
||||
USERPREF_PT_packages.all_packages = build_composite_packagelist(installed_packages, available_packages)
|
||||
_packages = build_composite_packagelist(installed_packages, available_packages)
|
||||
context.area.tag_redraw()
|
||||
|
||||
return {'FINISHED'}
|
||||
@@ -422,7 +427,7 @@ class PACKAGE_OT_refresh_repositories(SubprocMixin, bpy.types.Operator):
|
||||
for pkg in available_packages:
|
||||
pkg.repository = result.repository.name
|
||||
|
||||
USERPREF_PT_packages.all_packages = build_composite_packagelist(installed_packages, available_packages)
|
||||
_packages = build_composite_packagelist(installed_packages, available_packages)
|
||||
USERPREF_PT_packages.available_packages = available_packages
|
||||
self.report({'INFO'}, 'Package list retrieved successfully')
|
||||
|
||||
@@ -522,7 +527,6 @@ class USERPREF_PT_packages(bpy.types.Panel):
|
||||
|
||||
log = logging.getLogger(__name__ + '.USERPREF_PT_packages')
|
||||
|
||||
all_packages = OrderedDict()
|
||||
available_packages = []
|
||||
installed_packages = []
|
||||
displayed_packages = []
|
||||
@@ -731,35 +735,28 @@ class USERPREF_PT_packages(bpy.types.Panel):
|
||||
row.alignment='CENTER'
|
||||
row.scale_y = 10
|
||||
|
||||
if len(USERPREF_PT_packages.all_packages) == 0:
|
||||
center_message(pkgzone, "No packages found.")
|
||||
global _packages
|
||||
|
||||
if len(_packages) == 0:
|
||||
# TODO: read repository and installed packages synchronously for now;
|
||||
# can't run an operator from draw code to do async monitoring
|
||||
installed_packages = get_packages_from_disk()
|
||||
try:
|
||||
available_packages = get_packages_from_repo()
|
||||
except FileNotFoundError:
|
||||
center_message(pkgzone, "No repositories found")
|
||||
return
|
||||
|
||||
all_packages = build_composite_packagelist(installed_packages, available_packages)
|
||||
if len(all_packages) == 0:
|
||||
_packages = build_composite_packagelist(installed_packages, available_packages)
|
||||
if len(_packages) == 0:
|
||||
center_message(pkgzone, "No packages found")
|
||||
return
|
||||
|
||||
USERPREF_PT_packages.all_packages = all_packages
|
||||
|
||||
|
||||
filters = {
|
||||
'category': bpy.context.window_manager.addon_filter,
|
||||
'search': bpy.context.window_manager.package_search,
|
||||
}
|
||||
USERPREF_PT_packages.displayed_packages = filtered_packages(filters, USERPREF_PT_packages.all_packages)
|
||||
USERPREF_PT_packages.displayed_packages = filtered_packages(filters, _packages)
|
||||
|
||||
for pkgname in USERPREF_PT_packages.displayed_packages:
|
||||
row = pkgzone.row()
|
||||
draw_package(USERPREF_PT_packages.all_packages[pkgname], row)
|
||||
draw_package(_packages[pkgname], row)
|
||||
|
||||
|
||||
class WM_OT_package_toggle_expand(bpy.types.Operator):
|
||||
@@ -776,8 +773,9 @@ class WM_OT_package_toggle_expand(bpy.types.Operator):
|
||||
)
|
||||
|
||||
def invoke(self, context, event):
|
||||
global _packages
|
||||
try:
|
||||
pkg = USERPREF_PT_packages.all_packages[self.package_name]
|
||||
pkg = _packages[self.package_name]
|
||||
except KeyError:
|
||||
log.error("Couldn't find package '%s'", self.package_name)
|
||||
return {'CANCELLED'}
|
||||
@@ -786,7 +784,7 @@ class WM_OT_package_toggle_expand(bpy.types.Operator):
|
||||
if event.shift:
|
||||
for pkgname in USERPREF_PT_packages.displayed_packages:
|
||||
if not pkgname == self.package_name:
|
||||
USERPREF_PT_packages.all_packages[pkgname].expanded = False
|
||||
_packages[pkgname].expanded = False
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
@@ -837,7 +835,7 @@ def build_composite_packagelist(installed: list, available: list) -> OrderedDict
|
||||
pkg.installed = True
|
||||
if pkg.name in masterlist:
|
||||
for masterpkg in masterlist[pkg.name]:
|
||||
log.debug("{} and {} equivilent? {}".format((pkg.name, pkg.version), (masterpkg.name, masterpkg.version), packages_are_equivilent(pkg, masterpkg)))
|
||||
# log.debug("{} and {} equivilent? {}".format((pkg.name, pkg.version), (masterpkg.name, masterpkg.version), packages_are_equivilent(pkg, masterpkg)))
|
||||
if packages_are_equivilent(pkg, masterpkg):
|
||||
masterpkg.installed = True
|
||||
masterpkg.installed_location = pkg.installed_location
|
||||
|
Reference in New Issue
Block a user