]> git.ipfire.org Git - pakfire.git/blame - pakfire/distro.py
macros: Move make_*_targets into build section.
[pakfire.git] / pakfire / distro.py
CommitLineData
47a4cb89 1#!/usr/bin/python
b792d887
MT
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###############################################################################
47a4cb89
MT
21
22import logging
23import os
24import re
25
26from errors import ConfigError
7c8f2953 27from repository import Repositories
47a4cb89
MT
28
29class Distribution(object):
7c8f2953 30 def __init__(self, pakfire, distro_config=None):
47a4cb89
MT
31 self.pakfire = pakfire
32
33 self._data = {
3ad4bb5a 34 "arch" : self.config.host_arch,
47a4cb89
MT
35 "name" : "unknown",
36 "slogan" : "---",
37 "vendor" : "unknown",
38 "version" : "0.0",
39 }
40
7c8f2953
MT
41 # Inherit configuration from Pakfire configuration.
42 self.update(self.pakfire.config._distro)
47a4cb89 43
7c8f2953
MT
44 # Update my configuration from the constructor.
45 self.update(distro_config)
47a4cb89
MT
46
47 # Dump all data
48 self.dump()
49
3ad4bb5a
MT
50 @property
51 def config(self):
52 return self.pakfire.config
53
47a4cb89
MT
54 def dump(self):
55 logging.debug("Distribution configuration:")
56
7c8f2953 57 attrs = ("name", "version", "release", "sname", "dist", "vendor",
c07a3ca7 58 "arch", "machine", "source_dl",)
47a4cb89
MT
59
60 for attr in attrs:
61 logging.debug(" %s : %s" % (attr, getattr(self, attr)))
62
7c8f2953
MT
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
47a4cb89
MT
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
c07a3ca7
MT
100 @property
101 def maintainer(self):
102 return self._data.get("maintainer")
103
47a4cb89 104 def get_arch(self):
3ad4bb5a 105 return self._data.get("arch") or self.config.host_arch
47a4cb89
MT
106
107 def set_arch(self, arch):
108 # XXX check if we are allowed to set this arch
7c8f2953
MT
109 if not arch:
110 return
111
112 self._data["arch"] = arch
47a4cb89
MT
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):
7c8f2953
MT
122 vendor = self.vendor.split()[0]
123
124 return "%s-%s-linux-gnu" % (self.arch, vendor.lower())
47a4cb89 125
c07a3ca7
MT
126 @property
127 def source_dl(self):
128 return self._data.get("source_dl", None)
129
47a4cb89
MT
130 @property
131 def environ(self):
132 """
133 An attribute that adds some environment variables to the
134 chroot environment.
135 """
136 env = {
c07a3ca7
MT
137 "DISTRO_NAME" : self.name,
138 "DISTRO_SNAME" : self.sname,
139 "DISTRO_VERSION" : self.version,
140 "DISTRO_RELEASE" : self.release,
141 "DISTRO_DISTTAG" : self.dist,
142 "DISTRO_ARCH" : self.arch,
143 "DISTRO_MACHINE" : self.machine,
144 "DISTRO_MAINTAINER" : self.maintainer,
145 "DISTRO_VENDOR" : self.vendor,
146 "DISTRO_SLOGAN" : self.slogan,
47a4cb89
MT
147 }
148
149 return env
150
151 @property
152 def info(self):
153 info = {}
154
155 for k, v in self.environ.items():
156 info[k.lower()] = v
157
158 return info
159
e360ea59
MT
160 @property
161 def personality(self):
162 """
163 Return the personality of the target system.
164
165 If host and target system are of the same architecture, we return
166 None to skip the setting of the personality in the build chroot.
167 """
168
3ad4bb5a 169 if self.arch == self.config.host_arch:
e360ea59
MT
170 return None
171
172 arch2personality = {
173 "x86_64" : "linux64",
174 "i686" : "linux32",
175 "i586" : "linux32",
176 "i486" : "linux32",
177 }
178
179 return arch2personality[self.arch]