class DeviceQuery(object): def __init__(self, router): self._device = Device(router) def get(self, key): return self._device.get(key) def put(self, key, value): self._device.put(key, value) def delete(self, key): self._device.delete(key)
def web_device(device): 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]))) 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 active_device = Device.objects(model=device).first() return render_template("device.html", active_oem=active_oem, active_device=active_device, oems=oems, devices=devices, roms=roms, get_timestamp=get_timestamp)
def import_devices(): with open("devices.json", "r") as f: data = json.load(f) for device in data: d = Device.objects(model=device['model']) if d: d.update(**device) else: Device(**device).save() if os.path.isfile("devices_local.json"): with open("devices_local.json", "r") as f: data = json.load(f) for device in data: d = Device.objects(model=device['model']) if d: d.update(**device) else: Device(**device).save()
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)
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)
def report(): tested_data = json.loads(request.data) url = generate_report(tested_data) ip = str(tested_data['camInfo']['ip']) port = str(tested_data['camInfo']['port']) device = Device.query.filter(Device.ip == ip, Device.port == port).first() if device is None: device = Device(ip=ip, port=port, type='device', name='%s:%s' % (ip, port)) db.session.add(device) dbreport = TestResults(device=device, user=g.user, url=url, rawText=json.dumps(tested_data)) db.session.add(dbreport) db.session.commit() return jsonify(response=url)
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)
def __init__(self, router): self._device = Device(router)
def check_builds(): for d in Device.objects(): if requests.head(d.url).status_code == 404: print "Rom.objects(filename={}).delete()".format(d.filename)