From de22c168da68b8a6878b08e7c542d9fc2925dcc9 Mon Sep 17 00:00:00 2001 From: lenhattu Date: Mon, 16 Apr 2018 20:38:05 -0700 Subject: [PATCH 1/2] update gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 97f6f30..a7cf305 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,9 @@ ENV/ # mypy .mypy_cache/ + +# PyCharm project settings +.idea + +# MacOS auto-generated +.DS_Store \ No newline at end of file From 4f90099dfe877aa03bf9af17679dbd10d75cabb6 Mon Sep 17 00:00:00 2001 From: lenhattu Date: Tue, 17 Apr 2018 09:24:09 -0700 Subject: [PATCH 2/2] reformat code --- .travis.yml | 4 +- dialogue.py | 28 ++++++++---- example_config.json | 42 +++++++++--------- main.py => mainCLI.py | 13 +++--- runtype_options.json | 100 +++++++++++++++++++++--------------------- 5 files changed, 101 insertions(+), 86 deletions(-) rename main.py => mainCLI.py (94%) diff --git a/.travis.yml b/.travis.yml index 5061321..d52f732 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,12 +13,12 @@ install: - pipenv install --dev script: - python -m unittest discover - - python main.py -h + - python mainCLI.py -h before_deploy: - pipenv uninstall --all # clean out any dev dependencies - pipenv install # only add what we need - pip install pyinstaller # install pyinstaller - - pyinstaller --onefile main.py # make our one-file executable + - pyinstaller --onefile mainCLI.py # make our one-file executable deploy: provider: releases api_key: ${GITHUB_OAUTH_TOKEN} diff --git a/dialogue.py b/dialogue.py index fad706a..329c93d 100644 --- a/dialogue.py +++ b/dialogue.py @@ -7,6 +7,7 @@ import json + def write_json(filename, python_dict): """ Serialize python_dict (dictionary) to filename (text file). @@ -16,6 +17,7 @@ def write_json(filename, python_dict): with open(filename, 'w') as f: json.dump(python_dict, f, indent=4) + def read_json(filename): """ Deserializes json formatted string from filename (text file) as a dictionary. @@ -24,6 +26,7 @@ def read_json(filename): with open(filename) as f: return json.load(f) + def create_run_dict(runtype, *args): """ Returns a dictionary of a run-type option object deserialized @@ -41,6 +44,7 @@ def create_run_dict(runtype, *args): return return_dict return {} + def create_run_dict_list(runtype, args): """ Returns a dictionary of run-type option objects. @@ -48,6 +52,7 @@ def create_run_dict_list(runtype, args): """ return create_run_dict(runtype, *args) + def create_run_sh_invocation(run_dict): """ Builds a string to be used to invoke the `run.sh` script in ~/workloads. The @@ -78,6 +83,7 @@ def execute_run(run_dict): return True return False + def execute_runs(run_dict_list): """ A wrapper for `execute_run(...)`, which is invoked repeatedly for each set @@ -87,18 +93,13 @@ def execute_runs(run_dict_list): return [execute_run(run_dict) for run_dict in run_dict_list] - - - - - - # Utility functions. def print_dict(d): for key, value in sorted(d.items(), key=lambda x : x[0]): print("{}: {}".format(key, value)) + # Level-one layer of dialogue. def print_all_runs(run_dict, runtype_dict): @@ -106,6 +107,7 @@ def print_all_runs(run_dict, runtype_dict): print('Run {}'.format(k)) print_dict(v) + def create_run(run_dict, runtype_dict): run_name = input('Input a name for the run. ') if run_name in run_dict: @@ -122,6 +124,7 @@ def create_run(run_dict, runtype_dict): return run_dict[run_name] = create_run_dialogue(runtype_dict[run_type]) + def create_runtype(run_dict, runtype_dict): option_set = set() user_input = input('Input a name for the runtype. ') @@ -140,6 +143,7 @@ def create_runtype(run_dict, runtype_dict): if runtype_name.lower() not in ['q', 'quit']: runtype_dict[runtype_name] = list(option_set) + def delete_run(run_dict, runtype_dict): try: print('Input the tag of the run you want to delete.') @@ -153,6 +157,7 @@ def delete_run(run_dict, runtype_dict): return print('Run deleted.') + def copy_run(run_dict, runtype_dict): try: print('Input the tag of the run you want to copy.') @@ -166,6 +171,7 @@ def copy_run(run_dict, runtype_dict): print('Unable to copy tag {}.'.format(old_run)) print('Run copied to {}.'.format(new_run)) + def edit_run(run_dict, runtype_dict): try: print('Input the tag of the run you want to edit.') @@ -178,6 +184,7 @@ def edit_run(run_dict, runtype_dict): return print('Run edited.') + def save_runlist(run_dict, runtype_dict): filename = input('Input a filename to save the RunDict. ') try: @@ -187,6 +194,7 @@ def save_runlist(run_dict, runtype_dict): return print('Saved to {}'.format(filename)) + def load_runlist(run_dict, runtype_dict): filename = input('Input a filename to load a RunDict from. ') try: @@ -196,6 +204,7 @@ def load_runlist(run_dict, runtype_dict): return print('RunDict loaded from {}'.format(filename)) + def new_runlist(run_dict, runtype_dict): user_input = input('Are you sure? This will remove all runs from the RunDict!') if user_input.lower() in ['y', 'yes']: @@ -204,15 +213,18 @@ def new_runlist(run_dict, runtype_dict): else: print('RunDict has not been modified.') + def error(run_dict, runtype_dict): print('Invalid input.') - + + def create_run_dialogue(arg_list): new_run = {} for arg in arg_list: new_run[arg] = input("Input value for {}: ".format(arg)) return new_run + def edit_run_dialogue(old_run): new_run = {} for key, value in sorted(old_run.items(), key=lambda x : x[0]): @@ -220,6 +232,7 @@ def edit_run_dialogue(old_run): key, value)) return new_run + def dialogue(): """ A dialogue function for creating a RunDict. @@ -280,4 +293,3 @@ def dialogue(): if user_input.lower() not in ['q', 'quit']: function_dict.get(user_input, error)(run_dict, runtype_dict) print('Exiting.') - diff --git a/example_config.json b/example_config.json index afdae73..8ccedc7 100644 --- a/example_config.json +++ b/example_config.json @@ -1,23 +1,23 @@ { - "specjbb": { - "run_type": "LOADLEVEL", - "kit_version": "RC3", - "tag": "Run-Identifier", - "jdk": "jdk.8-u121", - "rt_start": 30, - "duration": 60, - "jvm_options": [ - "-Xms29g", - "-Xmx29g", - "-Xmn27g", - "-XX:ParallelGCThreads=48" - ], - "numa_node": 4, - "data": "NONE", - "t": [ - 154, - 45, - 23 - ] - } + "specjbb": { + "run_type": "LOADLEVEL", + "kit_version": "RC3", + "tag": "Run-Identifier", + "jdk": "jdk.8-u121", + "rt_start": 30, + "duration": 60, + "jvm_options": [ + "-Xms29g", + "-Xmx29g", + "-Xmn27g", + "-XX:ParallelGCThreads=48" + ], + "numa_node": 4, + "data": "NONE", + "t": [ + 154, + 45, + 23 + ] + } } diff --git a/main.py b/mainCLI.py similarity index 94% rename from main.py rename to mainCLI.py index c39593e..1ae1b85 100644 --- a/main.py +++ b/mainCLI.py @@ -1,10 +1,10 @@ """SPECtate. Usage: - main.py run [--props ] - main.py (-h | --help) - main.py --version - main.py dialogue + mainCLI.py run [--props ] + mainCLI.py (-h | --help) + mainCLI.py --version + mainCLI.py dialogue """ # library imports import json @@ -17,6 +17,7 @@ # source imports import dialogue + def to_list(s): if s['run_type'].lower() in ["hbir", "hbir_rt"]: return [ @@ -48,6 +49,7 @@ def to_list(s): s["t"][2], # t3 ] + def do_run(arguments): """ Does a run using scripts/run.sh from the provided property template and configuration. @@ -60,11 +62,11 @@ def do_run(arguments): cwd=os.path.join(os.path.dirname(__file__), 'scripts') ) + def do_dialogue(arguments): dialogue.dialogue() - # dictionary of runnables # these are functions that take arguments from the # command line and do something with them. @@ -73,6 +75,7 @@ def do_dialogue(arguments): 'dialogue' : do_dialogue } + if __name__ == "__main__": arguments = docopt(__doc__, version='SPECtate v0.1') diff --git a/runtype_options.json b/runtype_options.json index 919c9d3..eb325c1 100644 --- a/runtype_options.json +++ b/runtype_options.json @@ -1,54 +1,54 @@ { - "HBIR" : [ - "Kit Version", - "Tag", - "JDK", - "RTSTART", - "JVM Options", - "NUMA Nodes", - "Data Collection", - "T1", - "T2", - "T3" - ], - "HBIR_RT" : [ - "Kit Version", - "Tag", - "JDK", - "RTSTART", - "JVM Options", - "NUMA Nodes", - "Data Collection", - "T1", - "T2", - "T3" - ], - "PRESET" : [ - "kitVersion", - "tag", - "JDK", - "TXrate", - "Duration", - "JVMoptions", - "NUMA_Node", - "Data Collection", - "T1", - "T2", - "T3" - ], - "LOADLEVEL" : [ - "kitVersion", - "Tag", - "JDK", - "TXrate", - "Duration", - "JVMoptions", - "NUMA_Node", - "Data Collection", - "T1", - "T2", - "T3" - ] + "HBIR": [ + "Kit Version", + "Tag", + "JDK", + "RTSTART", + "JVM Options", + "NUMA Nodes", + "Data Collection", + "T1", + "T2", + "T3" + ], + "HBIR_RT": [ + "Kit Version", + "Tag", + "JDK", + "RTSTART", + "JVM Options", + "NUMA Nodes", + "Data Collection", + "T1", + "T2", + "T3" + ], + "PRESET": [ + "kitVersion", + "tag", + "JDK", + "TXrate", + "Duration", + "JVMoptions", + "NUMA_Node", + "Data Collection", + "T1", + "T2", + "T3" + ], + "LOADLEVEL": [ + "kitVersion", + "Tag", + "JDK", + "TXrate", + "Duration", + "JVMoptions", + "NUMA_Node", + "Data Collection", + "T1", + "T2", + "T3" + ] }