fetchphones working with loop

This commit is contained in:
d0c 2023-01-21 03:49:32 +01:00
parent e81d005f58
commit c9fe1637e8
4 changed files with 75 additions and 47 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
todo.md
db.sqlite3
# ---> Python

View file

@ -139,4 +139,4 @@ REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
}
LINEAGEWIKI = '/home/francesco/Code/lineage_wiki'
LINEAGEWIKI = '/home/d0c/Code/lineage_wiki'

View file

@ -8,11 +8,29 @@ from suitablephones.models import Bluetooth, Camera, Device
import logging
def set_camera(args):
cam = Camera.objects.filter(**args)
if not cam.exists():
cam = Camera()
for subkey, subvalue in args.items():
if subkey == 'info':
mp = subvalue.split(' ')[0]
setattr(cam, 'megapixel', mp)
info = ' '.join(map(str, subvalue.split(' ')[2:]))
setattr(cam, subkey, info)
setattr(cam, subkey, subvalue)
cam.save()
else:
cam = cam.get()
return cam
class Command(BaseCommand):
help = 'Aiuto'
#def add_arguments(self, parser):
# parser.add_argument('poll_ids', nargs='+', type=int)
# parser.add_argument('poll_ids', nargs='+', type=int
def handle(self, *args, **options):
Device.objects.all().delete()
@ -20,44 +38,52 @@ class Command(BaseCommand):
Camera.objects.all().delete()
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)
print(data['codename'])
dev = Device()
for key, value in data.items():
if key == "architecture":
if type(value) == dict():
setattr(dev, key, value)
else: #type(value) == str():
setattr(dev, key, dict({ 'cpu' : value }))
# if key == "architecture":
# if type(value) == dict():
# setattr(dev, key, value)
# else: #type(value) == str():
# setattr(dev, key, dict({ 'cpu' : value }))
#match caso:
# case dict():
# print('dict')
elif key == "bluetooth":
if key == "bluetooth":
if not 'profiles' in value.keys():
value['profiles'] = None
# get() returned more than one Bluetooth -- it returned 2!
bt = Bluetooth.objects.filter(**value)
# __exact? https://docs.djangoproject.com/en/4.1/ref/models/querysets/#exact
if not bt.exists():
bt = Bluetooth()
for subkey, subvalue in value.items():
if not hasattr(value, 'profiles'):
setattr(bt, 'profiles', None)
setattr(bt, subkey, subvalue)
bt.save()
else:
bt = bt.get()
bt = bt.get(spec=value['spec'], profiles=value['profiles'])
dev.bluetooth = bt
dev.save()
elif key == "cameras":
print('camera')
# 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)
dev.save()
for c in value:
cam = set_camera(c)
dev.cameras.add(cam)
elif key == "peripherals":
if str(value) == "None":
value = None
elif key == "storage":
if str(value) == "None":
value = None
else:
setattr(dev, key, value)
dev.save()
dev.save()
except yaml.YAMLError as exc:
print(exc)
print(exc)
stream.close()

View file

@ -4,62 +4,63 @@ from django.db import models
class Bluetooth(models.Model):
spec = models.CharField(max_length=100)
profiles = models.CharField(max_length=100)
profiles = models.CharField(max_length=100, blank=True, null=True)
def __str__(self):
return f"{self.spec} - {self.profiles}"
class Camera(models.Model):
class FLASHES(models.TextChoices):
LED = 'L', 'Led'
DUAL_LED = 'DL', 'Double Led'
# class FLASHES(models.TextChoices):
# LED = 'L', 'Led'
# DUAL_LED = 'DL', 'Double Led'
flash = models.CharField(max_length=100)
megapixel = models.DecimalField(max_digits=5, decimal_places=1)
flash = models.CharField(max_length=100, choices=FLASHES.choices)
info = models.CharField(max_length=100, null=True)
def __str__(self):
return f"{self.megapixel} - {self.flash}"
return f" {self.flash - self.megapixel - self.info}"
class Device(models.Model):
architecture = models.JSONField(default=dict)
battery = models.JSONField(default=dict)
before_install = models.JSONField(default=dict, null=True) # dict or str
bluetooth = models.ForeignKey(Bluetooth, on_delete=models.CASCADE)
#architecture = models.JSONField(default=dict)
#battery = models.JSONField(default=dict)
#before_install = models.JSONField(default=dict, null=True) # dict or str
bluetooth = models.ForeignKey(Bluetooth, on_delete=models.CASCADE, null=True)
cameras = models.ManyToManyField(Camera)
codename = models.CharField(max_length=100)
cpu = models.CharField(max_length=100)
cpu_cores = models.IntegerField(default=1)
cpu_freq = models.CharField(max_length=100)
current_branch = models.FloatField(default=None)
cpu_cores = models.CharField(max_length=100)
cpu_freq = models.CharField(max_length=1000)
current_branch = models.FloatField(default=None, null=True)
custom_recovery_link = models.URLField(max_length=200, null=True)
download_boot = models.CharField(max_length=200)
dimensions = models.JSONField(default=dict, null=True)
download_boot = models.CharField(max_length=1000)
#dimensions = models.JSONField(default=dict, null=True)
gpu = models.CharField(max_length=100)
image = models.CharField(max_length=100)
install_method = models.CharField(max_length=100)
is_ab_device = models.BooleanField(null=True)
kernel = models.CharField(max_length=100)
maintainers = ArrayField(models.CharField(max_length=100), default=None)
device_models = ArrayField(models.CharField(max_length=100), default=None)
maintainers = ArrayField(models.CharField(max_length=100), default=None, null=True)
device_models = ArrayField(models.CharField(max_length=100), default=None, null=True)
name = models.CharField(max_length=100)
network = ArrayField(models.CharField(max_length=100), default=None)
peripherals = ArrayField(models.CharField(max_length=100), default=None)
network = ArrayField(models.CharField(max_length=100), default=None, null=True)
peripherals = ArrayField(models.CharField(max_length=100, blank=True, null=True), default=None, blank=True, null=True)
ram = models.CharField(max_length=100)
recovery_boot = models.CharField(max_length=100)
recovery_boot = models.CharField(max_length=1000)
recovery_reboot = models.CharField(max_length=100)
release = models.DateField()
screen = models.JSONField(default=dict) # dict or str
sdcard = models.JSONField(default=dict) # dict or str{1}
soc = models.CharField(max_length=100)
storage = models.CharField(max_length=100)
#release = models.DateField()
#screen = models.JSONField(default=dict) # dict or str
#sdcard = models.JSONField(default=dict) # dict or str{1}
soc = models.CharField(max_length=1000)
storage = models.CharField(max_length=100, blank=True)
tree = models.CharField(max_length=100)
device_type = models.CharField(max_length=100)
uses_twrp = models.BooleanField(null=True)
vendor = models.CharField(max_length=100)
vendor_short = models.CharField(max_length=100)
versions = ArrayField(models.FloatField(default=None), default=None)
versions = ArrayField(models.FloatField(default=None), default=None, null=True)
wifi = models.CharField(max_length=200, null=True)
def __str__(self):