5 DEFAULT_MSG_CONF = "/etc/tic-core/message.conf"
6 DEFAULT_CONF = "/etc/tic-core/config.conf"
8 class ConfigMgr(object):
9 DEFAULT_MESSAGE = {'message': {
10 'repo_not_found': "The repository url cannot be found (%s)",
11 'xml_parse_error': "There was a problem parsing the %s, please check the file (%s)",
12 'yaml_parse_error': "There was a problem parsing the %s, please check the file (%s)",
13 'recipe_parse_error': "There was a problem parsing the recipe, please check the recipe file (%s)",
14 'package_not_exist': "The default package(%s) does not exist.",
15 'dependency_not_exist': "The %s needed by %s does not exist. should be checked for repository",
16 'server_error': "there was a problem servicing your request. please try again later" }
19 DEFAULT_TIC = {'setting': {
20 'tempdir': '/var/tmp/tic-core',
21 'cachedir': '/var/tmp/tic-core/cache',
22 'logdir': '/var/tmp/tic-core/log'},
26 'meta_prefix': "building-blocks",
27 'meta_prefix_root': "building-blocks-root-",
28 'meta_prefix_sub1': "building-blocks-sub1-",
29 'meta_pattern': "-(?P<meta>root|sub1|sub2)-(?P<pkgname>.+)",
30 'meta_sub1_pattern': "(?P<root>.+)-(?P<sub1>.+)",
31 'meta_sub2_pattern': "(?P<root>.+)-(?P<sub1>.+)-(?P<sub2>.+)",
32 'profile_pattern': "(?P<pkgname>.+)-profile_(?P<profile>[^-]+)-?(?P<extra>.+)?"}
37 def __new__(cls, *args, **kwargs):
39 cls._instance = super(ConfigMgr, cls).__new__(cls, *args, **kwargs)
44 for conf_path in [DEFAULT_CONF, DEFAULT_MSG_CONF]:
45 self._setConfig(conf_path)
48 for sec, vals in self.DEFAULT_TIC.iteritems():
49 setattr(self, sec, vals)
50 for sec, vals in self.DEFAULT_MESSAGE.iteritems():
51 setattr(self, sec, vals)
53 def _setConfig(self, conf):
54 configParser = ConfigParser.ConfigParser()
56 if os.path.exists(conf):
57 configParser.read(conf)
58 for section in configParser.sections():
59 for option in configParser.options(section):
61 opt_attr=getattr(self, section)
62 opt_attr[option]=configParser.get(section, option)
65 except Exception as e:
68 configmgr = ConfigMgr()
70 if __name__ == '__main__':
71 temp_dict = {'aaa': 'bbb'}
72 temp= temp_dict.get(temp_dict.get(None))
73 print(configmgr.setting['cachedir'])
74 print(configmgr.message['repo_not_found'])
75 print(configmgr.regularexp['meta_prefix'])
76 print(configmgr.server['port'])