-
Notifications
You must be signed in to change notification settings - Fork 46
/
api_v1.py
89 lines (73 loc) · 2.5 KB
/
api_v1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from flask import Blueprint, jsonify, request
from api_common import get_builds, get_device_version, get_build_types, get_device_builds
from changelog.gerrit import GerritServer
from changelog import get_changes, get_timestamp
from config import Config
import extensions
api = Blueprint('api_v1', __name__)
gerrit = GerritServer(Config.GERRIT_URL)
@api.route('/<string:device>/<string:romtype>/<string:incrementalversion>')
def api_v1_index(device, romtype, incrementalversion):
after = request.args.get('after')
version = request.args.get('version')
return get_build_types(device, romtype, after, version)
@api.route('/types/<string:device>/')
@extensions.cache.cached()
def api_v1_get_types(device):
data = get_device_builds(device)
types = {'nightly'}
for build in data:
types.add(build['type'])
return jsonify({'response': list(types)})
@api.route('/changes/<device>/')
@api.route('/changes/<device>/<int:before>/')
@api.route('/changes/<device>/-1/')
@extensions.cache.cached()
def api_v1_changes(device='all', before=-1):
version = get_device_version(device)
if version:
if float(version) >= 20:
versions = [version, version.split('.')[0]]
else:
versions = [version]
else:
versions = []
response_changes = []
try:
changes, last = get_changes(gerrit, device, before, versions)
for change in changes:
response_changes.append({
'project': change.project,
'subject': change.subject,
'submitted': get_timestamp(change.submitted),
'updated': get_timestamp(change.updated),
'url': change.url,
'owner': change.owner,
'labels': change.labels
})
except ConnectionError:
last = 0
response_changes.append({
'project': None,
'subject': None,
'submitted': 0,
'updated': 0,
'url': Config.STATUS_URL,
'owner': None,
'labels': None
})
return jsonify({
'last': last,
'res': response_changes,
})
@api.route('/devices')
@extensions.cache.cached()
def api_v1_devices():
data = get_builds()
versions = {}
for device in data.keys():
for build in data[device]:
versions.setdefault(build['version'], set()).add(device)
for version in versions.keys():
versions[version] = list(versions[version])
return jsonify(versions)