Ejemplo n.º 1
0
def add_build():
    data = request.get_json()
    validate = {
        "filename": "str",
        "device": "str",
        "version": "str",
        "md5sum": "str",
        "url": "str",
        "romtype": "str",
        "romsize": "int"
    }

    #bad data sent
    if not data:
        return jsonify(validate), 400
    #validate keys all exist
    for key in validate.keys():
        if key not in data:
            return jsonify(validate), 406

    # validate types
    for key in validate.keys():
        try:
            locate(validate[key])(data[key])
        except:
            return jsonify({
                "error":
                "{} must be parseable by python's {} class".format(
                    key, validate[key])
            }), 406
    rom = Rom(**data)
    rom.save()
    return "ok", 200
Ejemplo n.º 2
0
def web_device(device):
    devices = sorted([x for x in Device.get_devices() if x['model'] in Rom.get_devices()], key=lambda device: device['model'])
    oems = sorted(list(set([x['oem'] for x in devices])))

    roms = Rom.get_roms(device=device, before=app.config['BUILD_SYNC_TIME'])

    active_oem = [x['oem'] for x in devices if x['model'] == device]
    active_oem = active_oem[0] if active_oem else None

    return render_template("device.html", active_oem=active_oem, active_device=device, oems=oems, devices=devices, roms=roms)
Ejemplo n.º 3
0
def index(device, romtype, incrementalversion):
    after = request.args.get("after")
    version = request.args.get("version")

    roms = Rom.get_roms(device=device,
                        romtype=romtype,
                        before=app.config['BUILD_SYNC_TIME'])
    if after:
        roms = roms(datetime__gt=after)
    if version:
        roms = roms(version=version)

    roms = roms.order_by('datetime')
    data = []

    for rom in roms:
        data.append({
            "id": str(rom.id),
            "url": rom.url,
            "romtype": rom.romtype,
            "datetime": int(time.mktime(rom.datetime.timetuple())),
            "version": rom.version,
            "filename": rom.filename
        })
    return jsonify({'response': data})
Ejemplo n.º 4
0
def addrom(filename, device, version, datetime, romtype, md5sum, url):
    Rom(filename=filename,
        datetime=datetime,
        device=device,
        version=version,
        romtype=romtype,
        md5sum=md5sum,
        url=url).save()
Ejemplo n.º 5
0
def web_extras():
    devices = sorted(
        [x for x in Device.get_devices() if x['model'] in Rom.get_devices()],
        key=lambda device: device['name'])
    oems = sorted(list(set([x['oem'] for x in devices])))

    return render_template("extras.html",
                           oems=oems,
                           devices=devices,
                           extras=True)
Ejemplo n.º 6
0
def show_changelog(device='all', before=-1):
    devices = sorted(
        [x for x in Device.get_devices() if x['model'] in Rom.get_devices()],
        key=lambda device: device['name'])
    oems = sorted(list(set([x['oem'] for x in devices])))
    return render_template('changes.html',
                           oems=oems,
                           devices=devices,
                           device=device,
                           before=before,
                           changelog=True)
Ejemplo n.º 7
0
def delrom(filename):
    Rom.objects(filename=filename).delete()
Ejemplo n.º 8
0
def web_main():
    devices = sorted([x for x in Device.get_devices() if x['model'] in Rom.get_devices()], key=lambda device: device['model'])
    oems = sorted(list(set([x['oem'] for x in devices])))
    return render_template("main.html", oems=oems, devices=devices)
Ejemplo n.º 9
0
def api_v1_devices():
    return jsonify(Rom.get_current_devices_by_version())
Ejemplo n.º 10
0
def get_types(device):
    types = set(["nightly"])
    for rtype in Rom.get_types(device):
        types.add(rtype)
    return jsonify({'response': list(types)})
Ejemplo n.º 11
0
def api_v1_delete_file(filename):
    Rom.objects(filename=filename).delete()
    return '', 200
Ejemplo n.º 12
0
def check_builds():
    for r in Rom.objects():
        if requests.head(r.url).status_code == 404:
            print("Rom.objects(filename=\"{}\").delete()".format(r.filename))