Skip to content

Commit

Permalink
Merge pull request #251 from datmo/snapshot-ls
Browse files Browse the repository at this point in the history
Adding current state information during snapshot ls
  • Loading branch information
asampat3090 committed Aug 20, 2018
2 parents 12fbb00 + 286c73a commit c278379
Show file tree
Hide file tree
Showing 21 changed files with 631 additions and 183 deletions.
87 changes: 32 additions & 55 deletions datmo/cli/command/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,70 +135,25 @@ def version(self):

@Helper.notify_no_project_found
def status(self):
status_dict, latest_snapshot_user_generated, latest_snapshot_auto_generated, unstaged_code, unstaged_environment, unstaged_files = \
status_dict, current_snapshot, latest_snapshot_user_generated, latest_snapshot_auto_generated, unstaged_code, unstaged_environment, unstaged_files = \
self.project_controller.status()

# Print out simple project meta data
for k, v in status_dict.items():
if k != "config":
self.cli_helper.echo(str(k) + ": " + str(v))

self.cli_helper.echo("")

# Print out project config meta data
self.cli_helper.echo("config: ")
self.cli_helper.echo(status_dict['config'])

self.cli_helper.echo("")

# Print out info for the latest snapshot created by the user
self.cli_helper.echo(
"latest snapshot generated by the user (run `datmo snapshot ls` for more info): "
)
if latest_snapshot_user_generated:
self.cli_helper.echo(latest_snapshot_user_generated)
else:
self.cli_helper.echo("no user-generated snapshots created yet")

self.cli_helper.echo("")

# Print out info for the latest snapshot autogenerated by datmo
self.cli_helper.echo(
"latest snapshot autogenerated by datmo (run `datmo snapshot ls --all` for more info): "
)
if latest_snapshot_auto_generated:
self.cli_helper.echo(latest_snapshot_auto_generated)
else:
self.cli_helper.echo("no auto-generated snapshots created yet")

self.cli_helper.echo("")

# Print out the latest snapshot if no unstaged changes
# Print out any unstaged changes else print out the latest snapshot state of the repository
if not unstaged_code and not unstaged_environment and not unstaged_files:
if not latest_snapshot_user_generated and not latest_snapshot_auto_generated:
self.cli_helper.echo(
"all changes have been saved, no unstaged changes")
self.cli_helper.echo("no latest snapshot")
elif latest_snapshot_user_generated and not latest_snapshot_auto_generated:
self.cli_helper.echo(
"all changes have been saved, no unstaged changes")
self.cli_helper.echo("latest snapshot:")
self.cli_helper.echo(latest_snapshot_user_generated)
elif not latest_snapshot_user_generated and latest_snapshot_auto_generated:
self.cli_helper.echo(
"all changes have been saved, no unstaged changes")
self.cli_helper.echo("latest snapshot:")
self.cli_helper.echo(latest_snapshot_auto_generated)
else:
self.cli_helper.echo(
"all changes have been saved, no unstaged changes")
self.cli_helper.echo("latest snapshot:")
if latest_snapshot_user_generated.created_at > latest_snapshot_auto_generated.created_at:
self.cli_helper.echo(latest_snapshot_user_generated)
else:
self.cli_helper.echo(latest_snapshot_auto_generated)
self.cli_helper.echo(
"all changes have been saved, no unstaged changes")
self.cli_helper.echo("")
self.cli_helper.echo("current snapshot state of the repository: ")
if current_snapshot:
self.cli_helper.echo(current_snapshot)
else:
# Print out the the unstaged components if unstaged
# Print out the unstaged components if unstaged
self.cli_helper.echo("unstaged changes since latest snapshot:")
if unstaged_code:
self.cli_helper.echo("code has been changed")
Expand All @@ -207,7 +162,29 @@ def status(self):
if unstaged_files:
self.cli_helper.echo("files have been changed")

return status_dict, latest_snapshot_user_generated, latest_snapshot_auto_generated, unstaged_code, unstaged_environment, unstaged_files
# Print out info for the latest snapshot (the most recent first, and state if autogenerated or by user)
if latest_snapshot_user_generated and not latest_snapshot_auto_generated:
self.cli_helper.echo("latest snapshot generated by the user: ")
self.cli_helper.echo(latest_snapshot_user_generated)
self.cli_helper.echo("no snapshot autogenerated by datmo")
elif latest_snapshot_auto_generated and not latest_snapshot_user_generated:
self.cli_helper.echo("latest snapshot autogenerated by datmo: ")
self.cli_helper.echo(latest_snapshot_auto_generated)
self.cli_helper.echo("no snapshot generated by the user")
elif not latest_snapshot_user_generated and not latest_snapshot_auto_generated:
self.cli_helper.echo("no snapshots created yet")
elif latest_snapshot_user_generated.created_at > latest_snapshot_auto_generated.created_at:
self.cli_helper.echo("latest snapshot generated by the user: ")
self.cli_helper.echo(latest_snapshot_user_generated)
self.cli_helper.echo("latest snapshot autogenerated by datmo: ")
self.cli_helper.echo(latest_snapshot_auto_generated)
elif latest_snapshot_user_generated.created_at < latest_snapshot_auto_generated.created_at:
self.cli_helper.echo("latest snapshot autogenerated by datmo: ")
self.cli_helper.echo(latest_snapshot_auto_generated)
self.cli_helper.echo("latest snapshot generated by the user: ")
self.cli_helper.echo(latest_snapshot_user_generated)

return status_dict, current_snapshot, latest_snapshot_user_generated, latest_snapshot_auto_generated, unstaged_code, unstaged_environment, unstaged_files

def cleanup(self):
# Prompt user to ensure they would like to remove datmo information along with environment and files folder
Expand Down
21 changes: 16 additions & 5 deletions datmo/cli/command/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def ls(self, **kwargs):
print_format = kwargs.get('format', "table")
download = kwargs.get('download', None)
download_path = kwargs.get('download_path', None)
current_snapshot_obj = self.snapshot_controller.current_snapshot()
current_snapshot_id = current_snapshot_obj.id if current_snapshot_obj else None
if show_all:
snapshot_objs = self.snapshot_controller.list(
session_id=session_id,
Expand All @@ -201,8 +203,11 @@ def ls(self, **kwargs):
snapshot_stats_printable = printable_object(snapshot_obj.stats)
snapshot_message = printable_object(snapshot_obj.message)
snapshot_label = printable_object(snapshot_obj.label)
printable_snapshot_id = snapshot_obj.id if current_snapshot_id is not None and \
snapshot_obj.id != current_snapshot_id\
else "(current) " + snapshot_obj.id
item_dict_list.append({
"id": snapshot_obj.id,
"id": printable_snapshot_id,
"created at": prettify_datetime(snapshot_obj.created_at),
"config": snapshot_config_printable,
"stats": snapshot_stats_printable,
Expand All @@ -222,8 +227,11 @@ def ls(self, **kwargs):
snapshot_stats_printable = printable_object(snapshot_obj.stats)
snapshot_message = printable_object(snapshot_obj.message)
snapshot_label = printable_object(snapshot_obj.label)
printable_snapshot_id = snapshot_obj.id if current_snapshot_id is not None and \
snapshot_obj.id != current_snapshot_id \
else "(current) " + snapshot_obj.id
item_dict_list.append({
"id": snapshot_obj.id,
"id": printable_snapshot_id,
"created at": prettify_datetime(snapshot_obj.created_at),
"config": snapshot_config_printable,
"stats": snapshot_stats_printable,
Expand Down Expand Up @@ -288,9 +296,12 @@ def diff(self, **kwargs):
if isinstance(value_2, dict): alldict.append(value_2)
allkey = set().union(*alldict)
for key in allkey:
key_value_1 = "%s: %s" % (key, value_1[key]) if value_1.get(key, None) else "N/A"
key_value_2 = "%s: %s" % (key, value_2[key]) if value_2.get(key, None) else "N/A"
table_data.append([attribute, key_value_1, "->", key_value_2])
key_value_1 = "%s: %s" % (key, value_1[key]) if value_1 != "N/A" and value_1.get(key, None) \
else "N/A"
key_value_2 = "%s: %s" % (key, value_2[key]) if value_2 != "N/A" and value_2.get(key, None) \
else "N/A"
table_data.append(
[attribute, key_value_1, "->", key_value_2])
else:
table_data.append([attribute, value_1, "->", value_2])
output = format_table(table_data)
Expand Down

0 comments on commit c278379

Please sign in to comment.