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 ################################################################################
35 ################################################################################
37 default_config = "/etc/dak/dak.conf" #: default dak config, defines host properties
39 # suppress some deprecation warnings in squeeze related to apt_pkg
42 warnings.filterwarnings('ignore', \
43 "Attribute '.*' of the 'apt_pkg\.Configuration' object is deprecated, use '.*' instead\.", \
45 warnings.filterwarnings('ignore', \
46 "apt_pkg\.newConfiguration\(\) is deprecated\. Use apt_pkg\.Configuration\(\) instead\.", \
49 def which_conf_file():
50 return os.getenv("DAK_CONFIG", default_config)
54 A Config object is a singleton containing
55 information about the DAK configuration
60 def __init__(self, *args, **kwargs):
61 self.__dict__ = self.__shared_state
63 if not getattr(self, 'initialised', False):
64 self.initialised = True
66 self._setup_routines()
71 self.Cnf = apt_pkg.newConfiguration()
73 apt_pkg.ReadConfigFileISC(self.Cnf, which_conf_file())
75 # Check whether our dak.conf was the real one or
76 # just a pointer to our main one
77 res = socket.gethostbyaddr(socket.gethostname())
78 conffile = self.Cnf.get("Config::" + res[0] + "::DakConfig")
80 apt_pkg.ReadConfigFileISC(self.Cnf, conffile)
82 # Rebind some functions
84 self.get = self.Cnf.get
85 self.SubTree = self.Cnf.SubTree
86 self.ValueList = self.Cnf.ValueList
87 self.Find = self.Cnf.Find
88 self.FindB = self.Cnf.FindB
90 def has_key(self, name):
91 return self.Cnf.has_key(name)
93 def __getitem__(self, name):
96 def __setitem__(self, name, value):
97 self.Cnf[name] = value
100 def get_db_value(name, default=None, rettype=None):
101 from daklib.dbconn import DBConfig, DBConn, NoResultFound
103 res = DBConn().session().query(DBConfig).filter(DBConfig.name == name).one()
104 except NoResultFound:
108 return rettype(res.value)
112 def _setup_routines(self):
114 This routine is the canonical list of which fields need to exist in
115 the config table. If your dak instance is to work, we suggest reading it
117 Of course, what the values do is another matter
119 for field in [('db_revision', None, int),
120 ('defaultsuitename', 'unstable', str),
121 ('signingkeyids', '', str),
122 ('exportpath', '', str)
124 setattr(self, 'get_%s' % field[0], lambda s=None, x=field[0], y=field[1], z=field[2]: self.get_db_value(x, y, z))
125 setattr(Config, '%s' % field[0], property(fget=getattr(self, 'get_%s' % field[0])))
127 def get_defaultsuite(self):
128 from daklib.dbconn import get_suite
129 suitename = self.defaultsuitename
133 return get_suite(suitename)
135 defaultsuite = property(get_defaultsuite)