Write some tests for UI Downloading
This commit is contained in:
@@ -3,6 +3,8 @@ import sys
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
import requests
|
||||
|
||||
from freqtrade.configuration import setup_utils_configuration
|
||||
from freqtrade.configuration.directory_operations import copy_sample_files, create_userdata_dir
|
||||
from freqtrade.constants import USERPATH_HYPEROPTS, USERPATH_STRATEGIES
|
||||
@@ -140,9 +142,8 @@ def start_new_hyperopt(args: Dict[str, Any]) -> None:
|
||||
|
||||
|
||||
def clean_ui_subdir(directory: Path):
|
||||
print(directory)
|
||||
if directory.is_dir():
|
||||
logger.info("Removing UI directory content")
|
||||
logger.info("Removing UI directory content.")
|
||||
|
||||
for p in reversed(list(directory.glob('**/*'))): # iterate contents from leaves to root
|
||||
if p.name == '.gitkeep':
|
||||
@@ -153,11 +154,28 @@ def clean_ui_subdir(directory: Path):
|
||||
p.rmdir()
|
||||
|
||||
|
||||
def download_and_install_ui(dest_folder: Path):
|
||||
import requests
|
||||
def download_and_install_ui(dest_folder: Path, dl_url: str):
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
|
||||
logger.info(f"Downloading {dl_url}")
|
||||
resp = requests.get(dl_url).content
|
||||
with ZipFile(BytesIO(resp)) as zf:
|
||||
for fn in zf.filelist:
|
||||
with zf.open(fn) as x:
|
||||
destfile = dest_folder / fn.filename
|
||||
if fn.is_dir():
|
||||
destfile.mkdir(exist_ok=True)
|
||||
else:
|
||||
destfile.write_bytes(x.read())
|
||||
|
||||
|
||||
def start_install_ui(args: Dict[str, Any]) -> None:
|
||||
|
||||
dest_folder = Path(__file__).parents[1] / 'rpc/api_server/ui'
|
||||
# First make sure the assets are removed.
|
||||
clean_ui_subdir(dest_folder)
|
||||
|
||||
base_url = 'https://api.github.com/repos/freqtrade/frequi/'
|
||||
# Get base UI Repo path
|
||||
|
||||
@@ -170,24 +188,6 @@ def download_and_install_ui(dest_folder: Path):
|
||||
r = resp.json()
|
||||
|
||||
dl_url = r[0]['browser_download_url']
|
||||
logger.info(f"Downloading {dl_url}")
|
||||
resp = requests.get(dl_url).content
|
||||
with ZipFile(BytesIO(resp)) as zf:
|
||||
for fn in zf.filelist:
|
||||
with zf.open(fn) as x:
|
||||
destfile = dest_folder / fn.filename
|
||||
print(destfile)
|
||||
if fn.is_dir():
|
||||
destfile.mkdir(exist_ok=True)
|
||||
else:
|
||||
destfile.write_bytes(x.read())
|
||||
|
||||
|
||||
def start_install_ui(args: Dict[str, Any]) -> None:
|
||||
|
||||
dest_folder = Path(__file__).parents[1] / 'rpc/api_server/ui'
|
||||
# First make sure the assets are removed.
|
||||
clean_ui_subdir(dest_folder)
|
||||
|
||||
# Download a new version
|
||||
download_and_install_ui(dest_folder)
|
||||
download_and_install_ui(dest_folder, dl_url)
|
||||
|
Reference in New Issue
Block a user