Skip to content

Commit

Permalink
updater: provide incrementals if any are found for the given version
Browse files Browse the repository at this point in the history
* No functionality change if no incrementals are in the database, but
  if there are for the user's given version, those are provided rather
  than full roms. The future is now.
  • Loading branch information
invisiblek committed Nov 8, 2017
1 parent 1eed75b commit 7b2553e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ Options:
Example API Calls:
---
Obtaining rom list for a device:<br>
`GET /api/v1/<device>/<romtype>/<incremental>?after=<utc_timestamp>&version=<14.1>` (incremental can be anything, it is currently unused)<br>
`GET /api/v1/<device>/<romtype>/<incremental>?after=<utc_timestamp>&version=<14.1>`
`<device>` - Name of device. Example: `d2vzw`<br>
`<romtype>` - Type of rom. Example: `nightly`<br>
`<incremental>` - Caller device's incremental ID (ro.build.incr). Can be anything. <br>
`<incremental>` - Caller device's incremental ID (ro.build.incr). If any zips are available that updates the given incremental version, those are provided rather than full roms.<br>
`<after>` - Timestamp for current build on device. (optional) <br>
`<romversion>` - Version of rom. Example: `14.1`(optional)<br>

Expand Down
10 changes: 8 additions & 2 deletions updater/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from updater.changelog.gerrit import GerritServer, GerritJSONEncoder
from updater.changelog import get_changes, get_timestamp
from updater.database import Rom, ApiKey, Device
from updater.database import Rom, ApiKey, Device, Incremental

from flask import Flask, jsonify, request, abort, render_template
from flask_mongoengine import MongoEngine
Expand Down Expand Up @@ -101,7 +101,13 @@ def check_builds():

@cache.memoize(timeout=3600)
def get_build_types(device, romtype, after, version):
roms = Rom.get_roms(device=device, romtype=romtype, before=app.config['BUILD_SYNC_TIME'])
roms = []

roms = Incremental.get_incrementals(device=device, romtype=romtype, before=app.config['BUILD_SYNC_TIME'], incremental=incrementalversion)

if not len(roms):
roms = Rom.get_roms(device=device, romtype=romtype, before=app.config['BUILD_SYNC_TIME'])

if after:
roms = roms(datetime__gt=after)
if version:
Expand Down
48 changes: 48 additions & 0 deletions updater/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,54 @@ def get_device_version(cls, device):
return None
return cls.objects(device=device).first()['version']

class Incremental(Document):
filename = StringField(required=True)
datetime = DateTimeField(required=True, default=default_time)
device = StringField(required=True)
version = StringField(required=True)
romtype = StringField(required=True)
md5sum = StringField(required=True)
url = StringField()
from_incremental = StringField(required=True)
to_incremental = StringField(required=True)

@classmethod
def get_incrementals(cls, device, romtype=None, before=3600, incremental=None):
args = {
'device': device,
'romtype': romtype,
'datetime__lt': datetime.now()-timedelta(seconds=before),
'from_incremental': incremental
}
if before == 0:
del args['datetime__lt']
if not romtype:
del args['romtype']
return cls.objects(**args).order_by('-datetime')

@classmethod
def get_devices(cls):
#TODO change this to an aggregate
return cls.objects().distinct(field="device")

@classmethod
def get_types(cls, device):
return cls.objects().distinct(field="romtype")

@classmethod
def get_current_devices_by_version(cls):
# db.rom.aggregate({'$group': {'_id': '$version', 'device': {'$push': '$device'}}})
versions = {}
for version in cls.objects().aggregate({'$group': {'_id': '$version', 'devices': {'$push': '$device'}}}):
versions[version['_id']] = version['devices']
return versions

@classmethod
def get_device_version(cls, device):
if not device:
return None
return cls.objects(device=device).first()['version']

class Device(Document):
model = StringField(required=True, unique=True)
oem = StringField(required=True)
Expand Down

0 comments on commit 7b2553e

Please sign in to comment.