Allow resetting of the directory
This commit is contained in:
parent
19b1a6c638
commit
41494f28da
@ -37,7 +37,7 @@ ARGS_LIST_TIMEFRAMES = ["exchange", "print_one_column"]
|
|||||||
ARGS_LIST_PAIRS = ["exchange", "print_list", "list_pairs_print_json", "print_one_column",
|
ARGS_LIST_PAIRS = ["exchange", "print_list", "list_pairs_print_json", "print_one_column",
|
||||||
"print_csv", "base_currencies", "quote_currencies", "list_pairs_all"]
|
"print_csv", "base_currencies", "quote_currencies", "list_pairs_all"]
|
||||||
|
|
||||||
ARGS_CREATE_USERDIR = ["user_data_dir"]
|
ARGS_CREATE_USERDIR = ["user_data_dir", "reset"]
|
||||||
|
|
||||||
ARGS_DOWNLOAD_DATA = ["pairs", "pairs_file", "days", "download_trades", "exchange",
|
ARGS_DOWNLOAD_DATA = ["pairs", "pairs_file", "days", "download_trades", "exchange",
|
||||||
"timeframes", "erase"]
|
"timeframes", "erase"]
|
||||||
|
@ -62,6 +62,11 @@ AVAILABLE_CLI_OPTIONS = {
|
|||||||
help='Path to userdata directory.',
|
help='Path to userdata directory.',
|
||||||
metavar='PATH',
|
metavar='PATH',
|
||||||
),
|
),
|
||||||
|
"reset": Arg(
|
||||||
|
'--reset',
|
||||||
|
help='Reset sample files to their original state.',
|
||||||
|
action='store_true',
|
||||||
|
),
|
||||||
# Main options
|
# Main options
|
||||||
"strategy": Arg(
|
"strategy": Arg(
|
||||||
'-s', '--strategy',
|
'-s', '--strategy',
|
||||||
|
@ -53,10 +53,11 @@ def create_userdata_dir(directory: str, create_dir=False) -> Path:
|
|||||||
return folder
|
return folder
|
||||||
|
|
||||||
|
|
||||||
def copy_sample_files(directory: Path) -> None:
|
def copy_sample_files(directory: Path, overwrite: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
Copy files from templates to User data directory.
|
Copy files from templates to User data directory.
|
||||||
:param directory: Directory to copy data to
|
:param directory: Directory to copy data to
|
||||||
|
:param overwrite: Overwrite existing sample files
|
||||||
"""
|
"""
|
||||||
if not directory.is_dir():
|
if not directory.is_dir():
|
||||||
raise OperationalException(f"Directory `{directory}` does not exist.")
|
raise OperationalException(f"Directory `{directory}` does not exist.")
|
||||||
@ -67,6 +68,9 @@ def copy_sample_files(directory: Path) -> None:
|
|||||||
raise OperationalException(f"Directory `{targetdir}` does not exist.")
|
raise OperationalException(f"Directory `{targetdir}` does not exist.")
|
||||||
targetfile = targetdir / source
|
targetfile = targetdir / source
|
||||||
if targetfile.exists():
|
if targetfile.exists():
|
||||||
|
if not overwrite:
|
||||||
logger.warning(f"File `{targetfile}` exists already, not deploying sample file.")
|
logger.warning(f"File `{targetfile}` exists already, not deploying sample file.")
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
logger.warning(f"File `{targetfile}` exists already, overwriting.")
|
||||||
shutil.copy(str(sourcedir / source), str(targetfile))
|
shutil.copy(str(sourcedir / source), str(targetfile))
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from freqtrade.loggers import setup_logging
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
@ -82,7 +83,7 @@ def start_create_userdir(args: Dict[str, Any]) -> None:
|
|||||||
"""
|
"""
|
||||||
if "user_data_dir" in args and args["user_data_dir"]:
|
if "user_data_dir" in args and args["user_data_dir"]:
|
||||||
userdir = create_userdata_dir(args["user_data_dir"], create_dir=True)
|
userdir = create_userdata_dir(args["user_data_dir"], create_dir=True)
|
||||||
copy_sample_files(userdir)
|
copy_sample_files(userdir, overwrite=args["reset"])
|
||||||
else:
|
else:
|
||||||
logger.warning("`create-userdir` requires --userdir to be set.")
|
logger.warning("`create-userdir` requires --userdir to be set.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -80,4 +80,7 @@ def test_copy_sample_files_errors(mocker, default_conf, caplog) -> None:
|
|||||||
mocker.patch.object(Path, "is_dir", MagicMock(return_value=True))
|
mocker.patch.object(Path, "is_dir", MagicMock(return_value=True))
|
||||||
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
||||||
copy_sample_files(Path('/tmp/bar'))
|
copy_sample_files(Path('/tmp/bar'))
|
||||||
assert log_has_re(r"File `.*` exists already, not deploying sample.*", caplog)
|
assert log_has_re(r"File `.*` exists already, not deploying sample file\.", caplog)
|
||||||
|
caplog.clear()
|
||||||
|
copy_sample_files(Path('/tmp/bar'), overwrite=True)
|
||||||
|
assert log_has_re(r"File `.*` exists already, overwriting\.", caplog)
|
||||||
|
Loading…
Reference in New Issue
Block a user