From 4841d688168f5c7e878d804a5118e029601d4c68 Mon Sep 17 00:00:00 2001 From: JoYo <> Date: Wed, 8 Jun 2022 19:38:54 -0400 Subject: [PATCH] install from script file --- banana/__init__.py | 1 - banana/__main__.py | 3 - banana/compare.py | 91 ----------------------- banana/config.py | 27 ------- banana/parsing.py | 67 ----------------- banana/scripts.py | 131 --------------------------------- banana/tamriel_trade_centre.py | 28 ------- setup.py | 13 +--- 8 files changed, 4 insertions(+), 357 deletions(-) delete mode 100644 banana/__init__.py delete mode 100644 banana/__main__.py delete mode 100644 banana/compare.py delete mode 100644 banana/config.py delete mode 100644 banana/parsing.py delete mode 100644 banana/scripts.py delete mode 100644 banana/tamriel_trade_centre.py diff --git a/banana/__init__.py b/banana/__init__.py deleted file mode 100644 index c91ed92..0000000 --- a/banana/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .scripts import periodical_script diff --git a/banana/__main__.py b/banana/__main__.py deleted file mode 100644 index bd099e3..0000000 --- a/banana/__main__.py +++ /dev/null @@ -1,3 +0,0 @@ -from . import scripts - -scripts.periodical_script() diff --git a/banana/compare.py b/banana/compare.py deleted file mode 100644 index bd49c18..0000000 --- a/banana/compare.py +++ /dev/null @@ -1,91 +0,0 @@ -from io import BytesIO -from pathlib import Path -from shutil import rmtree, copytree -from tempfile import TemporaryDirectory -from zipfile import ZipFile -import logging -import requests - -from . import parsing - - -def live_to_esoui(*, path: Path, esoui_uris: list): - live_name, live_version, live_path = parsing.live(path) - - if not live_path: - return - - 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 - break - - if live_name in _name: - esoui_name, esoui_version, esoui_uri = _name, _version, _uri - break - - if not esoui_name: - rmtree(live_path) - logging.info(f"{live_name} addon removed from: {live_path}") - return - - if esoui_version == live_version: - logging.info(f"{live_name} is already up to date.") - return - - response = requests.get(esoui_uri) - response.raise_for_status() - - temp_dir = TemporaryDirectory() - temp_path = Path(temp_dir.name) - - zip_file = ZipFile(BytesIO(response.content)) - zip_file.extractall(temp_path) - - rmtree(live_path) - - for each in temp_path.iterdir(): - copytree(each, live_path) - - logging.info( - f"{live_name} updated from {live_version} to {esoui_version} at {live_path}" - ) - - -def esoui_to_live(*, esoui_uris: list, live_path: Path): - 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) - response.raise_for_status() - - temp_dir = TemporaryDirectory() - temp_path = Path(temp_dir.name) - - zip_file = ZipFile(BytesIO(response.content)) - zip_file.extractall(temp_path) - - for each in temp_path.iterdir(): - live_dest = live_path.joinpath(each.name) - - if live_dest.exists(): - continue - - copytree(each, live_dest) - - logging.info(f"{addon_name} installed {addon_version} at {live_dest}") diff --git a/banana/config.py b/banana/config.py deleted file mode 100644 index d2d0a56..0000000 --- a/banana/config.py +++ /dev/null @@ -1,27 +0,0 @@ -import yaml -from pathlib import Path - - -def new(path: Path): - config = { - "addons": [ - "https://www.esoui.com/downloads/info7-LibAddonMenu.html", - "https://www.esoui.com/downloads/info1245-TamrielTradeCentre.html", - "https://www.esoui.com/downloads/info1146-LibCustomMenu.html", - ] - } - - with path.open("w") as file_open: - config = yaml.dump(config, file_open, default_flow_style=False) - - -def load(path: Path) -> dict: - with path.open("r") as file_open: - config = yaml.load(file_open, Loader=yaml.Loader) - - return config - - -def valid(config: dict) -> bool: - assert config.get("addons") - assert isinstance(config["addons"], list) diff --git a/banana/parsing.py b/banana/parsing.py deleted file mode 100644 index 0533166..0000000 --- a/banana/parsing.py +++ /dev/null @@ -1,67 +0,0 @@ -from packaging import version -from pathlib import Path -import logging -import re -import requests - -esoui_prefix = re.compile("https://www.esoui.com/downloads/info[0-9]+\-") -esoui_version_html = re.compile('Version:\s+[^<]+') -esoui_version_split = re.compile('Version:\s+') -esoui_download = re.compile('https://cdn.esoui.com/downloads/file[^"]*') -live_version = re.compile("##\s+Version:\s+.*") -live_version_split = re.compile("##\s+Version:\s+") - - -def esoui(url: str): - addon_name = esoui_prefix.split(url)[1] - addon_name = addon_name.split(".html")[0] - - response = requests.get(url) - response.raise_for_status() - - version_line = esoui_version_html.search(response.text).group(0) - _version = esoui_version_split.split(version_line)[1] - _version = version.parse(_version) - - esoui_page_url = url.replace("info", "download").replace(".html", "") - - response = requests.get(esoui_page_url) - response.raise_for_status() - - esoui_dowload_uri = esoui_download.search(response.text).group(0) - response = requests.head(esoui_dowload_uri) - response.raise_for_status() - - return addon_name, _version, esoui_dowload_uri - - -def live(path: Path): - if not path.is_dir(): - logging.error(f"unexpected file object {path}, ignoring") - return - - meta_file = path.joinpath(f"{path.stem}.txt") - - if not meta_file.exists(): - for meta_file in path.glob("*.txt"): - if not meta_file.stem in path.stem: - continue - - try: - with meta_file.open("r") as file_open: - meta_data = file_open.read() - except UnicodeDecodeError: - with meta_file.open("r", encoding="latin-1") as file_open: - meta_data = file_open.read() - - addon_name = meta_file.stem - result = live_version.search(meta_data) - - if result: - _version = result.group(0) - _version = live_version_split.split(_version)[1] - _version = version.parse(_version) - else: - _version = version.parse("0") - - return addon_name, _version, path diff --git a/banana/scripts.py b/banana/scripts.py deleted file mode 100644 index c33d89a..0000000 --- a/banana/scripts.py +++ /dev/null @@ -1,131 +0,0 @@ -from argparse import ArgumentParser -from pathlib import Path -from platform import system -import logging - -from . import compare -from . import config -from . import parsing -from . import tamriel_trade_centre - - -def periodical_script(): - parser = ArgumentParser( - description="Visit https://www.esoui.com/ to search for addons and their dependencies URLs. Edit addons.yaml in the ESO live path and add the URL for each addon for installation. " - ) - parser.add_argument("-v", "--verbose", action="count", help="verbose logging") - parser.add_argument("-l", "--log", action="store_true") - parser.add_argument("-p", "--eso_live_path") - args = parser.parse_args() - - if args.eso_live_path: - args.eso_live_path = Path(args.eso_live_path) - else: - if system() == "Windows": - args.eso_live_path = Path.home().joinpath( - "Documents\Elder Scrolls Online\live" - ) - else: - args.eso_live_path = Path.home().joinpath( - ".steam/steam/steamapps/compatdata/306130/pfx/drive_c/users/steamuser/Documents/Elder Scrolls Online/live/" - ) - - if args.verbose: - level = logging.DEBUG - format = "%(asctime)s %(filename)s:%(lineno)d %(message)s" - else: - level = logging.INFO - format = "%(asctime)s %(message)s" - - if args.log: - logging.basicConfig( - level=level, - format=format, - filename=args.eso_live_path.joinpath("banana.log"), - ) - else: - logging.basicConfig( - level=level, - format=format, - ) - - logging.info(args) - - config_path = Path(args.eso_live_path).joinpath("addons.yaml") - config_path.touch(exist_ok=True) - config_current = config.load(config_path) - - try: - config.valid(config_current) - except (AssertionError, AttributeError): - config.new(config_path) - config_current = config.load(config_path) - logging.info(f'addons list created at "{config_path}"') - - live_path = args.eso_live_path.joinpath("AddOns") - - if not live_path.is_dir(): - logging.error(f"eso_live_path_invalid_dir {live_path}") - return - - addon_urls = config_current.get("addons") - esoui_uris = list() - - for url in addon_urls: - esoui = parsing.esoui(url) - esoui_uris.append(esoui) - - for child in live_path.iterdir(): - compare.live_to_esoui(path=child, esoui_uris=esoui_uris) - - compare.esoui_to_live(esoui_uris=esoui_uris, live_path=live_path) - tamriel_trade_centre.update(live_path=live_path) - - -def ttc(): - parser = ArgumentParser(description="Tamriel Trade Centre price table updater.") - parser.add_argument("-v", "--verbose", action="count", help="verbose logging") - parser.add_argument("-l", "--log", action="store_true") - parser.add_argument("-p", "--eso_live_path") - args = parser.parse_args() - - if args.eso_live_path: - args.eso_live_path = Path(args.eso_live_path) - else: - if system() == "Windows": - args.eso_live_path = Path.home().joinpath( - "Documents\Elder Scrolls Online\live" - ) - else: - args.eso_live_path = Path.home().joinpath( - ".steam/steam/steamapps/compatdata/306130/pfx/drive_c/users/steamuser/Documents/Elder Scrolls Online/live/" - ) - - if args.verbose: - level = logging.DEBUG - format = "%(asctime)s %(filename)s:%(lineno)d %(message)s" - else: - level = logging.INFO - format = "%(asctime)s %(message)s" - - if args.log: - logging.basicConfig( - level=level, - format=format, - filename=args.eso_live_path.joinpath("banana.log"), - ) - else: - logging.basicConfig( - level=level, - format=format, - ) - - logging.info(args) - - live_path = Path(args.eso_live_path).joinpath("AddOns") - - if not live_path.is_dir(): - logging.error(f"eso_live_path_invalid_dir {live_path}") - return - - tamriel_trade_centre.update(live_path=live_path) diff --git a/banana/tamriel_trade_centre.py b/banana/tamriel_trade_centre.py deleted file mode 100644 index 47ea6e7..0000000 --- a/banana/tamriel_trade_centre.py +++ /dev/null @@ -1,28 +0,0 @@ -from distutils.dir_util import copy_tree -from io import BytesIO -from pathlib import Path -from tempfile import TemporaryDirectory -from zipfile import ZipFile -import logging -import requests - -price_table_uri = "https://us.tamrieltradecentre.com/download/PriceTable" -price_table_name = "TamrielTradeCentre" - - -def update(live_path: Path): - response = requests.get(price_table_uri) - response.raise_for_status() - - temp_dir = TemporaryDirectory() - temp_path = Path(temp_dir.name) - - zip_file = ZipFile(BytesIO(response.content)) - zip_file.extractall(temp_path) - - live_tamriel_trade_centre = live_path.joinpath("TamrielTradeCentre") - copy_tree(str(temp_path.absolute()), str(live_tamriel_trade_centre.absolute())) - - logging.info( - f"tamriel trade centre price table updated: {live_tamriel_trade_centre}" - ) diff --git a/setup.py b/setup.py index e9cd551..155b335 100644 --- a/setup.py +++ b/setup.py @@ -2,18 +2,13 @@ from setuptools import setup setup( name="eso-banana", - version="0.0.1", - packages=["banana"], + version="0.0.2", + scripts=["banana.py"], entry_points={ "console_scripts": [ - "eso-banana-script = banana:scripts.periodical_script", - "eso-ttc = banana:scripts.ttc", + "eso-banana-script = banana:periodical_script", + "eso-ttc = banana:ttc", ], }, python_requires=">3", - install_requires=[ - "packaging", - "PyYAML", - "requests", - ], )