|
1 | 1 | import ConfigParser |
2 | | - |
3 | | -import clg |
4 | 2 | import os |
5 | 3 | import yaml |
6 | 4 |
|
| 5 | +import clg |
| 6 | +import yamlordereddictloader |
| 7 | + |
7 | 8 | from cli import exceptions |
8 | 9 | from cli import utils |
9 | 10 |
|
@@ -43,38 +44,41 @@ class SpecManager(object): |
43 | 44 |
|
44 | 45 | SPEC_EXTENSION = '.spec' |
45 | 46 |
|
46 | | - def __init__(self, config): |
47 | | - self.config = config |
| 47 | + @classmethod |
| 48 | + def parse_args(cls, module_name, config, args=None): |
| 49 | + """ |
| 50 | + Looks for all the specs for specified module |
| 51 | + and parses the commandline input arguments accordingly. |
48 | 52 |
|
49 | | - def get_specs(self, module_name): |
| 53 | + :param module_name: the module name: installer|provisioner|tester |
| 54 | + """ |
| 55 | + cmd = clg.CommandLine(cls._get_specs(module_name, config)) |
| 56 | + return cmd.parse(args) |
| 57 | + |
| 58 | + @classmethod |
| 59 | + def _get_specs(cls, module_name, config): |
50 | 60 | """ |
51 | 61 | Gets specs files as a dict from settings/<module_name> folder. |
52 | 62 | :param module_name: the module name: installer|provisioner|tester |
53 | 63 | """ |
54 | 64 | res = {} |
55 | | - for spec_file in self.__get_all_specs(subfolder=module_name): |
56 | | - spec = yaml.load(open(spec_file)) |
| 65 | + for spec_file in cls._get_all_specs(config, subfolder=module_name): |
| 66 | + spec = yaml.load(open(spec_file), |
| 67 | + Loader=yamlordereddictloader.Loader) |
57 | 68 | utils.dict_merge(res, spec) |
58 | 69 | return res |
59 | 70 |
|
60 | | - def parse_args(self, module_name, args=None): |
61 | | - """ |
62 | | - Looks for all the specs for specified module |
63 | | - and parses the commandline input arguments accordingly. |
64 | | - """ |
65 | | - cmd = clg.CommandLine(self.get_specs(module_name)) |
66 | | - return cmd.parse(args) |
67 | | - |
68 | | - def __get_all_specs(self, subfolder=None): |
| 71 | + @classmethod |
| 72 | + def _get_all_specs(cls, config, subfolder=None): |
69 | 73 | root_dir = utils.validate_settings_dir( |
70 | | - self.config.get('defaults', 'settings')) |
| 74 | + config.get('defaults', 'settings')) |
71 | 75 | if subfolder: |
72 | 76 | root_dir = os.path.join(root_dir, subfolder) |
73 | 77 |
|
74 | 78 | res = [] |
75 | 79 | for dirpath, _, filenames in os.walk(root_dir): |
76 | 80 | for filename in [f for f in filenames |
77 | | - if f.endswith(self.SPEC_EXTENSION)]: |
| 81 | + if f.endswith(cls.SPEC_EXTENSION)]: |
78 | 82 | res.append(os.path.join(dirpath, filename)) |
79 | 83 |
|
80 | 84 | return res |
|
0 commit comments