Exemple #1
0
def parse_job(args):
    """Loads YAML file, adds any parsed arguments"""
    with open(args.script, 'r') as fin:
        result = yaml.safe_load(fin)

    for arg in args.override:
        try:
            key, value = arg.split('=')
            override(result, key, yaml.safe_load(value))
        except (ValueError, yaml.YAMLError):
            print('[amaltheia] Ignoring option {}'.format(arg))

    config.variables = {}
    for var in args.variables:
        try:
            key, value = var.split('=')
            config.variables[key] = yaml.safe_load(value)
        except (ValueError, yaml.YAMLError):
            print('[amaltheia] Ignoring variable {}'.format(var))

    for var_name in result.get('requires', []):
        if var_name not in config.variables:
            print('[amaltheia] Missing required variable {} for {}'.format(
                var_name, args.script))
            sys.exit(-1)

    return result
Exemple #2
0
 def test_simple(self):
     x = {'a': 'b'}
     override(x, 'a', 'c')
     assert x == {'a': 'c'}
Exemple #3
0
 def test_dict_key(self):
     x = {'a': 'b'}
     override(x, '[a]', 'c')
     assert x == {'a': 'c'}
Exemple #4
0
 def test_list_out_of_bounds(self):
     x = [['a']]
     override(x, '[0][2]', 'b')
     assert x == [['a']]
Exemple #5
0
 def test_list_in_list(self):
     x = [['a']]
     override(x, '[0][0]', 'b')
     assert x == [['b']]
Exemple #6
0
 def test_list(self):
     x = {'a': {'b': ['c', {'d': 'e'}]}}
     override(x, 'a.b[1].d', 'f')
     assert x == {'a': {'b': ['c', {'d': 'f'}]}}
Exemple #7
0
 def test_dict(self):
     x = {'a': {'b': 'c'}}
     override(x, 'a.b', 'd')
     assert x == {'a': {'b': 'd'}}