Skip to content

Commit

Permalink
Merge pull request #19 from diggyk/master
Browse files Browse the repository at this point in the history
CLI output fixes
  • Loading branch information
jathanism committed Jun 23, 2015
2 parents ca02731 + 733b608 commit 9b3370f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
46 changes: 37 additions & 9 deletions bin/hermes
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,14 @@ def list_host_labors(args):
)

labors = response.json()["labors"]
total_labors = response.json()["totalLabors"]

response = request_get("/api/v1/fates?limit=all&expand=eventtypes")
fates = response.json()["fates"]

print "OPEN LABORS FOR {} (up to {}):".format(args.hostname, args.limit)
print "OPEN LABORS FOR {} ({} of {}):".format(
args.hostname, len(labors), total_labors
)
for labor in labors:
print_labor(labor, fates)

Expand Down Expand Up @@ -597,53 +600,78 @@ def show_quest(args):

max_width = 0
remaining = []
remaining_types = {}
completed = []
for labor in quest["labors"]:
if len(labor["host"]["hostname"]) > max_width:
max_width = len(labor["host"]["hostname"])

if labor["completionTime"] is None:
remaining.append(labor)
type_key = "{} {}".format(
labor["creationEvent"]["eventType"]["category"],
labor["creationEvent"]["eventType"]["state"],
)
if type_key in remaining_types:
remaining_types[type_key] += 1
else:
remaining_types[type_key] = 1
else:
completed.append(labor)

if not args.list_only:
print "QUEST {}:".format(args.quest_id)
embark_time = parser.parse(quest["embarkTime"])
embark_time = embark_time.replace(tzinfo=tz.tzutc())
embark_time = embark_time.astimezone(tz.tzlocal())
print "{} by {}.\n\tEmbarked on {}".format(
quest["description"], quest["creator"], embark_time
print "\nQUEST {}: Embarked on {} by {}".format(
args.quest_id,
embark_time,
quest["creator"],
)
if quest["targetTime"]:
target_time = parser.parse(quest["targetTime"])
target_time = target_time.replace(tzinfo=tz.tzutc())
target_time = target_time.astimezone(tz.tzlocal())
print"\tTarget Completion: {}".format(target_time)

print "\n\"{}\"\n".format(
textwrap.fill(
quest["description"],
width=76, subsequent_indent=" "
)
)

print "\tLABORS:"
if args.all or args.completed_only:
for labor in completed:
completion_time = parser.parse(labor["completionTime"])
completion_time = completion_time.replace(tzinfo=tz.tzutc())
completion_time = completion_time.astimezone(tz.tzlocal())
print "{} achieved {} {} on {}".format(
labor["host"]["hostname"].rjust(max_width + 4),
print "\t{} achieved {} {} on {}".format(
labor["host"]["hostname"].rjust(max_width),
labor["creationEvent"]["eventType"]["category"],
labor["creationEvent"]["eventType"]["state"],
completion_time
)
if not args.completed_only:
for labor in remaining:
print "{} must achieve {} {}".format(
labor["host"]["hostname"].rjust(max_width + 4),
print "\t{} is currently {} {}".format(
labor["host"]["hostname"].rjust(max_width),
labor["creationEvent"]["eventType"]["category"],
labor["creationEvent"]["eventType"]["state"]
)

total_labors = len(quest["labors"])
labors_remaining = len(remaining)
labors_completed = len(completed)
print "{:.2%} complete. {} total labors. {} remain open.\n".format(
if labors_remaining:
print "\n\tOPEN LABORS BY TYPE:"
for type in remaining_types.iterkeys():
print "\t\t{}: {}".format(
type,
remaining_types[type]
)
print "\n\t{:.2%} complete. {} total labors. {} remain open.\n".format(
labors_completed/total_labors,
total_labors,
labors_remaining
Expand Down
2 changes: 1 addition & 1 deletion hermes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.26"
__version__ = "0.1.28"

0 comments on commit 9b3370f

Please sign in to comment.