Merge branch 'master' into gregoa
[gregoa/zavai.git] / zavai / config.py
1 import os.path
2 import zavai
3
4 class Config:
5     def __init__(self):
6         self.conf = zavai.read_config(nick="zavai")
7
8     def get(self, section, name, default=None):
9         if self.conf.has_section(section):
10             if self.conf.has_option(section, name):
11                 return self.conf.get(section, name)
12         return None
13
14     def _get_homedir(self):
15         res = self.get("global", "home")
16         if res is None:
17             res = os.path.expanduser("~/.zavai")
18         if not os.path.isdir(res):
19             zavai.info("Creating directory", res)
20             os.makedirs(res)
21         return res
22
23     homedir = property(_get_homedir)