6 @contact: Debian FTPMaster <ftpmaster@debian.org>
7 @copyright: 2008 Mark Hymers <mhy@debian.org>
8 @license: GNU General Public License version 2 or later
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 ################################################################################
27 # <NCommander> mhy, how about "Now with 20% more monty python references"
29 ################################################################################
34 from singleton import Singleton
36 ################################################################################
38 default_config = "/etc/dak/dak.conf"
40 def which_conf_file(Cnf):
41 res = socket.gethostbyaddr(socket.gethostname())
42 if Cnf.get("Config::" + res[0] + "::DakConfig"):
43 return Cnf["Config::" + res[0] + "::DakConfig"]
47 class Config(Singleton):
49 A Config object is a singleton containing
50 information about the DAK configuration
52 def __init__(self, *args, **kwargs):
53 super(Config, self).__init__(*args, **kwargs)
58 self.Cnf = apt_pkg.newConfiguration()
60 apt_pkg.ReadConfigFileISC(self.Cnf, default_config)
62 # Check whether our dak.conf was the real one or
63 # just a pointer to our main one
64 res = socket.gethostbyaddr(socket.gethostname())
65 conffile = self.Cnf.get("Config::" + res[0] + "::DakConfig")
67 apt_pkg.ReadConfigFileISC(self.Cnf, conffile)
69 # Rebind some functions
71 self.get = self.Cnf.get
72 self.SubTree = self.Cnf.SubTree
73 self.ValueList = self.Cnf.ValueList
74 self.Find = self.Cnf.Find
75 self.FindB = self.Cnf.FindB
77 def _startup(self, *args, **kwargs):
80 def has_key(self, name):
81 return self.Cnf.has_key(name)
83 def __getitem__(self, name):
86 def __setitem__(self, name, value):
87 self.Cnf[name] = value