]>
git.ipfire.org Git - people/ms/pakfire.git/blob - python/pakfire/distro.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 ###############################################################################
26 log
= logging
.getLogger("pakfire")
30 class Distribution(object):
31 def __init__(self
, data
=None):
37 # Read /etc/os-release if it does exist.
43 def read_osrelease(self
):
44 filename
= "/etc/os-release"
46 if not os
.path
.exists(filename
):
51 "PRETTY_NAME" : "pretty_name",
52 "VERSION_ID" : "release",
58 for line
in f
.readlines():
59 m
= re
.match(r
"^(.*)=(.*)$", line
)
63 v
= v
.replace("\"", "")
77 log
.debug("Distribution configuration:")
79 attrs
= ("name", "release", "sname", "dist", "vendor", "contact",
80 "arch", "machine", "buildtarget", "source_dl",)
83 log
.debug(" %s : %s" % (attr
, getattr(self
, attr
)))
88 "name = %s" % self
.name
,
89 "release = %s" % self
.release
,
90 "slogan = %s" % self
.slogan
,
92 "vendor = %s" % self
.vendor
,
93 "contact = %s" % self
.contact
,
96 return "\n".join(lines
)
98 def update(self
, config
):
102 # Exceptional handling for arch.
103 if config
.has_key("arch"):
104 self
.arch
= config
["arch"]
107 self
._data
.update(config
)
111 return self
._data
.get("name", "unknown")
114 def pretty_name(self
):
115 pretty_name
= self
._data
.get("pretty_name", None)
117 pretty_name
= " ".join((self
.name
, self
.release
))
123 return self
._data
.get("release", "0")
127 return self
.name
.strip().lower()
131 return self
._data
.get("slogan", "N/A")
135 vendor
= self
._data
.get("vendor")
137 vendor
= "%s Project" % self
.name
143 return self
._data
.get("contact", "N/A")
146 arch
= self
._data
.get("arch", None) or system
.system
.arch
148 # We can not set up a build environment for noarch.
150 arch
= system
.system
.arch
154 def set_arch(self
, arch
):
155 # XXX check if we are allowed to set this arch
159 self
._data
["arch"] = arch
161 arch
= property(get_arch
, set_arch
)
166 Returns the "class" this architecture belongs to.
168 if self
.arch
.startswith("arm"):
171 if self
.arch
in ("i686", "x86_64"):
178 return self
.sname
[:2] + self
.release
182 vendor
= self
.vendor
.split()[0]
184 s
= "%s-%s-linux-gnu" % (self
.arch
, vendor
.lower())
186 if self
.arch
.startswith("arm"):
192 def buildtarget(self
):
193 # Cut off last segment of machine.
194 return self
.machine
.replace("-gnu", "")
198 return self
._data
.get("source_dl", None)
203 An attribute that adds some environment variables to the
207 "DISTRO_NAME" : self
.name
,
208 "DISTRO_SNAME" : self
.sname
,
209 "DISTRO_RELEASE" : self
.release
,
210 "DISTRO_DISTTAG" : self
.dist
,
211 "DISTRO_ARCH" : self
.arch
,
212 "DISTRO_MACHINE" : self
.machine
,
213 "DISTRO_PLATFORM" : self
.platform
,
214 "DISTRO_BUILDTARGET" : self
.buildtarget
,
215 "DISTRO_VENDOR" : self
.vendor
,
216 "DISTRO_CONTACT" : self
.contact
,
217 "DISTRO_SLOGAN" : self
.slogan
,
226 for k
, v
in self
.environ
.items():
232 def personality(self
):
234 Return the personality of the target system.
236 If host and target system are of the same architecture, we return
237 None to skip the setting of the personality in the build chroot.
240 if self
.arch
== system
.system
.native_arch
:
244 "x86_64" : "linux64",
251 personality
= arch2personality
[self
.arch
]