]> git.decadent.org.uk Git - dak.git/blob - daklib/config.py
bootstrap_bin working
[dak.git] / daklib / config.py
1 #!/usr/bin/env python
2
3 """
4 Config access class
5
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
9 """
10
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.
15
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.
20
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
24
25 ################################################################################
26
27 # <NCommander> mhy, how about "Now with 20% more monty python references"
28
29 ################################################################################
30
31 import apt_pkg
32 import socket
33
34 from singleton import Singleton
35
36 ################################################################################
37
38 #default_config = "/etc/dak/dak.conf"
39 default_config = "/home/stew/etc/dak/dak.conf"     #: default dak config, defines host properties
40
41 def which_conf_file(Cnf):
42     res = socket.gethostbyaddr(socket.gethostname())
43     if Cnf.get("Config::" + res[0] + "::DakConfig"):
44         return Cnf["Config::" + res[0] + "::DakConfig"]
45     else:
46         return default_config
47
48 class Config(Singleton):
49     """
50     A Config object is a singleton containing
51     information about the DAK configuration
52     """
53     def __init__(self, *args, **kwargs):
54         super(Config, self).__init__(*args, **kwargs)
55
56     def _readconf(self):
57         apt_pkg.init()
58
59         self.Cnf = apt_pkg.newConfiguration()
60
61         apt_pkg.ReadConfigFileISC(self.Cnf, default_config)
62
63         # Check whether our dak.conf was the real one or
64         # just a pointer to our main one
65         res = socket.gethostbyaddr(socket.gethostname())
66         conffile = self.Cnf.get("Config::" + res[0] + "::DakConfig")
67         if conffile:
68             apt_pkg.ReadConfigFileISC(self.Cnf, conffile)
69
70         # Rebind some functions
71         # TODO: Clean this up
72         self.get = self.Cnf.get
73         self.SubTree = self.Cnf.SubTree
74         self.ValueList = self.Cnf.ValueList
75         self.Find = self.Cnf.Find
76         self.FindB = self.Cnf.FindB
77
78     def _startup(self, *args, **kwargs):
79         self._readconf()
80
81     def has_key(self, name):
82         return self.Cnf.has_key(name)
83
84     def __getitem__(self, name):
85         return self.Cnf[name]
86
87     def __setitem__(self, name, value):
88         self.Cnf[name] = value