diff --git a/crunch/__version__.py b/crunch/__version__.py index 3fd8277..7916027 100644 --- a/crunch/__version__.py +++ b/crunch/__version__.py @@ -1,6 +1,6 @@ __title__ = 'crunch-cli' __description__ = 'crunch-cli - CLI of the CrunchDAO Platform' -__version__ = '0.17.0' +__version__ = '0.18.0' __author__ = 'Enzo CACERES' __author_email__ = 'enzo.caceres@crunchdao.com' __url__ = 'https://github.com/crunchdao/crunch-cli' diff --git a/crunch/command/setup.py b/crunch/command/setup.py index cfc449c..e540ae6 100644 --- a/crunch/command/setup.py +++ b/crunch/command/setup.py @@ -3,9 +3,21 @@ import tarfile import io import requests +import shutil from .. import constants + +def _check_if_already_exists(directory: str, force: bool): + if os.path.exists(directory): + if force: + print(f"{directory}: deleting") + shutil.rmtree(directory) + else: + print(f"{directory}: already exists (use --force to override)") + raise click.Abort() + + def setup( session: requests.Session, clone_token: str, @@ -13,10 +25,9 @@ def setup( project_name: str, directory: str, model_directory: str, + force: bool, ): - if os.path.exists(directory): - print(f"{directory}: already exists") - raise click.Abort() + _check_if_already_exists(directory, force) push_token = session.post(f"/v1/projects/{project_name}/tokens", json={ "type": "PERMANENT", @@ -47,12 +58,12 @@ def setup( for member in tar.getmembers(): path = os.path.join(directory, member.name) print(f"extract {path}") - + os.makedirs(os.path.dirname(path), exist_ok=True) fileobj = tar.extractfile(member) with open(path, "wb") as fd: fd.write(fileobj.read()) - + path = os.path.join(directory, model_directory) os.makedirs(path, exist_ok=True) diff --git a/crunch/main.py b/crunch/main.py index 6c6e559..d5e9294 100644 --- a/crunch/main.py +++ b/crunch/main.py @@ -35,6 +35,7 @@ def cli( @click.option("--token", "clone_token", required=True, help="Clone token to use.") @click.option("--submission", "submission_number", required=False, type=int, help="Submission number to clone. (latest if not specified)") @click.option("--no-data", is_flag=True, help="Do not download the data. (faster)") +@click.option("--force", "-f", is_flag=True, help="Deleting the old directory (if any).") @click.option("--model-directory", "model_directory_path", default="resources", show_default=True, help="Directory where your model is stored.") @click.argument("project-name", required=True) @click.argument("directory", default="{projectName}") @@ -42,6 +43,7 @@ def setup( clone_token: str, submission_number: str, no_data: bool, + force: bool, project_name: str, directory: str, model_directory_path: str, @@ -55,6 +57,7 @@ def setup( project_name=project_name, directory=directory, model_directory=model_directory_path, + force=force, ) if not no_data: