~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/views/api.py

  • Committer: Tarmac
  • Author(s): Aaron Bentley
  • Date: 2013-04-08 19:27:00 UTC
  • mfrom: (187.2.20 revisions-access)
  • Revision ID: tarmac-20130408192700-3w89hqewu4b1cdy9
[r=sinzui][bug=][author=abentley] Include revisions in API

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from datetime import datetime
1
2
from email.utils import parseaddr
2
3
from inspect import getargspec
3
4
import json
97
98
        """Return the API id for a Mongo-formatted charm."""
98
99
        return re.sub('^cs:', '', charm['store_url'])
99
100
 
 
101
    @staticmethod
 
102
    def _parsed_email(address):
 
103
        name, address = parseaddr(address)
 
104
        return {
 
105
            'name': name,
 
106
            'email': address,
 
107
        }
 
108
 
 
109
    @classmethod
 
110
    def _format_revision(cls, revision):
 
111
        created = datetime.utcfromtimestamp(round(revision['created']))
 
112
        authors = [cls._parsed_email(author)
 
113
                   for author in revision['authors']]
 
114
        return{
 
115
            'message': revision['message'],
 
116
            'revno': revision['revno'],
 
117
            'date': created.isoformat(),
 
118
            'authors': authors,
 
119
        }
 
120
 
100
121
    @classmethod
101
122
    def _format_charm(cls, charm):
102
123
        """Format the charm for API consumers."""
111
132
        }
112
133
        output = dict((key, charm[value]) for key, value in mapping.items())
113
134
        maintainer = charm.get('maintainer', '')
114
 
        maintainer_name, maintainer_email = parseaddr(maintainer)
115
135
        bugs_link = (
116
136
            'https://bugs.launchpad.net/charms/%(series)s/+source/%(name)s'
117
137
            % charm)
 
138
        revisions = []
 
139
        for revision in charm['changes']:
 
140
            revisions.append(cls._format_revision(revision))
118
141
        output.update({
119
142
            'id': cls._get_api_id(charm),
120
143
            'rating_numerator': 0,
128
151
                'revision': str(charm['last_change']['revno']),
129
152
                'last_log': charm['last_change']['message'],
130
153
                'bugs_link': bugs_link,
131
 
            },
132
 
            'maintainer': {
133
 
                'name': maintainer_name,
134
 
                'email': maintainer_email,
135
 
            },
 
154
                'revisions': revisions,
 
155
            },
 
156
            'maintainer': cls._parsed_email(maintainer),
136
157
            'relations': {
137
158
                'provides': charm.get('provides', {}),
138
159
                'requires': charm.get('requires', {}),