|
6 | 6 | import yaml |
7 | 7 | import apt_pkg |
8 | 8 | from aptly.exceptions import AptlyException, NoSuchPublish |
| 9 | +from aptly.decorators import CachedMethod |
9 | 10 |
|
10 | 11 | lg = logging.getLogger(__name__) |
11 | 12 |
|
@@ -150,7 +151,7 @@ def get_repo_information(config, client, fill_repo=False, components=[]): |
150 | 151 | if components and repo.get('component') not in components: |
151 | 152 | continue |
152 | 153 | if fill_repo and origin == 'repo': |
153 | | - packages = client.do_get('/{}/{}/{}'.format("repos", name, "packages")) |
| 154 | + packages = Publish._get_packages("repos", name) |
154 | 155 | repo_dict[name] = packages |
155 | 156 | for distribution in repo.get('distributions'): |
156 | 157 | publish_name = str.join('/', distribution.split('/')[:-1]) |
@@ -281,11 +282,26 @@ def compare(self, other, components=[]): |
281 | 282 |
|
282 | 283 | return (diff, equal) |
283 | 284 |
|
| 285 | + @staticmethod |
| 286 | + @CachedMethod |
| 287 | + def _get_packages(client, source_type, source_name): |
| 288 | + return client.do_get('/{}/{}/packages'.format(source_type, source_name)) |
| 289 | + |
| 290 | + @staticmethod |
| 291 | + @CachedMethod |
| 292 | + def _get_publishes(client): |
| 293 | + return client.do_get('/publish') |
| 294 | + |
| 295 | + @staticmethod |
| 296 | + @CachedMethod |
| 297 | + def _get_snapshots(client): |
| 298 | + return client.do_get('/snapshots', {'sort': 'time'}) |
| 299 | + |
284 | 300 | def _get_publish(self): |
285 | 301 | """ |
286 | 302 | Find this publish on remote |
287 | 303 | """ |
288 | | - publishes = self.client.do_get('/publish') |
| 304 | + publishes = self._get_publishes(self.client) |
289 | 305 | for publish in publishes: |
290 | 306 | if publish['Distribution'] == self.distribution and \ |
291 | 307 | publish['Prefix'].replace("/", "_") == (self.prefix or '.') and \ |
@@ -350,7 +366,7 @@ def purge_publish(self, repo_dict, publish_dict, components=[], publish=False): |
350 | 366 | repo_dict[repo_name] = [] |
351 | 367 | continue |
352 | 368 |
|
353 | | - packages = self.client.do_get('/{}/{}/{}'.format("snapshots", name, "packages")) |
| 369 | + packages = self._get_packages(self.client, "snapshots", name) |
354 | 370 | packages = sorted(packages, key=lambda x: self.parse_package_ref(x)[2], reverse=True, cmp=apt_pkg.version_compare) |
355 | 371 |
|
356 | 372 | for package in packages: |
@@ -503,7 +519,7 @@ def get_packages(self, component=None, components=[], packages=None): |
503 | 519 | # We don't want packages for this component |
504 | 520 | continue |
505 | 521 |
|
506 | | - component_refs = self.client.do_get('/snapshots/%s/packages' % snapshot['Name']) |
| 522 | + component_refs = self._get_packages(self.client, "snapshots", snapshot['Name']) |
507 | 523 | if packages: |
508 | 524 | # Filter package names |
509 | 525 | for ref in component_refs: |
@@ -536,7 +552,7 @@ def _find_snapshot(self, name): |
536 | 552 | """ |
537 | 553 | Find snapshot on remote by name or regular expression |
538 | 554 | """ |
539 | | - remote_snapshots = self.client.do_get('/snapshots', {'sort': 'time'}) |
| 555 | + remote_snapshots = self._get_snapshots(self.client) |
540 | 556 | for remote in reversed(remote_snapshots): |
541 | 557 | if remote["Name"] == name or \ |
542 | 558 | re.match(name, remote["Name"]): |
@@ -597,7 +613,7 @@ def merge_snapshots(self): |
597 | 613 | package_refs = [] |
598 | 614 | for snapshot in snapshots: |
599 | 615 | # Get package refs from each snapshot |
600 | | - packages = self.client.do_get('/snapshots/%s/packages' % snapshot) |
| 616 | + packages = self._get_packages(self.client, "snapshots", snapshot) |
601 | 617 | package_refs.extend(packages) |
602 | 618 |
|
603 | 619 | try: |
|
0 commit comments