update xpi version source for 6 / 7
This commit is contained in:
parent
89744c3a9d
commit
9b79f8fdcb
7
main.py
7
main.py
@ -111,20 +111,23 @@ def parse(plugin: AddonInfo, **kwargs):
|
||||
}
|
||||
xpi_filename = f'{plugin.owner}#{plugin.repository}+{release.tagName}@{release_asset["id"]}.xpi'
|
||||
details = None
|
||||
priority_sources = ['rdf', 'json']
|
||||
if release.targetZoteroVersion == '6':
|
||||
priority_sources = ['json', 'rdf']
|
||||
try:
|
||||
xpi_filepath = download_xpi(xpi_url=xpi_url,
|
||||
download_dir=kwargs.get('runtime_xpi_directory'),
|
||||
unique_name=xpi_filename,
|
||||
force_download=False,
|
||||
cache_dir=kwargs.get('cache_directory'))
|
||||
details = addon_details(xpi_filepath)
|
||||
details = addon_details(xpi_filepath, priority_sources=priority_sources)
|
||||
except:
|
||||
try:
|
||||
xpi_filepath = download_xpi(xpi_url=xpi_url,
|
||||
download_dir=kwargs.get('runtime_xpi_directory'),
|
||||
unique_name=xpi_filename,
|
||||
force_download=True)
|
||||
details = addon_details(xpi_filepath)
|
||||
details = addon_details(xpi_filepath, priority_sources=priority_sources)
|
||||
except Exception as e:
|
||||
print(f'fetch addon detail of {plugin.repo} with {xpi_url} failed: {e}')
|
||||
|
||||
|
||||
@ -67,7 +67,8 @@ class XpiDetail:
|
||||
def check_compatible_for_zotero_version(self, version: str | int):
|
||||
if isinstance(version, int):
|
||||
version = str(version) + '.*'
|
||||
if (min_version := self.min_version.replace('*', '0')) and (max_version := self.max_version.replace('*', '999')):
|
||||
if (min_version := self.min_version.replace('*', '0')) and (
|
||||
max_version := self.max_version.replace('*', '999')):
|
||||
return (compare_versions(min_version, version.replace('*', '999')) <= 0
|
||||
<= compare_versions(max_version, version.replace('*', '0')))
|
||||
|
||||
@ -203,6 +204,7 @@ def detail_from_manifest_rdf(manifest):
|
||||
result.update({entry: get_text(child_node)})
|
||||
except:
|
||||
return
|
||||
|
||||
extract_info(description, details)
|
||||
if not details.get('id') or (details.get('id').startswith("__") and details.get('id').endswith("__")):
|
||||
return
|
||||
@ -226,7 +228,6 @@ def detail_from_manifest_rdf(manifest):
|
||||
else:
|
||||
details['max_version'] = max_version
|
||||
|
||||
|
||||
for targetApplication in description.getElementsByTagName(em + "targetApplication"):
|
||||
version_info = {'id': None, 'minVersion': None, 'maxVersion': None}
|
||||
extract_info(targetApplication, version_info)
|
||||
@ -242,13 +243,18 @@ def detail_from_manifest_rdf(manifest):
|
||||
raise e
|
||||
|
||||
|
||||
def addon_details(addon_path) -> XpiDetail:
|
||||
def addon_details(addon_path, priority_sources=None) -> XpiDetail:
|
||||
if priority_sources is None:
|
||||
priority_sources = ['json', 'rdf']
|
||||
if not os.path.exists(addon_path):
|
||||
raise IOError(f"Add-on path does not exist: {addon_path}")
|
||||
xpi_detail = XpiDetail()
|
||||
for source in priority_sources:
|
||||
if source == 'json':
|
||||
if ((manifest := manifest_from_json(addon_path)) and
|
||||
(details := detail_from_manifest_json(addon_path, manifest))):
|
||||
xpi_detail._append_info(details)
|
||||
if source == 'rdf':
|
||||
if ((manifest := manifest_from_rdf(addon_path)) and
|
||||
(details := detail_from_manifest_rdf(manifest))):
|
||||
xpi_detail._append_info(details)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user