My Project
yaml_controller.py
Go to the documentation of this file.
1 import sys
2 import os
3 import traceback
4 sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
5 
6 from yamlTools import YamlTools as yt
7 
8 results_path = os.path.dirname(os.path.realpath(__file__)) + "/../../../results/"
9 
10 def value_print(
11  parameter,
12  yaml,
13  time_description = "currently"
14 ):
15  try:
16  value = yaml.get_parameter(parameter)
17  print_dictionary = {'time_description': time_description, 'parameter': parameter, 'value': value, 'type': type(value)}
18  print("Value of \"%(parameter)s\" %(time_description)s: %(value)s with the type %(type)s." % print_dictionary)
19  except KeyError:
20  traceback.print_exc()
21  print("Check if you have loaded some parameters before calling this function.")
22 
23 
25  path_to_run,
26  parameter,
27  new_value
28 ):
29  yaml = yt()
30 
31  yaml.load_yaml_parameters(results_path, path_to_run)
32 
33  value_print(parameter, yaml, "before")
34  yaml.set_parameter(parameter, new_value)
35 
36  value_print(parameter, yaml, "after")
37 
38  yaml.save_yaml_parameters(results_path, path_to_run)
39 
40 
41 def run():
42  if(len(sys.argv) > 2):
43  change_one_parameter(sys.argv[1], sys.argv[2], sys.argv[3])
44  else:
45  print("Please provide a path to the run folder, one parameter to change and it's new value.")
46  quit()
47 
48 if __name__ == "__main__":
49  run()
def change_one_parameter(path_to_run, parameter, new_value)
def value_print(parameter, yaml, time_description="currently")