Package daklib :: Module packagelist
[hide private]
[frames] | no frames]

Source Code for Module daklib.packagelist

  1  """parse Package-List field 
  2   
  3  @copyright: 2014, Ansgar Burchardt <ansgar@debian.org> 
  4  @license: GPL-2+ 
  5  """ 
  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 2 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, write to the Free Software 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 20   
 21  from daklib.architecture import match_architecture 
 22  from daklib.utils import extract_component_from_section 
 23   
 24   
25 -class InvalidSource(Exception):
26 pass
27 28
29 -class PackageListEntry:
30 - def __init__(self, name, package_type, section, component, priority, **other):
31 self.name = name 32 self.type = package_type 33 self.section = section 34 self.component = component 35 self.priority = priority 36 self.other = other 37 38 self.architectures = self._architectures()
39
40 - def _architectures(self):
41 archs = self.other.get("arch", None) 42 if archs is None: 43 return None 44 return archs.split(',')
45
46 - def built_on_architecture(self, architecture):
47 archs = self.architectures 48 if archs is None: 49 return None 50 for arch in archs: 51 if match_architecture(architecture, arch): 52 return True 53 return False
54
55 - def built_in_suite(self, suite):
56 built = False 57 for arch in suite.architectures: 58 if arch.arch_string == 'source': 59 continue 60 built_on_arch = self.built_on_architecture(arch.arch_string) 61 if built_on_arch: 62 return True 63 if built_on_arch is None: 64 built = None 65 return built
66
67 - def built_in_default_profile(self):
68 # See man:dsc(5) and https://bugs.debian.org/913965#77 69 profiles_and = self.other.get('profile') 70 if profiles_and is None: 71 return True 72 return all( 73 any(profile.startswith("!") for profile in profiles_or.split("+")) 74 for profiles_or in profiles_and.split(",") 75 )
76 77
78 -class PackageList:
79 - def __init__(self, source):
80 if 'Package-List' in source: 81 self._parse(source) 82 elif 'Binary' in source: 83 self._parse_fallback(source) 84 else: 85 raise InvalidSource('Source package has neither Package-List nor Binary field.') 86 87 self.fallback = any(entry.architectures is None for entry in self.package_list)
88
89 - def _binaries(self, source):
90 return set(name.strip() for name in source['Binary'].split(","))
91
92 - def _parse(self, source):
93 self.package_list = [] 94 95 binaries_binary = self._binaries(source) 96 binaries_package_list = set() 97 98 for line in source['Package-List'].split("\n"): 99 if not line: 100 continue 101 fields = line.split() 102 if len(fields) < 4: 103 raise InvalidSource("Package-List entry has less than four fields.") 104 105 # <name> <type> <component/section> <priority> [arch=<arch>[,<arch>]...] 106 name = fields[0] 107 package_type = fields[1] 108 section, component = extract_component_from_section(fields[2]) 109 priority = fields[3] 110 other = dict(kv.split('=', 1) for kv in fields[4:]) 111 112 if name in binaries_package_list: 113 raise InvalidSource("Package-List has two entries for '{0}'.".format(name)) 114 if name not in binaries_binary: 115 raise InvalidSource("Package-List lists {0} which is not listed in Binary.".format(name)) 116 binaries_package_list.add(name) 117 118 entry = PackageListEntry(name, package_type, section, component, priority, **other) 119 self.package_list.append(entry) 120 121 if len(binaries_binary) != len(binaries_package_list): 122 raise InvalidSource("Package-List and Binaries fields have a different number of entries.")
123
124 - def _parse_fallback(self, source):
125 self.package_list = [] 126 127 for binary in self._binaries(source): 128 name = binary 129 package_type = None 130 component = None 131 section = None 132 priority = None 133 other = dict() 134 135 entry = PackageListEntry(name, package_type, section, component, priority, **other) 136 self.package_list.append(entry)
137
138 - def packages_for_suite(self, suite, only_default_profile=True):
139 packages = [] 140 for entry in self.package_list: 141 if only_default_profile and not entry.built_in_default_profile(): 142 continue 143 built = entry.built_in_suite(suite) 144 if built or built is None: 145 packages.append(entry) 146 return packages
147
148 - def has_arch_indep_packages(self):
149 has_arch_indep = False 150 for entry in self.package_list: 151 built = entry.built_on_architecture('all') 152 if built: 153 return True 154 if built is None: 155 has_arch_indep = None 156 return has_arch_indep
157
158 - def has_arch_dep_packages(self):
159 has_arch_dep = False 160 for entry in self.package_list: 161 built_on_all = entry.built_on_architecture('all') 162 if built_on_all is False: 163 return True 164 if built_on_all is None: 165 has_arch_dep = None 166 return has_arch_dep
167