/* * config - zavai configuration * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ namespace zavai { public class Config { public string version { get; set; } public string homedir { get; set; } public string icondir { get; set; } public int min_button_height { get; set; } public Config() { // Set defaults version = "0.1"; homedir = "/root/.zavai"; icondir = "./icons"; min_button_height = 80; } /* def _get_homedir(self): res = self.get("global", "home") if res is None: res = os.path.expanduser("~/.zavai") if not os.path.isdir(res): zavai.info("Creating directory", res) os.makedirs(res) return res */ } /* import os import ConfigParser, StringIO def read_config(rootDir = None, defaults = None, nick="octofuss"): """ Read octofuss configuration, returning a ConfigParser object """ if rootDir == None: rootDir = os.environ.get(nick.upper() + "_CONFDIR", "/etc/" + nick) files = [] def trytouse(path): if os.path.exists(path): files.append(path) # Start with the main config file trytouse(os.path.join(rootDir, nick + ".conf")) # Add snippets found in rc.d style directory subdir = os.path.join(rootDir, nick + ".conf.d") if os.path.isdir(subdir): for file in sorted(os.listdir(subdir)): if file.startswith('#'): continue if file.startswith('.'): continue if file.endswith('~'): continue if file.endswith('.bak'): continue trytouse(os.path.join(subdir, file)) config = ConfigParser.ConfigParser() if defaults != None: infile = StringIO.StringIO(defaults) config.readfp(infile, "defaults") config.read(files) return config import os.path import zavai class Config: def __init__(self): self.conf = zavai.read_config(nick="zavai") def get(self, section, name, default=None): if self.conf.has_section(section): if self.conf.has_option(section, name): return self.conf.get(section, name) return None homedir = property(_get_homedir) */ Config config = null; }