Skip to content

Commit

Permalink
feat(setup): add --force
Browse files Browse the repository at this point in the history
  • Loading branch information
Caceresenzo committed May 5, 2023
1 parent 78bd750 commit 04eee36
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crunch/__version__.py
Original file line number Diff line number Diff line change
@@ -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__ = '[email protected]'
__url__ = 'https://github.com/crunchdao/crunch-cli'
21 changes: 16 additions & 5 deletions crunch/command/setup.py
Original file line number Diff line number Diff line change
@@ -3,20 +3,31 @@
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,
submission_number: str,
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)
3 changes: 3 additions & 0 deletions crunch/main.py
Original file line number Diff line number Diff line change
@@ -35,13 +35,15 @@ 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}")
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:

0 comments on commit 04eee36

Please sign in to comment.