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 "recipe_not_found": "The recipe URL cannot be found (%s)",
12 "xml_parse_error": "There was a problem parsing the %s, please check the file (%s)",
13 "yaml_parse_error": "There was a problem parsing the %s, please check the file (%s)",
14 "recipe_parse_error": "There was a problem parsing the recipe, please check the recipe file (%s)",
15 "recipe_convert_error": "There was a problem converting this recipe, please check the recipes",
16 "package_not_exist": "The default package(%s) does not exist.",
17 "dependency_not_exist": "The %s needed by %s does not exist. should be checked for repository",
18 "server_error": "there was a problem servicing your request. please try again later",
19 "recipe_repo_not_exist": "%s repository does not exist in in the recipe",
20 "default_recipe_use": "Use default recipe because there is no import data",
21 "no_package_to_install": "No packages to install. Please select a package to install",
22 "recipes_not_define": "Please define recipe for %s file creation"}
25 DEFAULT_TIC = {"setting": {
26 "tempdir": "/var/tmp/tic-core",
27 "cachedir": "/var/tmp/tic-core/cache",
28 "logdir": "/var/tmp/tic-core/log",
29 "default_recipe": "/etc/tic-core/recipe.yaml"},
33 "meta_prefix": "building-blocks",
34 "meta_prefix_root": "building-blocks-root-",
35 "meta_prefix_sub1": "building-blocks-sub1-",
36 "meta_pattern": "-(?P<meta>root|sub1|sub2|category)-(?P<pkgname>.+)",
37 "meta_sub1_pattern": "(?P<root>.+)-(?P<sub1>.+)",
38 "meta_sub2_pattern": "(?P<root>.+)-(?P<sub1>.+)-(?P<sub2>.+)",
39 "profile_pattern": "(?P<pkgname>.+)-profile_(?P<profile>[^-]+)-?(?P<extra>.+)?"}
44 def __new__(cls, *args, **kwargs):
46 cls._instance = super(ConfigMgr, cls).__new__(cls, *args, **kwargs)
51 for conf_path in [DEFAULT_CONF, DEFAULT_MSG_CONF]:
52 self._setConfig(conf_path)
55 for sec, vals in self.DEFAULT_TIC.iteritems():
56 setattr(self, sec, vals)
57 for sec, vals in self.DEFAULT_MESSAGE.iteritems():
58 setattr(self, sec, vals)
60 def _setConfig(self, conf):
61 configParser = ConfigParser.ConfigParser()
63 if os.path.exists(conf):
64 configParser.read(conf)
65 for section in configParser.sections():
66 for option in configParser.options(section):
68 opt_attr=getattr(self, section)
69 opt_attr[option]=configParser.get(section, option)
72 except Exception as e:
75 configmgr = ConfigMgr()
77 if __name__ == '__main__':
78 temp_dict = {'aaa': 'bbb'}
79 temp= temp_dict.get(temp_dict.get(None))
80 print(configmgr.setting['cachedir'])
81 print(configmgr.message['repo_not_found'])
82 print(configmgr.regularexp['meta_prefix'])
83 print(configmgr.server['port'])