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 protected Lua.LuaVM lua;
26 protected weak string get_string(string name)
29 weak string res = lua.to_string(-1);
33 protected void set_string(string name, string? val)
41 protected weak int get_int(string name)
44 int res = lua.to_integer(-1);
48 protected void set_int(string name, int val)
50 lua.push_integer(val);
56 get { return get_string("version"); }
57 set { set_string("version", value); }
59 // "phone" or "laptop"
62 get { return get_string("profile"); }
63 set { set_string("profile", value); }
67 get { return get_string("homedir"); }
68 set { set_string("homedir", value); }
72 get { return get_string("icondir"); }
73 set { set_string("icondir", value); }
75 public int min_button_height
77 get { return get_int("min_button_height"); }
78 set { set_int("min_button_height", value); }
80 public string gprs_apn
82 get { return get_string("gprs_apn"); }
83 set { set_string("gprs_apn", value); }
85 public string gprs_user
87 get { return get_string("gprs_user"); }
88 set { set_string("gprs_user", value); }
90 public string gprs_pass
92 get { return get_string("gprs_pass"); }
93 set { set_string("gprs_pass", value); }
95 public int backlight_max
100 private string _argv0;
101 public string argv0 {
102 get { return _argv0; }
103 set { _argv0 = value; }
108 lua = new Lua.LuaVM();
114 homedir = GLib.Environment.get_home_dir() + "/.zavai";
115 icondir = GLib.Environment.get_variable("ZAVAI_ICONDIR");
117 icondir = "/usr/share/zavai/icons";
118 min_button_height = 80;
119 gprs_apn = "general.t-mobile.uk";
125 if (lua.do_file(homedir + "/config"))
127 zavai.log.error("Failed to parse " + homedir + "/config: " + lua.to_string(-1));
132 def _get_homedir(self):
133 res = self.get("global", "home")
135 res = os.path.expanduser("~/.zavai")
136 if not os.path.isdir(res):
137 zavai.info("Creating directory", res)
145 import ConfigParser, StringIO
147 def read_config(rootDir = None, defaults = None, nick="octofuss"):
149 Read octofuss configuration, returning a ConfigParser object
152 rootDir = os.environ.get(nick.upper() + "_CONFDIR", "/etc/" + nick)
155 if os.path.exists(path):
158 # Start with the main config file
159 trytouse(os.path.join(rootDir, nick + ".conf"))
161 # Add snippets found in rc.d style directory
162 subdir = os.path.join(rootDir, nick + ".conf.d")
163 if os.path.isdir(subdir):
164 for file in sorted(os.listdir(subdir)):
165 if file.startswith('#'): continue
166 if file.startswith('.'): continue
167 if file.endswith('~'): continue
168 if file.endswith('.bak'): continue
169 trytouse(os.path.join(subdir, file))
171 config = ConfigParser.ConfigParser()
173 infile = StringIO.StringIO(defaults)
174 config.readfp(infile, "defaults")
182 self.conf = zavai.read_config(nick="zavai")
184 def get(self, section, name, default=None):
185 if self.conf.has_section(section):
186 if self.conf.has_option(section, name):
187 return self.conf.get(section, name)
190 homedir = property(_get_homedir)
193 public Config config = null;