Skip to content

Commit

Permalink
Merge pull request #168 from PDXCapstoneF/mab-fix-run-format-rebase
Browse files Browse the repository at this point in the history
Bring dialogue's run format in line with standard
  • Loading branch information
mbottini authored May 17, 2018
2 parents b34f716 + d83806d commit a542911
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 43 deletions.
80 changes: 45 additions & 35 deletions dialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
TEMPLATE_DATA = 'TemplateData'
RUN_LIST = 'RunList'
RUNLIST_ARGS = 'args'
TAG_ARG = 'Tag'
TAG_ARG = 'tag'
RUN_TEMPLATE_TYPE = 'template_type'

TEMPLATE_ARGS = 'args'
TEMPLATE_ANNO = 'annotations'
TEMPLATE_TYPES = 'types'
TEMPLATE_TRANS = 'translations'
TEMPLATE_DEFAULT = 'default_props'
TEMPLATE_DEFAULT = 'prop_options'


def write_json(filename, python_dict):
Expand Down Expand Up @@ -45,16 +45,11 @@ def print_dict(d):
# All functions take run_dict, runtype_dict as arguments so that they can be
# called homogenously from a dictionary in `dialogue`.

def print_all_runs(run_dict, runtype_dict):
for k, v in sorted(run_dict.items(), key=lambda x: x[0]):
print('\nTag {}\n'.format(k))
print_dict(v)

def tag_in_runlist(tag, run_list):
"""
Returns True if a Run with tag `tag` is in the list.
"""
return any(map(lambda run : run[RUNLIST_ARGS][TAG_ARG] == tag, run_list))
return any(map(lambda run : run[TAG_ARG] == tag, run_list))

def find(f, seq):
"""
Expand All @@ -64,7 +59,7 @@ def find(f, seq):
if f(item):
return item
def find_run_tag(tag, run_list):
return find(lambda run : run[RUNLIST_ARGS]['Tag'] == tag, run_list)
return find(lambda run : run[TAG_ARG] == tag, run_list)

# Level-one layer of dialogue. All functions take run_dict, template_dict as
# arguments so that they can be called homogeneously from a dictionary in
Expand All @@ -77,7 +72,8 @@ def print_all_runs(run_list, template_dict):
`template_dict`.
"""
for run in run_list:
print('\nTemplate Type: {}'.format(run[RUN_TEMPLATE_TYPE]))
print('\nTag: {}'.format(run[TAG_ARG]))
print('Template Type: {}'.format(run[RUN_TEMPLATE_TYPE]))
for arg in template_dict[run[RUN_TEMPLATE_TYPE]][RUNLIST_ARGS]:
print('{}: {}'.format(arg, run[RUNLIST_ARGS][arg]))
print()
Expand All @@ -98,6 +94,15 @@ def create_run(run_list, template_dict):
new_run[RUN_TEMPLATE_TYPE] = run_type
new_run[RUNLIST_ARGS] = {}

# Input the tag.
while True:
new_tag = input('Input a tag for the run. ')
if new_tag in [run[TAG_ARG] for run in run_list]:
print('Tag {} already exists in the run list!'.format(new_tag))
continue
new_run[TAG_ARG] = new_tag
break

# Input values.
for arg in template_dict[run_type][RUNLIST_ARGS]:
while True:
Expand All @@ -115,13 +120,16 @@ def create_run(run_list, template_dict):
break
except:
print('Invalid input.')
while True:
if input('Add run {} to list? '.format(new_tag)) in YES_CONSTS:
run_list.append(new_run)
print('Run {} added to list.'.format(new_tag))
return run_list, runtype_dict
else:
if input('Discard new run {}? '.format(new_tag)) in YES_CONSTS:
return run_list, runtype_dict

# Validate tag uniqueness.
while tag_in_runlist(new_run[RUNLIST_ARGS][TAG_ARG], run_list):
new_run[RUNLIST_ARGS][TAG_ARG] = input('Duplicate tag! Input a new tag. ')
run_list.append(new_run)
print('Run {} added to list.'.format(new_run[RUNLIST_ARGS][TAG_ARG]))
return (run_list, template_dict)
return run_list, template_dict

def create_runtype(run_list, template_dict):
new_template = {}
Expand Down Expand Up @@ -201,11 +209,11 @@ def create_runtype(run_list, template_dict):
def delete_run(run_list, template_dict):
print('Input the tag of the Run that you want to delete. Available tags')
print('are {}'.format(
' '.join(run[RUNLIST_ARGS]['Tag'] for run in run_list)))
' '.join(run[TAG_ARG] for run in run_list)))
delete_tag = input('-> ')

new_run_list = [run for run in run_list
if run[RUNLIST_ARGS]['Tag'] != delete_tag]
if run[TAG_ARG] != delete_tag]
if len(run_list) == len(new_run_list):
print('Tag {} does not exist.'.format(delete_tag))
else:
Expand All @@ -220,7 +228,7 @@ def delete_run(run_list, template_dict):
def copy_run(run_list, template_dict):
print('Input the tag of the Run that you want to copy. Available tags')
print('are {}'.format(
' '.join(run[RUNLIST_ARGS]['Tag'] for run in run_list)))
' '.join(run[TAG_ARG] for run in run_list)))
old_run_tag = input('-> ')

if old_run_tag in EXIT_CONSTS:
Expand All @@ -242,7 +250,7 @@ def copy_run(run_list, template_dict):
if tag_in_runlist(new_run_tag, run_list):
print('Tag {} already exists!'.format(new_run_tag))
else:
new_run[RUNLIST_ARGS]['Tag'] = new_run_tag
new_run[TAG_ARG] = new_run_tag
break

if input('Add run {} to RunList? '.format(new_run_tag)) in YES_CONSTS:
Expand All @@ -264,6 +272,17 @@ def edit_run(run_list, template_dict):
return run_list, template_dict
new_run = copy.deepcopy(old_run)

# Edit the name.
while True:
new_tag = input('Input a new tag name. Blank input keeps it the same. ')
if not new_tag:
break
if new_tag != old_run[TAG_ARG] and tag_in_runlist(new_tag, run_list):
print('Tag already exists! Input a new tag.')
else:
new_run[TAG_ARG] = new_tag
break

for arg in template_dict[new_run[RUN_TEMPLATE_TYPE]][TEMPLATE_ARGS]:
while True:
try:
Expand All @@ -282,28 +301,19 @@ def edit_run(run_list, template_dict):
except:
print('Invalid input.')

# Tag uniqueness validation.
while new_run[RUNLIST_ARGS]['Tag'] != old_run[RUNLIST_ARGS]['Tag'] and \
tag_in_runlist(new_run[RUNLIST_ARGS]['Tag'], run_list):
user_input = input('Tag already exists! Input a new tag! ')
if not user_input or user_input in HELP_CONSTS:
continue
if user_input in EXIT_CONSTS:
return run_list, template_dict
new_run[RUNLIST_ARGS]['Tag'] = user_input

if input('Are you sure you want to change run {}? '\
.format(old_run[RUNLIST_ARGS]['Tag'])) in YES_CONSTS:
.format(old_run[TAG_ARG])) in YES_CONSTS:
# Find the index of old_run and create a new list with new_run in its
# place.
for index, run in enumerate(run_list):
if run == old_run:
print('Run {} changed.'.format(old_run[RUNLIST_ARGS]['Tag']))
print('Run {} changed.'.format(old_run[TAG_ARG]))
return (run_list[:index] + [new_run] + run_list[index+1:],
template_dict)
print('Something terribly wrong has happened. Cancelled.')
else:
print('Edit of Run {} cancelled.'.format(old_run[RUNLIST_ARGS]['Tag']))
print('Edit of Run {} cancelled.'.format(old_run[TAG_ARG]))
return run_list, template_dict

def delete_runtype(run_list, template_dict):
Expand Down Expand Up @@ -351,7 +361,7 @@ def load_tate(run_list, template_dict):
def reorder_run(run_list, template_dict):
print('Select an index to reorder.')
for index, run in enumerate(run_list):
print('Index {}: Tag {}'.format(index, run[RUNLIST_ARGS]['Tag']))
print('Index {}: Tag {}'.format(index, run[TAG_ARG]))

new_list = run_list[:]
try:
Expand All @@ -367,10 +377,10 @@ def reorder_run(run_list, template_dict):
run = new_list.pop(old_index)
new_list.insert(new_index, run)
if input('Remove Tag {} from index {} and place it in {}? '\
.format(run[RUNLIST_ARGS]['Tag'], old_index, new_index))\
.format(run[TAG_ARG], old_index, new_index))\
in YES_CONSTS:
print('Run {} removed from index {} and placed in index {}.'\
.format(run[RUNLIST_ARGS]['Tag'], old_index, new_index))
.format(run[TAG_ARG], old_index, new_index))
return new_list, template_dict
except:
print('Invalid index.')
Expand Down
10 changes: 2 additions & 8 deletions example_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"TemplateData": {
"HBIR": {
"args": [
"Tag",
"Kit Version",
"JDK",
"RTSTART",
Expand All @@ -14,7 +13,6 @@
"T3"
],
"annotations" : {
"Tag" : "Name of the run",
"Kit Version" : "Version of SpecJBB",
"JDK" : "Version of the JVM that will run SpecJBB",
"RTSTART" : "What percentage of total output will we start at",
Expand All @@ -37,7 +35,6 @@
"specjbb.mapreducer.pool.size": 27
},
"types": {
"Tag": "string",
"Kit Version": "string",
"JDK": "string",
"RTSTART": "integer",
Expand All @@ -58,7 +55,6 @@
},
"HBIR_RT": {
"args": [
"Tag",
"Kit Version",
"JDK",
"RTSTART",
Expand All @@ -70,7 +66,6 @@
"T3"
],
"annotations" : {
"Tag" : "Name of the run",
"Kit Version" : "Version of SpecJBB",
"JDK" : "Version of the JVM that will run SpecJBB",
"RTSTART" : "What percentage of total output will we start at",
Expand All @@ -96,7 +91,6 @@
"specjbb.mapreducer.pool.size": 27
},
"types": {
"Tag": "string",
"Kit Version": "string",
"JDK": "string",
"RTSTART": "integer",
Expand All @@ -118,8 +112,8 @@
},
"RunList": [{
"template_type": "HBIR",
"tag": "TAG",
"args": {
"Tag": "TAG",
"Kit Version": "15",
"JDK": 7,
"RTSTART": "4",
Expand All @@ -133,8 +127,8 @@
},
{
"template_type": "HBIR_RT",
"tag" : "specjbb",
"args": {
"Tag" : "specjbb",
"Kit Version": "RC3",
"RTSTART" : 30,
"JDK": "jdk.8-u121",
Expand Down

0 comments on commit a542911

Please sign in to comment.