OLD | NEW |
1 __metaclass__ = type | 1 __metaclass__ = type |
2 | 2 |
3 from datetime import ( | 3 from datetime import ( |
4 datetime, | 4 datetime, |
5 timedelta, | 5 timedelta, |
6 ) | 6 ) |
7 from email.utils import parseaddr | 7 from email.utils import parseaddr |
8 from inspect import getargspec | 8 from inspect import getargspec |
9 from os.path import ( | 9 from os.path import ( |
10 join, | 10 join, |
(...skipping 27 matching lines...) Expand all Loading... |
38 CHARM, | 38 CHARM, |
39 InvalidCharmType, | 39 InvalidCharmType, |
40 NegativeLimit, | 40 NegativeLimit, |
41 ) | 41 ) |
42 from charmworld.utils import ( | 42 from charmworld.utils import ( |
43 build_metric_key, | 43 build_metric_key, |
44 quote_key, | 44 quote_key, |
45 timestamp, | 45 timestamp, |
46 ) | 46 ) |
47 from charmworld.views.api.proof import proof_deployer | 47 from charmworld.views.api.proof import proof_deployer |
48 from charmworld.views.utils import json_response | 48 from charmworld.views.utils import ( |
| 49 get_bundle_downloads, |
| 50 json_response, |
| 51 ) |
49 | 52 |
50 | 53 |
51 @view_config(route_name="search-json-obsolete") | 54 @view_config(route_name="search-json-obsolete") |
52 @view_config(route_name="api-obsolete-0") | 55 @view_config(route_name="api-obsolete-0") |
53 @view_config(route_name="api-obsolete-1") | 56 @view_config(route_name="api-obsolete-1") |
54 def obsolete(request): | 57 def obsolete(request): |
55 message = 'This API version is no longer supported.' | 58 message = 'This API version is no longer supported.' |
56 return Response( | 59 return Response( |
57 message, | 60 message, |
58 headerlist=[ | 61 headerlist=[ |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 # Add the list of files in the bundle. | 424 # Add the list of files in the bundle. |
422 bundle_dict['files'] = bundle.get_file_list(db) | 425 bundle_dict['files'] = bundle.get_file_list(db) |
423 bundle_dict['charm_metadata'] = {} | 426 bundle_dict['charm_metadata'] = {} |
424 bundle_dict['deployer_file_url'] = route_url( | 427 bundle_dict['deployer_file_url'] = route_url( |
425 'personal-bundle-json-revision', | 428 'personal-bundle-json-revision', |
426 basket=bundle_dict['basket_name'], | 429 basket=bundle_dict['basket_name'], |
427 bundle=bundle_dict['name'], | 430 bundle=bundle_dict['name'], |
428 owner=bundle_dict['owner'], | 431 owner=bundle_dict['owner'], |
429 rev=bundle_dict['basket_revision'], | 432 rev=bundle_dict['basket_revision'], |
430 ) | 433 ) |
| 434 |
| 435 # Add in download data. |
| 436 downloads = get_bundle_downloads(db, bundle.id) |
| 437 bundle_dict['downloads'] = downloads.total |
| 438 bundle_dict['downloads_in_past_30_days'] = downloads.past_30_days |
| 439 |
431 service_data = bundle_dict.get('data') | 440 service_data = bundle_dict.get('data') |
432 # Now load the charm information we require for the services in the | 441 # Now load the charm information we require for the services in the |
433 # bundle. | 442 # bundle. |
434 for service, data in bundle.data['services'].iteritems(): | 443 for service, data in bundle.data['services'].iteritems(): |
435 description = BundledCharmDescription( | 444 description = BundledCharmDescription( |
436 service, data, service_data.get('series')) | 445 service, data, service_data.get('series')) |
437 charm = resolve_charm_from_description(db, description) | 446 charm = resolve_charm_from_description(db, description) |
438 if charm: | 447 if charm: |
439 formatted = cls._format_charm(Charm(charm)) | 448 formatted = cls._format_charm(Charm(charm)) |
440 bundle_dict['charm_metadata'][service] = formatted | 449 bundle_dict['charm_metadata'][service] = formatted |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 'series': series, | 818 'series': series, |
810 'name': name, | 819 'name': name, |
811 }, sort=[('store_data.revision', pymongo.DESCENDING)]) | 820 }, sort=[('store_data.revision', pymongo.DESCENDING)]) |
812 if charm is not None: | 821 if charm is not None: |
813 api_id = self._get_api_id(Charm(charm)) | 822 api_id = self._get_api_id(Charm(charm)) |
814 # Charm ID should match up to, but not including the revision. | 823 # Charm ID should match up to, but not including the revision. |
815 revisionless_charm_id = charm_id.split('-', 1)[0] | 824 revisionless_charm_id = charm_id.split('-', 1)[0] |
816 if not api_id.startswith(revisionless_charm_id): | 825 if not api_id.startswith(revisionless_charm_id): |
817 charm = None | 826 charm = None |
818 return charm_id, trailing, charm | 827 return charm_id, trailing, charm |
OLD | NEW |