]>
git.ipfire.org Git - pakfire.git/blob - pakfire/config.py
2 ###############################################################################
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2011 Pakfire development team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
25 from ConfigParser
import ConfigParser
29 from constants
import *
32 def __init__(self
, type=None):
37 "logfile" : "/var/log/pakfire.log",
38 "source_download_url" : SOURCE_DOWNLOAD_URL
,
39 "local_build_repo_path" : LOCAL_BUILD_REPO_PATH
,
42 self
._config
_repos
= {}
48 # Read default configuration files
49 for file in self
.config_files
:
53 logging
.debug("Configuration:")
54 for k
, v
in self
._config
.items():
55 logging
.debug(" %s : %s" % (k
, v
))
57 logging
.debug("Loaded from files:")
59 logging
.debug(" %s" % f
)
61 def read(self
, filename
):
62 # If filename does not exist we return silently
63 if not filename
or not os
.path
.exists(filename
):
66 filename
= os
.path
.abspath(filename
)
68 # If the file was already loaded, we return silently, too
69 if filename
in self
._files
:
72 logging
.debug("Reading configuration file: %s" % filename
)
74 config
= ConfigParser()
77 # Read the main section from the file if any
78 if "main" in config
.sections():
79 for k
,v
in config
.items("main"):
81 config
.remove_section("main")
83 # Read distribution information from the file
84 if "distro" in config
.sections():
85 for k
,v
in config
.items("distro"):
87 config
.remove_section("distro")
89 # Read master settings from file
90 if "master" in config
.sections():
91 for k
,v
in config
.items("master"):
93 config
.remove_section("master")
95 # Read slave settings from file
96 if "slave" in config
.sections():
97 for k
,v
in config
.items("slave"):
99 config
.remove_section("slave")
101 # Read repository definitions
102 for section
in config
.sections():
103 if not self
._config
_repos
.has_key(section
):
104 self
._config
_repos
[section
] = {}
107 for option
in config
.options(section
):
108 options
[option
] = config
.get(section
, option
)
110 self
._config
_repos
[section
].update(options
)
112 self
._files
.append(filename
)
114 def get(self
, key
, default
=None):
115 return self
._config
.get(key
, default
)
117 def set(self
, key
, val
):
118 logging
.debug("Updating configuration parameter: %s = %s" % (key
, val
))
119 self
._config
[key
] = val
121 def update(self
, values
):
123 This function takes a dictionary which configuration
124 parameters and applies them to the configuration.
126 for key
, val
in values
.items():
130 return self
._config
_repos
.items()
133 def config_files(self
):
136 if self
.type == "builder":
139 while not path
== "/":
140 _path
= os
.path
.join(path
, "config")
141 if os
.path
.exists(_path
):
145 path
= os
.path
.dirname(path
)
148 files
.append(os
.path
.join(_path
, "pakfire.conf"))
149 files
.append(os
.path
.join(_path
, "default.conf"))
151 # Remove non-existant files
153 if not os
.path
.exists(f
):
157 # Return system configuration files
158 files
+= [CONFIG_FILE
]
159 files
+= [os
.path
.join(CONFIG_DIR
, f
) for f
in os
.listdir(CONFIG_DIR
)]
166 Return the architecture of the host we are running on.
171 def supported_arches(self
):
173 "x86_64" : [ "x86_64", ],
174 "i686" : [ "i686", "x86_64", ],
175 "i586" : [ "i586", "i686", "x86_64", ],
176 "i486" : [ "i486", "i586", "i686", "x86_64", ],
179 for host
, can_be_built
in host_arches
.items():
180 if self
.host_arch
in can_be_built
:
183 def host_supports_arch(self
, arch
):
185 Check if this host can build for the target architecture "arch".
187 return arch
in self
.supported_arches