OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 # | 4 # |
5 # Adapted from portage/getbinpkg.py -- Portage binary-package helper functions | 5 # Adapted from portage/getbinpkg.py -- Portage binary-package helper functions |
6 # Copyright 2003-2004 Gentoo Foundation | 6 # Copyright 2003-2004 Gentoo Foundation |
7 # Distributed under the terms of the GNU General Public License v2 | 7 # Distributed under the terms of the GNU General Public License v2 |
8 | 8 |
9 import operator | 9 import operator |
10 import os | 10 import os |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 def _PopulateDuplicateDB(self, db): | 45 def _PopulateDuplicateDB(self, db): |
46 """Populate db with SHA1 -> URL mapping for packages. | 46 """Populate db with SHA1 -> URL mapping for packages. |
47 | 47 |
48 Args: | 48 Args: |
49 db: Dictionary to populate with SHA1 -> URL mapping for packages. | 49 db: Dictionary to populate with SHA1 -> URL mapping for packages. |
50 """ | 50 """ |
51 | 51 |
52 uri = self.header['URI'] | 52 uri = self.header['URI'] |
53 for pkg in self.packages: | 53 for pkg in self.packages: |
54 cpv, sha1 = pkg['CPV'], pkg['SHA1'] | 54 cpv, sha1 = pkg['CPV'], pkg.get('SHA1') |
55 path = pkg.get('PATH', cpv + '.tbz2') | 55 if sha1: |
56 db[sha1] = urlparse.urljoin(uri, path) | 56 path = pkg.get('PATH', cpv + '.tbz2') |
| 57 db[sha1] = urlparse.urljoin(uri, path) |
57 | 58 |
58 def _ReadPkgIndex(self, pkgfile): | 59 def _ReadPkgIndex(self, pkgfile): |
59 """Read a list of key/value pairs from the Packages file into a dictionary. | 60 """Read a list of key/value pairs from the Packages file into a dictionary. |
60 | 61 |
61 Both header entries and package entries are lists of key/value pairs, so | 62 Both header entries and package entries are lists of key/value pairs, so |
62 they can both be read by this function. Entries can be terminated by empty | 63 they can both be read by this function. Entries can be terminated by empty |
63 lines or by the end of the file. | 64 lines or by the end of the file. |
64 | 65 |
65 This function will read lines from the specified file until it encounters | 66 This function will read lines from the specified file until it encounters |
66 the a blank line or the end of the file. | 67 the a blank line or the end of the file. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 Returns: | 174 Returns: |
174 A list of the packages that still need to be uploaded. | 175 A list of the packages that still need to be uploaded. |
175 """ | 176 """ |
176 db = {} | 177 db = {} |
177 for pkgindex in pkgindexes: | 178 for pkgindex in pkgindexes: |
178 pkgindex._PopulateDuplicateDB(db) | 179 pkgindex._PopulateDuplicateDB(db) |
179 | 180 |
180 uploads = [] | 181 uploads = [] |
181 base_uri = self.header['URI'] | 182 base_uri = self.header['URI'] |
182 for pkg in self.packages: | 183 for pkg in self.packages: |
183 sha1 = pkg['SHA1'] | 184 sha1 = pkg.get('SHA1') |
184 uri = db.get(sha1) | 185 uri = db.get(sha1) |
185 if uri and uri.startswith(base_uri): | 186 if sha1 and uri and uri.startswith(base_uri): |
186 pkg['PATH'] = uri[len(base_uri):].lstrip('/') | 187 pkg['PATH'] = uri[len(base_uri):].lstrip('/') |
187 else: | 188 else: |
188 uploads.append(pkg) | 189 uploads.append(pkg) |
189 return uploads | 190 return uploads |
190 | 191 |
191 def SetUploadLocation(self, base_uri, path_prefix): | 192 def SetUploadLocation(self, base_uri, path_prefix): |
192 """Set upload location to base_uri + path_prefix. | 193 """Set upload location to base_uri + path_prefix. |
193 | 194 |
194 Args: | 195 Args: |
195 base_uri: Base URI for all packages in the file. We set | 196 base_uri: Base URI for all packages in the file. We set |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 package_path: Directory containing Packages file. | 299 package_path: Directory containing Packages file. |
299 | 300 |
300 Returns: | 301 Returns: |
301 A PackageIndex object. | 302 A PackageIndex object. |
302 """ | 303 """ |
303 packages_file = file(os.path.join(package_path, 'Packages')) | 304 packages_file = file(os.path.join(package_path, 'Packages')) |
304 pkgindex = PackageIndex() | 305 pkgindex = PackageIndex() |
305 pkgindex.Read(packages_file) | 306 pkgindex.Read(packages_file) |
306 packages_file.close() | 307 packages_file.close() |
307 return pkgindex | 308 return pkgindex |
OLD | NEW |