1 """parse Package-List field
3 @copyright: 2014, Ansgar Burchardt <ansgar@debian.org>
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 2 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, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 from daklib.architecture import match_architecture
22 from daklib.utils import extract_component_from_section
24 class InvalidSource(Exception):
27 class PackageListEntry(object):
28 def __init__(self, name, package_type, section, component, priority, **other):
30 self.type = package_type
31 self.section = section
32 self.component = component
33 self.priority = priority
36 self.architectures = self._architectures()
38 def _architectures(self):
39 archs = self.other.get("arch", None)
42 return archs.split(',')
44 def built_on_architecture(self, architecture):
45 archs = self.architectures
49 if match_architecture(architecture, arch):
53 def built_in_suite(self, suite):
55 for arch in suite.architectures:
56 built_on_arch = self.built_on_architecture(arch.arch_string)
59 if built_on_arch is None:
63 class PackageList(object):
64 def __init__(self, source):
65 if 'Package-List' in source:
67 elif 'Binary' in source:
68 self._parse_fallback(source)
70 raise InvalidSource('Source package has neither Package-List nor Binary field.')
72 self.fallback = any(entry.architectures is None for entry in self.package_list)
74 def _binaries(self, source):
75 return set(name.strip() for name in source['Binary'].split(","))
77 def _parse(self, source):
78 self.package_list = []
80 binaries_binary = self._binaries(source)
81 binaries_package_list = set()
83 for line in source['Package-List'].split("\n"):
88 raise InvalidSource("Package-List entry has less than four fields.")
90 # <name> <type> <component/section> <priority> [arch=<arch>[,<arch>]...]
92 package_type = fields[1]
93 component, section = extract_component_from_section(fields[2])
95 other = dict(kv.split('=', 1) for kv in fields[4:])
97 if name in binaries_package_list:
98 raise InvalidSource("Package-List has two entries for '{0}'.".format(name))
99 if name not in binaries_binary:
100 raise InvalidSource("Package-List lists {0} which is not listed in Binary.".format(name))
101 binaries_package_list.add(name)
103 entry = PackageListEntry(name, package_type, section, component, priority, **other)
104 self.package_list.append(entry)
106 if len(binaries_binary) != len(binaries_package_list):
107 raise InvalidSource("Package-List and Binaries fields have a different number of entries.")
109 def _parse_fallback(self, source):
110 self.package_list = []
112 for binary in self._binaries(source):
120 entry = PackageListEntry(name, package_type, section, component, priority, **other)
121 self.package_list.append(entry)
123 def packages_for_suite(self, suite):
125 for entry in self.package_list:
126 built = entry.built_in_suite(suite)
127 if built or built is None:
128 packages.append(entry)
131 def has_arch_indep_packages(self):
132 has_arch_indep = False
133 for entry in self.package_list:
134 built = entry.built_on_architecture('all')
138 has_arch_indep = None
139 return has_arch_indep
141 def has_arch_dep_packages(self):
143 for entry in self.package_list:
144 built_on_all = entry.built_on_architecture('all')
145 if built_on_all == False:
147 if built_on_all is None: