Allow resetting of the directory

This commit is contained in:
Matthias
2019-11-01 14:08:55 +01:00
parent 19b1a6c638
commit 41494f28da
5 changed files with 19 additions and 6 deletions

View File

@@ -53,10 +53,11 @@ def create_userdata_dir(directory: str, create_dir=False) -> Path:
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.
:param directory: Directory to copy data to
:param overwrite: Overwrite existing sample files
"""
if not directory.is_dir():
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.")
targetfile = targetdir / source
if targetfile.exists():
logger.warning(f"File `{targetfile}` exists already, not deploying sample file.")
continue
if not overwrite:
logger.warning(f"File `{targetfile}` exists already, not deploying sample file.")
continue
else:
logger.warning(f"File `{targetfile}` exists already, overwriting.")
shutil.copy(str(sourcedir / source), str(targetfile))