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