fetchphones progress not working
This commit is contained in:
parent
7a9e31a8d3
commit
8f8b337e27
2 changed files with 45 additions and 19 deletions
25
Readme.md
25
Readme.md
|
@ -6,16 +6,15 @@
|
|||
```
|
||||
git clone https://git.lattuga.net/d0c/suitablephones.git
|
||||
virtualenv .
|
||||
bin/pip install -r requirements.txt
|
||||
bin/python manage.py migrate
|
||||
bin/python manage.py createsuperuser
|
||||
bin/python manage.py runserver
|
||||
source bin/activate
|
||||
pip install -r requirements.txt
|
||||
python manage.py migrate
|
||||
python manage.py createsuperuser
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
|
||||
Download Lineage official wiki as data source.
|
||||
Yaml file descripting all devices are in _"lineage_wiki/_data/devices/"_
|
||||
Yaml files descripting all devices are in _"lineage_wiki/_data/devices/"_
|
||||
|
||||
```
|
||||
git clone https://github.com/LineageOS/lineage_wiki.git
|
||||
|
@ -27,3 +26,15 @@ es.
|
|||
```
|
||||
LINEAGEWIKI = '/home/d0c/lineage_wiki'
|
||||
```
|
||||
|
||||
Populate database:
|
||||
```
|
||||
python manage.py fetchphones
|
||||
|
||||
```
|
||||
|
||||
Run
|
||||
|
||||
```
|
||||
python manage.py runserver
|
||||
```
|
|
@ -6,31 +6,46 @@ from django.core.management.base import BaseCommand, CommandError
|
|||
|
||||
from suitablephones.models import Bluetooth, Camera, Device
|
||||
|
||||
import logging
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Closes the specified poll for voting'
|
||||
help = 'Aiuto'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('poll_ids', nargs='+', type=int)
|
||||
#def add_arguments(self, parser):
|
||||
# parser.add_argument('poll_ids', nargs='+', type=int)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
Device.objects.all().delete()
|
||||
Bluetooth.objects.all().delete()
|
||||
Camera.objects.all().delete()
|
||||
for filename in os.listdir(settings.LINEAGEWIKI + "/_data/devices/"):
|
||||
with open(filename, "r") as stream:
|
||||
devicesdir = settings.LINEAGEWIKI + "/_data/devices/"
|
||||
for filename in os.listdir(devicesdir):
|
||||
with open(os.path.join(devicesdir, filename), "r") as stream:
|
||||
try:
|
||||
data = yaml.safe_load(stream)
|
||||
dev = Device()
|
||||
for key, value in data.items():
|
||||
if key == "cameras":
|
||||
cam = Camera.objects.filter(*value.items())
|
||||
if not cam.exists():
|
||||
cam = Camera()
|
||||
if key == "bluetooth":
|
||||
bt = Bluetooth.objects.filter(*value.items())
|
||||
if not bt.exists():
|
||||
bt = Bluetooth()
|
||||
for subkey, subvalue in value.items():
|
||||
cam
|
||||
for subkey in value.items():
|
||||
setattr(cam, subkey, subvalue)
|
||||
bt
|
||||
for subkey, subvalue in value.items():
|
||||
#logging.warning(type(subkey))
|
||||
#logging.warning(subkey)
|
||||
#print(type(subvalue) + subvalue)
|
||||
setattr(bt, subkey, subvalue)
|
||||
# elif key == "cameras":
|
||||
# cam = []
|
||||
# for c in Camera.objects.filter(*value.items())
|
||||
# cam.append(c)
|
||||
# if not cam.exists():
|
||||
# cam = Camera()
|
||||
# for subkey, subvalue in value.items():
|
||||
# cam
|
||||
# for subkey, subvalue in value.items():
|
||||
# setattr(cam, subkey, subvalue)
|
||||
else:
|
||||
setattr(dev, key, value)
|
||||
dev.save()
|
||||
|
|
Loading…
Reference in a new issue