4 # Copyright (C) 2008 Mark Hymers <mhy@debian.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
20 ################################################################################
22 # <NCommander> mhy, how about "Now with 20% more monty python references"
24 ################################################################################
29 from Singleton import Singleton
31 ################################################################################
33 default_config = "/etc/dak/dak.conf"
35 def which_conf_file(Cnf):
36 res = socket.gethostbyaddr(socket.gethostname())
37 if Cnf.get("Config::" + res[0] + "::DakConfig"):
38 return Cnf["Config::" + res[0] + "::DakConfig"]
42 class Config(Singleton):
44 A Config object is a singleton containing
45 information about the DAK configuration
47 def __init__(self, *args, **kwargs):
48 super(Config, self).__init__(*args, **kwargs)
53 self.Cnf = apt_pkg.newConfiguration()
55 apt_pkg.ReadConfigFileISC(self.Cnf, default_config)
57 # Check whether our dak.conf was the real one or
58 # just a pointer to our main one
59 res = socket.gethostbyaddr(socket.gethostname())
60 conffile = self.Cnf.get("Config::" + res[0] + "::DakConfig")
62 apt_pkg.ReadConfigFileISC(self.Cnf, conffile)
64 # Rebind some functions
66 self.get = self.Cnf.get
67 self.SubTree = self.Cnf.SubTree
68 self.ValueList = self.Cnf.ValueList
70 def _startup(self, *args, **kwargs):
73 def __getitem__(self, name):
76 def GetDBConnString(self):
77 s = "dbname=%s" % self.Cnf["DB::Name"]
78 if self.Cnf["DB::Host"]:
79 s += " host=%s" % self.Cnf["DB::Host"]
80 if self.Cnf["DB::Port"] and self.Cnf["DB::Port"] != "-1":
81 s += " port=%s" % self.Cnf["DB::Port"]