Store repository on window manager so it isn't saved in the .blend
We store it outside blender in JSON anyway, storing it two places at once could be confusing. We can move it back into the .blend later if it seems that would be preferred.
This commit is contained in:
@@ -284,8 +284,7 @@ class BPKG_OT_refresh(SubprocMixin, bpy.types.Operator):
|
|||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
def _subproc_repository_result(self, result: subproc.RepositoryResult):
|
def _subproc_repository_result(self, result: subproc.RepositoryResult):
|
||||||
prefs = bpy.context.user_preferences.addons[__package__].preferences
|
bpy.context.window_manager['package_repo'] = result.repository
|
||||||
prefs['repo'] = result.repository
|
|
||||||
self.report({'INFO'}, 'Package list retrieved successfully')
|
self.report({'INFO'}, 'Package list retrieved successfully')
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
@@ -443,7 +442,7 @@ class USERPREF_PT_packages(bpy.types.Panel):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# use two lists as a simple way of putting matches from the start on top
|
# use two lists as a simple way of putting "matches from the beginning" on top
|
||||||
contains = []
|
contains = []
|
||||||
startswith = []
|
startswith = []
|
||||||
|
|
||||||
@@ -544,21 +543,22 @@ class USERPREF_PT_packages(bpy.types.Panel):
|
|||||||
row.scale_y = 10
|
row.scale_y = 10
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#TODO either store repos in windowmanager and reload from disk every time, or store them in the .blend. Not both
|
repo = wm['package_repo']
|
||||||
repo = context.user_preferences.addons[__package__].preferences['repo']
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
center_message(pkgzone, "Loading Repositories...")
|
center_message(pkgzone, "Loading Repositories...")
|
||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
# TODO: read repository synchronously for now; can't run an operator to do async monitoring from draw code
|
# TODO: read repository synchronously for now; can't run an operator to do async monitoring from draw code
|
||||||
prefs = bpy.context.user_preferences.addons[__package__].preferences
|
|
||||||
storage_path = pathlib.Path(bpy.utils.user_resource('CONFIG', 'packages', create=True))
|
storage_path = pathlib.Path(bpy.utils.user_resource('CONFIG', 'packages', create=True))
|
||||||
res = subproc._load_repo(storage_path)
|
try:
|
||||||
prefs['repo'] = res.to_dict(sort=True, ids=True)
|
res = subproc._load_repo(storage_path)
|
||||||
|
wm['package_repo'] = res.to_dict(sort=True, ids=True)
|
||||||
|
except FileNotFoundError:
|
||||||
|
wm['package_repo'] = None
|
||||||
return
|
return
|
||||||
|
|
||||||
if repo is None:
|
if repo is None:
|
||||||
center_message(pkgzone, "No repository found. Add one in the addon preferences.")
|
center_message(pkgzone, "No repositories found.")
|
||||||
return
|
return
|
||||||
|
|
||||||
filters = {
|
filters = {
|
||||||
@@ -586,15 +586,13 @@ class WM_OT_package_toggle_expand(bpy.types.Operator):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
repo = context.user_preferences.addons[__package__].preferences.get('repo')
|
repo = context.window_manager.get('package_repo')
|
||||||
|
|
||||||
if not repo:
|
if not repo:
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
pkg_id = self.package_id
|
|
||||||
|
|
||||||
for pkg in repo['packages']:
|
for pkg in repo['packages']:
|
||||||
if pkg.get('id') == pkg_id:
|
if pkg.get('id') == self.package_id:
|
||||||
# if pkg['expand'] is unset, it's not expanded
|
# if pkg['expand'] is unset, it's not expanded
|
||||||
pkg['expand'] = not pkg.get('expand', False)
|
pkg['expand'] = not pkg.get('expand', False)
|
||||||
|
|
||||||
|
@@ -310,10 +310,7 @@ class Repository:
|
|||||||
"""
|
"""
|
||||||
Read repository from a json file at `path`.
|
Read repository from a json file at `path`.
|
||||||
"""
|
"""
|
||||||
try:
|
repo_file = path.open('r', encoding='utf-8')
|
||||||
repo_file = path.open('r', encoding='utf-8')
|
|
||||||
except IOError as err:
|
|
||||||
raise BadRepository from err
|
|
||||||
|
|
||||||
with repo_file:
|
with repo_file:
|
||||||
try:
|
try:
|
||||||
@@ -513,14 +510,12 @@ def refresh(pipe_to_blender, storage_path: pathlib.Path, repository_url: str):
|
|||||||
log = logging.getLogger(__name__ + '.refresh')
|
log = logging.getLogger(__name__ + '.refresh')
|
||||||
|
|
||||||
repo_path = storage_path / 'repo.json'
|
repo_path = storage_path / 'repo.json'
|
||||||
try:
|
if repo_path.exists():
|
||||||
repo = Repository.from_file(repo_path)
|
repo = Repository.from_file(repo_path)
|
||||||
except BadRepository as err:
|
if repo.url != repository_url:
|
||||||
log.warning("Failed to read existing repository: %s. Continuing download.", err)
|
# We're getting a new repository
|
||||||
repo = Repository(repository_url)
|
repo = Repository(repository_url)
|
||||||
|
else:
|
||||||
if repo.url != repository_url:
|
|
||||||
# We're getting a new repository
|
|
||||||
repo = Repository(repository_url)
|
repo = Repository(repository_url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user