Skip to content

Commit

Permalink
added cleanup cli function to match the current README and enable eas…
Browse files Browse the repository at this point in the history
…y project teardown
  • Loading branch information
asampat3090 committed May 11, 2018
1 parent c2d61c3 commit 2361adf
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 6 deletions.
32 changes: 32 additions & 0 deletions datmo/cli/command/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,35 @@ def status(self):
self.cli_helper.echo("no unstaged tasks")

return status_dict, latest_snapshot, ascending_unstaged_tasks

def cleanup(self):
# Prompt user to ensure they would like to remove all datmo information
response = self.cli_helper.prompt_bool(
__("prompt", "cli.project.cleanup.confirm"))

# Cleanup datmo project if user specifies
if response:
self.cli_helper.echo(
__(
"info", "cli.project.cleanup", {
"name": self.project_controller.model.name,
"path": self.project_controller.home
}))
try:
success = self.project_controller.cleanup()
if success:
self.cli_helper.echo(
__(
"info", "cli.project.cleanup.success", {
"name": self.project_controller.model.name,
"path": self.project_controller.home
}))
return success
except Exception:
self.cli_helper.echo(
__(
"info", "cli.project.cleanup.failure", {
"name": self.project_controller.model.name,
"path": self.project_controller.home
}))
return False
26 changes: 26 additions & 0 deletions datmo/cli/command/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,29 @@ def test_status_invalid_arg(self):
except UnrecognizedCLIArgument:
exception_thrown = True
assert exception_thrown

def test_cleanup(self):
test_name = "foobar"
test_description = "test model"
self.project.parse(
["init", "--name", test_name, "--description", test_description])
_ = self.project.execute()

self.project.parse(["cleanup"])

@self.project.cli_helper.input("y\n")
def dummy(self):
return self.project.execute()

result = dummy(self)
assert not os.path.exists(os.path.join(self.temp_dir, '.datmo'))
assert isinstance(result, bool)
assert result

def test_cleanup_invalid_arg(self):
exception_thrown = False
try:
self.project.parse(["cleanup", "--foobar"])
except UnrecognizedCLIArgument:
exception_thrown = True
assert exception_thrown
4 changes: 3 additions & 1 deletion datmo/cli/driver/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def prompt(self, msg, default=None):
pass

def prompt_bool(self, msg):
msg = msg + ": "
val = input(msg).lower()
return val in [
'true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly', 'uh-huh'
Expand Down Expand Up @@ -99,5 +100,6 @@ def get_command_class(self, command_name):

def get_command_choices(self):
return [
"init", "version", "--version", "-v", "status", "snapshot", "task"
"init", "version", "--version", "-v", "status", "cleanup",
"snapshot", "task"
]
4 changes: 3 additions & 1 deletion datmo/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def main():
elif command_name == "status":
command_name = "project"
sys.argv[1] = "status"

elif command_name == "cleanup":
command_name = "project"
sys.argv[1] = "cleanup"
command_class = cli_helper.get_command_class(command_name)
else:
command_class = BaseCommand
Expand Down
2 changes: 2 additions & 0 deletions datmo/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def get_datmo_parser():

status_parser = subparsers.add_parser("status", help="project status")

cleanup_parser = subparsers.add_parser("cleanup", help="remove project")

# Session
session_parser = subparsers.add_parser("session", help="session module")
session_subcommand_parsers = session_parser.add_subparsers(
Expand Down
20 changes: 16 additions & 4 deletions datmo/core/util/lang/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"Pulling information from the Datmo project url and adding it to local...",
"cli.project.update":
"Update Datmo project",
"cli.project.cleanup":
"Cleaning up project {name} @ ({path}) ",
"cli.project.cleanup.success":
"Removed project {name} @ ({path}) ",
"cli.project.cleanup.failure":
"Failed to remove project {name} @ ({path}) ",
"cli.general.abort":
u'\u274c' + " Your changes have been aborted!",
"cli.general.success":
Expand Down Expand Up @@ -282,10 +288,16 @@
"trace": {},
"fatal": {},
"prompt": {
"cli.project.init.name": "Enter name for the project",
"cli.project.init.description": "Enter description for the project",
"cli.project.init.git": "Enter remote git url for the Datmo project",
"cli.general.confirm": "Is it okay?",
"cli.project.init.name":
"Enter name for the project",
"cli.project.init.description":
"Enter description for the project",
"cli.project.init.git":
"Enter remote git url for the Datmo project",
"cli.general.confirm":
"Is it okay?",
"cli.project.cleanup.confirm":
"Are you sure you want to delete all datmo project information? [yN]",
},
"argparser": {
"cli.datmo.usage":
Expand Down

0 comments on commit 2361adf

Please sign in to comment.