Extensions: detect dropping URL's from disabled repositories
Report an error when dropping a URL into a repository which has been disabled.
This commit is contained in:
parent
b19d4d7df6
commit
29f1c96657
@ -140,6 +140,16 @@ class CheckSIGINT_Context:
|
||||
# Internal Utilities
|
||||
#
|
||||
|
||||
def _preferences_repo_find_by_remote_url(context, remote_url):
|
||||
remote_url = remote_url.rstrip("/")
|
||||
prefs = context.preferences
|
||||
extension_repos = prefs.extensions.repos
|
||||
for repo in extension_repos:
|
||||
if repo.use_remote_url and repo.remote_url.rstrip("/") == remote_url:
|
||||
return repo
|
||||
return None
|
||||
|
||||
|
||||
def extension_url_find_repo_index_and_pkg_id(url):
|
||||
from .bl_extension_utils import (
|
||||
pkg_manifest_archive_url_abs_from_remote_url,
|
||||
@ -1922,9 +1932,19 @@ class BlPkgPkgInstall(Operator, _BlPkgCmdMixIn):
|
||||
return self.execute(context)
|
||||
|
||||
def _invoke_for_drop(self, context, event):
|
||||
from .bl_extension_utils import url_params_extract_repo_url
|
||||
|
||||
url = self.url
|
||||
print("DROP URL:", url)
|
||||
|
||||
# First check if this is part of a disabled repository.
|
||||
remote_url = url_params_extract_repo_url(url)
|
||||
repo_from_url = None if remote_url is None else _preferences_repo_find_by_remote_url(context, remote_url)
|
||||
|
||||
if repo_from_url and not repo_from_url.enabled:
|
||||
self.report({'ERROR'}, "Extension: repository \"{:s}\" exists but is disabled".format(repo_from_url.name))
|
||||
return {'CANCELLED'}
|
||||
|
||||
_preferences_ensure_sync()
|
||||
|
||||
repo_index, repo_name, pkg_id, item_remote, item_local = extension_url_find_repo_index_and_pkg_id(url)
|
||||
|
@ -27,6 +27,7 @@ __all__ = (
|
||||
"pkg_theme_file_list",
|
||||
"platform_from_this_system",
|
||||
"url_params_append_for_blender",
|
||||
"url_params_extract_repo_url",
|
||||
"file_mtime_or_none",
|
||||
|
||||
# Public API.
|
||||
@ -356,6 +357,35 @@ def url_params_append_for_blender(url: str, blender_version: Tuple[int, int, int
|
||||
return _url_params_append(url, params)
|
||||
|
||||
|
||||
def url_params_extract_repo_url(url: str) -> Optional[str]:
|
||||
# Extract `?repository=...` value from the URL and return it.
|
||||
# Concatenating it where appropriate.
|
||||
import urllib
|
||||
import urllib.parse
|
||||
|
||||
# Parse the URL to get its scheme, domain, and query parameters.
|
||||
parsed_url = urllib.parse.urlparse(url)
|
||||
|
||||
# Combine existing query parameters with new parameters
|
||||
params = urllib.parse.parse_qsl(parsed_url.query)
|
||||
|
||||
if repo_path := next((value for key, value in params if key == "repository"), None):
|
||||
if repo_path.startswith("/"):
|
||||
repo_url = urllib.parse.urlunparse((
|
||||
parsed_url.scheme,
|
||||
parsed_url.netloc,
|
||||
repo_path[1:],
|
||||
None, # `parsed_url.params,`
|
||||
None, # `parsed_url.query,`
|
||||
None, # `parsed_url.fragment,`
|
||||
))
|
||||
else:
|
||||
repo_url = repo_path
|
||||
return repo_url
|
||||
|
||||
return None
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Public Repository Actions
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user