]> git.ipfire.org Git - pakfire.git/blob - pakfire/distro.py
Bump version 0.9.9.
[pakfire.git] / pakfire / distro.py
1 #!/usr/bin/python
2 ###############################################################################
3 # #
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2011 Pakfire development team #
6 # #
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. #
11 # #
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. #
16 # #
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/>. #
19 # #
20 ###############################################################################
21
22 import logging
23 import os
24 import re
25
26 from errors import ConfigError
27 from repository import Repositories
28
29 class Distribution(object):
30 def __init__(self, pakfire, distro_config=None):
31 self.pakfire = pakfire
32
33 self._data = {
34 "arch" : self.config.host_arch,
35 "name" : "unknown",
36 "slogan" : "---",
37 "vendor" : "unknown",
38 "version" : "0.0",
39 }
40
41 # Inherit configuration from Pakfire configuration.
42 self.update(self.pakfire.config._distro)
43
44 # Update my configuration from the constructor.
45 self.update(distro_config)
46
47 # Dump all data
48 self.dump()
49
50 @property
51 def config(self):
52 return self.pakfire.config
53
54 def dump(self):
55 logging.debug("Distribution configuration:")
56
57 attrs = ("name", "version", "release", "sname", "dist", "vendor",
58 "arch", "machine", "source_dl",)
59
60 for attr in attrs:
61 logging.debug(" %s : %s" % (attr, getattr(self, attr)))
62
63 def update(self, config):
64 if not config:
65 return
66
67 # Exceptional handling for arch.
68 if config.has_key("arch"):
69 self.arch = config["arch"]
70 del config["arch"]
71
72 self._data.update(config)
73
74 @property
75 def name(self):
76 return self._data.get("name")
77
78 @property
79 def version(self):
80 return self._data.get("version")
81
82 @property
83 def release(self):
84 m = re.match(r"^([0-9]+)\..*", self.version)
85
86 return m.group(1)
87
88 @property
89 def sname(self):
90 return self.name.strip().lower()
91
92 @property
93 def slogan(self):
94 return self._data.get("slogan")
95
96 @property
97 def vendor(self):
98 return self._data.get("vendor")
99
100 @property
101 def maintainer(self):
102 return self._data.get("maintainer")
103
104 def get_arch(self):
105 return self._data.get("arch") or self.config.host_arch
106
107 def set_arch(self, arch):
108 # XXX check if we are allowed to set this arch
109 if not arch:
110 return
111
112 self._data["arch"] = arch
113
114 arch = property(get_arch, set_arch)
115
116 @property
117 def dist(self):
118 return self.sname[:2] + self.release
119
120 @property
121 def machine(self):
122 vendor = self.vendor.split()[0]
123
124 return "%s-%s-linux-gnu" % (self.arch, vendor.lower())
125
126 @property
127 def buildtarget(self):
128 return self.machine.replace("-gnu", "")
129
130 @property
131 def source_dl(self):
132 return self._data.get("source_dl", None)
133
134 @property
135 def environ(self):
136 """
137 An attribute that adds some environment variables to the
138 chroot environment.
139 """
140 env = {
141 "DISTRO_NAME" : self.name,
142 "DISTRO_SNAME" : self.sname,
143 "DISTRO_VERSION" : self.version,
144 "DISTRO_RELEASE" : self.release,
145 "DISTRO_DISTTAG" : self.dist,
146 "DISTRO_ARCH" : self.arch,
147 "DISTRO_MACHINE" : self.machine,
148 "DISTRO_BUILDTARGET" : self.buildtarget,
149 "DISTRO_MAINTAINER" : self.maintainer,
150 "DISTRO_VENDOR" : self.vendor,
151 "DISTRO_SLOGAN" : self.slogan,
152 }
153
154 return env
155
156 @property
157 def info(self):
158 info = {}
159
160 for k, v in self.environ.items():
161 info[k.lower()] = v
162
163 return info
164
165 @property
166 def personality(self):
167 """
168 Return the personality of the target system.
169
170 If host and target system are of the same architecture, we return
171 None to skip the setting of the personality in the build chroot.
172 """
173
174 if self.arch == self.config.host_arch:
175 return None
176
177 arch2personality = {
178 "x86_64" : "linux64",
179 "i686" : "linux32",
180 "i586" : "linux32",
181 "i486" : "linux32",
182 }
183
184 return arch2personality[self.arch]