From aa09569b38f1fd1a78377396b24587d6ef69432b Mon Sep 17 00:00:00 2001 From: Dan Pasanen Date: Tue, 24 Jan 2017 10:11:54 -0600 Subject: [PATCH] add file size to download pages * defaults to 0.00 MB if no size is defined in the database Change-Id: Iaab0d3139cdba437c7f42d4e996e67b133f53d1f --- examples/add_rom.json | 3 ++- seed.sh | 3 ++- updater/app.py | 7 ++++--- updater/database.py | 4 +++- updater/templates/device.html | 2 ++ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/add_rom.json b/examples/add_rom.json index 5ad1b56..d61897a 100644 --- a/examples/add_rom.json +++ b/examples/add_rom.json @@ -5,5 +5,6 @@ "filename": "cm-14.1-mako-signed.zip", "datetime": "2012-07-07", "url": "https://mirrorbits.lineageos.org/full/mako/20120707/cm-14.1-mako-signed.zip", - "romtype": "nightly" + "romtype": "nightly", + "size": "123456789" } diff --git a/seed.sh b/seed.sh index 4e2dd04..03b29a2 100755 --- a/seed.sh +++ b/seed.sh @@ -11,9 +11,10 @@ VERSION=14.1 DATETIME="2017-07-07" ROMTYPE="nightly" MD5SUM=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) +SIZE="123456789" URL=https://mirrobits.lineageos.org/full/${DEVICE}/${DATETIME}/${FILENAME} -flask addrom --filename $FILENAME --device $DEVICE --version $VERSION --datetime $DATETIME --romtype $ROMTYPE --md5sum $MD5SUM --url $URL +flask addrom --filename $FILENAME --device $DEVICE --version $VERSION --datetime $DATETIME --romtype $ROMTYPE --md5sum $MD5SUM --url $URL --size $SIZE done diff --git a/updater/app.py b/updater/app.py index afe5383..695623e 100755 --- a/updater/app.py +++ b/updater/app.py @@ -46,9 +46,10 @@ def decorated_function(*args, **kwargs): @click.option('--datetime', '-t', 'datetime', required=True) @click.option('--romtype', '-r', 'romtype', required=True) @click.option('--md5sum', '-m', 'md5sum', required=True) +@click.option('--size', '-s', 'size', required=True) @click.option('--url', '-u', 'url', required=True) -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() +def addrom(filename, device, version, datetime, romtype, md5sum, size, url): + Rom(filename=filename, datetime=datetime, device=device, version=version, romtype=romtype, md5sum=md5sum, romsize=size, url=url).save() @app.cli.command() @click.option('--filename', '-f', 'filename', required=True) @@ -165,7 +166,7 @@ def test_auth(): @api_key_required def add_build(): data = request.get_json() - validate = {"filename": "str", "device": "str", "version": "str", "md5sum": "str", "url": "str", "romtype": "str"} + validate = {"filename": "str", "device": "str", "version": "str", "md5sum": "str", "url": "str", "romtype": "str", "romsize": "int"} #bad data sent if not data: diff --git a/updater/database.py b/updater/database.py index 37939f6..f25bfeb 100755 --- a/updater/database.py +++ b/updater/database.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from mongoengine import Document, BooleanField, DateTimeField, StringField +from mongoengine import Document, BooleanField, DateTimeField, StringField, IntField from datetime import datetime, timedelta @@ -15,6 +15,7 @@ class Rom(Document): romtype = StringField(required=True) md5sum = StringField(required=True) url = StringField() + romsize = IntField() @classmethod def get_roms(cls, device, romtype=None, before=3600): @@ -60,6 +61,7 @@ class Incremental(Document): romtype = StringField(required=True) md5sum = StringField(required=True) url = StringField() + romsize = IntField() from_incremental = StringField(required=True) to_incremental = StringField(required=True) diff --git a/updater/templates/device.html b/updater/templates/device.html index 2e9a275..bde65ce 100644 --- a/updater/templates/device.html +++ b/updater/templates/device.html @@ -22,6 +22,7 @@

Builds for {{active_device.model}}

Type Version File + Size Date @@ -33,6 +34,7 @@

Builds for {{active_device.model}}

{{rom.filename}}
sha256 sha1 + {% if rom.romsize %} {{'%0.2f'| format(rom.romsize/1024/1024|float)}} {% else %} 0.00 {% endif %} MB {{rom.datetime.strftime("%Y-%m-%d %H:%M:%S %Z")}} {% endfor %}