2 * config - zavai configuration
4 * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 public string version { get; set; }
26 public string homedir { get; set; }
27 public string icondir { get; set; }
28 public int min_button_height { get; set; }
34 homedir = GLib.Environment.get_home_dir() + "/.zavai";
36 min_button_height = 80;
40 def _get_homedir(self):
41 res = self.get("global", "home")
43 res = os.path.expanduser("~/.zavai")
44 if not os.path.isdir(res):
45 zavai.info("Creating directory", res)
53 import ConfigParser, StringIO
55 def read_config(rootDir = None, defaults = None, nick="octofuss"):
57 Read octofuss configuration, returning a ConfigParser object
60 rootDir = os.environ.get(nick.upper() + "_CONFDIR", "/etc/" + nick)
63 if os.path.exists(path):
66 # Start with the main config file
67 trytouse(os.path.join(rootDir, nick + ".conf"))
69 # Add snippets found in rc.d style directory
70 subdir = os.path.join(rootDir, nick + ".conf.d")
71 if os.path.isdir(subdir):
72 for file in sorted(os.listdir(subdir)):
73 if file.startswith('#'): continue
74 if file.startswith('.'): continue
75 if file.endswith('~'): continue
76 if file.endswith('.bak'): continue
77 trytouse(os.path.join(subdir, file))
79 config = ConfigParser.ConfigParser()
81 infile = StringIO.StringIO(defaults)
82 config.readfp(infile, "defaults")
90 self.conf = zavai.read_config(nick="zavai")
92 def get(self, section, name, default=None):
93 if self.conf.has_section(section):
94 if self.conf.has_option(section, name):
95 return self.conf.get(section, name)
98 homedir = property(_get_homedir)
101 Config config = null;