live version parsing fixes

master
JoYo 2021-12-23 18:33:50 -05:00
parent 435230aa6e
commit 432f4128c9
3 changed files with 53 additions and 26 deletions

View File

@ -0,0 +1 @@
from .scripts import periodical_script

View File

@ -17,9 +17,13 @@ def live_to_esoui(*, path: Path, esoui_uris: list):
esoui_name, esoui_version, esoui_uri = None, None, None
for name, version, uri in esoui_uris:
if name in live_name:
esoui_name, esoui_version, esoui_uri = name, version, uri
for _name, _version, _uri in esoui_uris:
if _name in live_name:
esoui_name, esoui_version, esoui_uri = _name, _version, _uri
break
if live_name in _name:
esoui_name, esoui_version, esoui_uri = _name, _version, _uri
break
if not esoui_name:
@ -51,9 +55,20 @@ def live_to_esoui(*, path: Path, esoui_uris: list):
def esoui_to_live(*, esoui_uris: list, live_path: Path):
for addon_name, version, esoui_dowload_uri in esoui_uris:
if addon_name in list(live_path.iterdir()):
logging.info(f"{addon_name} already installed.")
for addon_name, addon_version, esoui_dowload_uri in esoui_uris:
match = None
for each in live_path.iterdir():
if addon_name in each.name:
match = each
break
if each.name in addon_name:
match = each
break
if match:
logging.debug(f"{addon_name} already installed.")
continue
response = requests.get(esoui_dowload_uri)
@ -65,9 +80,12 @@ def esoui_to_live(*, esoui_uris: list, live_path: Path):
zip_file = ZipFile(BytesIO(response.content))
zip_file.extractall(temp_path)
for each in temp_path.iterdir():
live_dest = live_path.joinpath(each.name)
for each in temp_path.iterdir():
if live_dest.exists():
continue
copytree(each, live_dest)
logging.info(f"{addon_name} installed {version} at {live_dest}")
logging.info(f"{addon_name} installed {addon_version} at {live_dest}")

View File

@ -1,3 +1,4 @@
from packaging import version
from pathlib import Path
import logging
import re
@ -7,8 +8,6 @@ esoui_prefix = re.compile("https://www.esoui.com/downloads/info[0-9]+\-")
esoui_version_html = re.compile('<div\s+id="version">Version:\s+[^<]+')
esoui_version_split = re.compile('<div\s+id="version">Version:\s+')
esoui_download = re.compile('https://cdn.esoui.com/downloads/file[^"]*')
live_title = re.compile("##\s+Title:\s+.*")
live_title_split = re.compile("##\s+Title:\s+")
live_version = re.compile("##\s+Version:\s+.*")
live_version_split = re.compile("##\s+Version:\s+")
@ -21,7 +20,8 @@ def esoui(url: str):
response.raise_for_status()
version_line = esoui_version_html.search(response.text).group(0)
version = esoui_version_split.split(version_line)[1]
_version = esoui_version_split.split(version_line)[1]
_version = version.parse(_version)
esoui_page_url = url.replace("info", "download").replace(".html", "")
@ -32,24 +32,32 @@ def esoui(url: str):
response = requests.head(esoui_dowload_uri)
response.raise_for_status()
return addon_name, version, esoui_dowload_uri
return addon_name, _version, esoui_dowload_uri
def live(path: Path):
for meta in path.glob("*.txt"):
meta_file = path.joinpath(f"{path.stem}.txt")
if not meta_file.is_file():
for meta_file in path.glob("*.txt"):
if not meta_file.stem in path.stem:
continue
try:
with meta.open("r") as file_open:
with meta_file.open("r") as file_open:
meta_data = file_open.read()
except UnicodeDecodeError:
with meta.open("r", encoding="latin-1") as file_open:
with meta_file.open("r", encoding="latin-1") as file_open:
meta_data = file_open.read()
addon_name = live_title.search(meta_data).group(0)
addon_name = live_title_split.split(addon_name)[1]
version = live_version.search(meta_data).group(0)
version = live_version_split.split(version)[1]
addon_name = meta_file.stem
result = live_version.search(meta_data)
return addon_name, version, path
if result:
_version = result.group(0)
_version = live_version_split.split(_version)[1]
_version = version.parse(_version)
else:
_version = version.parse("0")
return None, None, None
return addon_name, _version, path