Store freqUI version and read it again
This commit is contained in:
parent
2af1d2d639
commit
944d674eeb
@ -1,7 +1,7 @@
|
||||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Tuple
|
||||
from typing import Any, Dict, Optional, Tuple
|
||||
|
||||
import requests
|
||||
|
||||
@ -154,7 +154,16 @@ def clean_ui_subdir(directory: Path):
|
||||
p.rmdir()
|
||||
|
||||
|
||||
def download_and_install_ui(dest_folder: Path, dl_url: str):
|
||||
def read_ui_version(dest_folder: Path) -> Optional[str]:
|
||||
file = dest_folder / '.uiversion'
|
||||
if not file.is_file():
|
||||
return None
|
||||
|
||||
with file.open('r') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def download_and_install_ui(dest_folder: Path, dl_url: str, version: str):
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
|
||||
@ -168,6 +177,8 @@ def download_and_install_ui(dest_folder: Path, dl_url: str):
|
||||
destfile.mkdir(exist_ok=True)
|
||||
else:
|
||||
destfile.write_bytes(x.read())
|
||||
with (dest_folder / '.uiversion').open('w') as f:
|
||||
f.write(version)
|
||||
|
||||
|
||||
def get_ui_download_url() -> Tuple[str, str]:
|
||||
@ -199,10 +210,16 @@ 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.
|
||||
dl_url, latest_version = get_ui_download_url()
|
||||
clean_ui_subdir(dest_folder)
|
||||
|
||||
curr_version = read_ui_version(dest_folder)
|
||||
if curr_version == latest_version and not args.get('erase_ui_only'):
|
||||
logger.info(f"UI already uptodate, FreqUI Version {curr_version}.")
|
||||
return
|
||||
|
||||
if args.get('erase_ui_only'):
|
||||
clean_ui_subdir(dest_folder)
|
||||
logger.info("Erased UI directory content. Not downloading new version.")
|
||||
else:
|
||||
|
||||
# Download a new version
|
||||
download_and_install_ui(dest_folder, dl_url)
|
||||
download_and_install_ui(dest_folder, dl_url, latest_version)
|
||||
|
@ -14,7 +14,7 @@ from freqtrade.commands import (start_convert_data, start_create_userdir, start_
|
||||
start_new_hyperopt, start_new_strategy, start_show_trades,
|
||||
start_test_pairlist, start_trading)
|
||||
from freqtrade.commands.deploy_commands import (clean_ui_subdir, download_and_install_ui,
|
||||
get_ui_download_url)
|
||||
get_ui_download_url, read_ui_version)
|
||||
from freqtrade.configuration import setup_utils_configuration
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.state import RunMode
|
||||
@ -563,6 +563,7 @@ def test_start_install_ui(mocker):
|
||||
clean_mock = mocker.patch('freqtrade.commands.deploy_commands.clean_ui_subdir')
|
||||
get_url_mock = mocker.patch('freqtrade.commands.deploy_commands.get_ui_download_url')
|
||||
download_mock = mocker.patch('freqtrade.commands.deploy_commands.download_and_install_ui')
|
||||
mocker.patch('freqtrade.commands.deploy_commands.read_ui_version', return_value=None)
|
||||
args = [
|
||||
"install-ui",
|
||||
]
|
||||
@ -616,15 +617,16 @@ def test_download_and_install_ui(mocker, tmpdir):
|
||||
|
||||
mocker.patch("freqtrade.commands.deploy_commands.Path.is_dir",
|
||||
side_effect=[True, False])
|
||||
mkdir_mock = mocker.patch("freqtrade.commands.deploy_commands.Path.mkdir")
|
||||
wb_mock = mocker.patch("freqtrade.commands.deploy_commands.Path.write_bytes")
|
||||
|
||||
folder = Path(tmpdir) / "uitests_dl"
|
||||
download_and_install_ui(folder, 'http://whatever.xxx/download/file.zip')
|
||||
folder.mkdir(exist_ok=True)
|
||||
download_and_install_ui(folder, 'http://whatever.xxx/download/file.zip', '22')
|
||||
|
||||
assert mkdir_mock.call_count == 1
|
||||
assert wb_mock.call_count == 2
|
||||
|
||||
assert read_ui_version(folder) == '22'
|
||||
|
||||
|
||||
def test_get_ui_download_url(mocker):
|
||||
response = MagicMock()
|
||||
|
Loading…
Reference in New Issue
Block a user