Compare commits
3 Commits
main
...
96-add-ser
Author | SHA1 | Date |
---|---|---|
sergio_gimenez | 915d95379c | |
sergio_gimenez | 8cb66104ca | |
sergio_gimenez | 7db879e189 |
|
@ -1,6 +1,5 @@
|
||||||
DOMAIN=localhost
|
DOMAIN=localhost
|
||||||
# note that with DEBUG=true, logs are more verbose (include tracebacks)
|
# note that DEBUG=true make snapshot parsing more verbose
|
||||||
DEBUG=true
|
|
||||||
DEMO=true
|
DEMO=true
|
||||||
|
|
||||||
STATIC_ROOT=/tmp/static/
|
STATIC_ROOT=/tmp/static/
|
||||||
|
|
|
@ -29,7 +29,7 @@ class Device:
|
||||||
self.shortid = self.pk[:6].upper()
|
self.shortid = self.pk[:6].upper()
|
||||||
self.algorithm = None
|
self.algorithm = None
|
||||||
self.owner = None
|
self.owner = None
|
||||||
self.annotations = []
|
self.annotations = []
|
||||||
self.hids = []
|
self.hids = []
|
||||||
self.uuids = []
|
self.uuids = []
|
||||||
self.evidences = []
|
self.evidences = []
|
||||||
|
@ -108,7 +108,7 @@ class Device:
|
||||||
return
|
return
|
||||||
annotation = annotations.first()
|
annotation = annotations.first()
|
||||||
self.last_evidence = Evidence(annotation.uuid)
|
self.last_evidence = Evidence(annotation.uuid)
|
||||||
|
|
||||||
def is_eraseserver(self):
|
def is_eraseserver(self):
|
||||||
if not self.uuids:
|
if not self.uuids:
|
||||||
self.get_uuids()
|
self.get_uuids()
|
||||||
|
@ -120,7 +120,7 @@ class Device:
|
||||||
owner=self.owner,
|
owner=self.owner,
|
||||||
type=Annotation.Type.ERASE_SERVER
|
type=Annotation.Type.ERASE_SERVER
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if annotation:
|
if annotation:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -129,7 +129,8 @@ class Device:
|
||||||
return self.uuids[0]
|
return self.uuids[0]
|
||||||
|
|
||||||
def get_lots(self):
|
def get_lots(self):
|
||||||
self.lots = [x.lot for x in DeviceLot.objects.filter(device_id=self.id)]
|
self.lots = [
|
||||||
|
x.lot for x in DeviceLot.objects.filter(device_id=self.id)]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_unassigned(cls, institution, offset=0, limit=None):
|
def get_unassigned(cls, institution, offset=0, limit=None):
|
||||||
|
@ -179,7 +180,6 @@ class Device:
|
||||||
count = cls.get_unassigned_count(institution)
|
count = cls.get_unassigned_count(institution)
|
||||||
return devices, count
|
return devices, count
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_unassigned_count(cls, institution):
|
def get_unassigned_count(cls, institution):
|
||||||
|
|
||||||
|
@ -279,6 +279,12 @@ class Device:
|
||||||
self.get_last_evidence()
|
self.get_last_evidence()
|
||||||
return self.last_evidence.get_manufacturer()
|
return self.last_evidence.get_manufacturer()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def serial_number(self):
|
||||||
|
if not self.last_evidence:
|
||||||
|
self.get_last_evidence()
|
||||||
|
return self.last_evidence.get_serial_number()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
if self.last_evidence.doc['type'] == "WebSnapshot":
|
if self.last_evidence.doc['type'] == "WebSnapshot":
|
||||||
|
|
|
@ -84,7 +84,7 @@
|
||||||
<div class="col-lg-3 col-md-4 label">
|
<div class="col-lg-3 col-md-4 label">
|
||||||
{% trans 'Serial Number' %}
|
{% trans 'Serial Number' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-9 col-md-8">{{ object.last_evidence.doc.device.serialNumber|default:'' }}</div>
|
<div class="col-lg-9 col-md-8">{{ object.serial_number|default:'' }}</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ DEBUG = config('DEBUG', default=False, cast=bool)
|
||||||
|
|
||||||
DOMAIN = config("DOMAIN")
|
DOMAIN = config("DOMAIN")
|
||||||
assert DOMAIN not in [None, ''], "DOMAIN var is MANDATORY"
|
assert DOMAIN not in [None, ''], "DOMAIN var is MANDATORY"
|
||||||
|
# this var is very important, we print it
|
||||||
|
print("DOMAIN: " + DOMAIN)
|
||||||
|
|
||||||
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=DOMAIN, cast=Csv())
|
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=DOMAIN, cast=Csv())
|
||||||
assert DOMAIN in ALLOWED_HOSTS, f"DOMAIN {DOMAIN} is not in ALLOWED_HOSTS {ALLOWED_HOSTS}"
|
assert DOMAIN in ALLOWED_HOSTS, f"DOMAIN {DOMAIN} is not in ALLOWED_HOSTS {ALLOWED_HOSTS}"
|
||||||
|
|
|
@ -18,8 +18,6 @@ deploy() {
|
||||||
|
|
||||||
if [ "${DEBUG:-}" = 'true' ]; then
|
if [ "${DEBUG:-}" = 'true' ]; then
|
||||||
./manage.py print_settings
|
./manage.py print_settings
|
||||||
else
|
|
||||||
echo "DOMAIN: ${DOMAIN}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# detect if existing deployment (TODO only works with sqlite)
|
# detect if existing deployment (TODO only works with sqlite)
|
||||||
|
|
|
@ -58,6 +58,8 @@ class Command(BaseCommand):
|
||||||
self.devices.append(Build(s, self.user))
|
self.devices.append(Build(s, self.user))
|
||||||
move_json(p, self.user.institution.name)
|
move_json(p, self.user.institution.name)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
if settings.DEBUG:
|
||||||
|
logger.exception("%s", err)
|
||||||
snapshot_id = s.get("uuid", "")
|
snapshot_id = s.get("uuid", "")
|
||||||
txt = "Could not parse snapshot: %s"
|
txt = "It is not possible to parse snapshot: %s"
|
||||||
logger.error(txt, snapshot_id)
|
logger.error(txt, snapshot_id)
|
||||||
|
|
|
@ -11,7 +11,7 @@ from user.models import User, Institution
|
||||||
|
|
||||||
class Annotation(models.Model):
|
class Annotation(models.Model):
|
||||||
class Type(models.IntegerChoices):
|
class Type(models.IntegerChoices):
|
||||||
SYSTEM= 0, "System"
|
SYSTEM = 0, "System"
|
||||||
USER = 1, "User"
|
USER = 1, "User"
|
||||||
DOCUMENT = 2, "Document"
|
DOCUMENT = 2, "Document"
|
||||||
ERASE_SERVER = 3, "EraseServer"
|
ERASE_SERVER = 3, "EraseServer"
|
||||||
|
@ -19,14 +19,16 @@ class Annotation(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
uuid = models.UUIDField()
|
uuid = models.UUIDField()
|
||||||
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
||||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
user = models.ForeignKey(
|
||||||
type = models.SmallIntegerField(choices=Type)
|
User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||||
|
type = models.SmallIntegerField(choices=Type)
|
||||||
key = models.CharField(max_length=STR_EXTEND_SIZE)
|
key = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||||
value = models.CharField(max_length=STR_EXTEND_SIZE)
|
value = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
constraints = [
|
constraints = [
|
||||||
models.UniqueConstraint(fields=["type", "key", "uuid"], name="unique_type_key_uuid")
|
models.UniqueConstraint(
|
||||||
|
fields=["type", "key", "uuid"], name="unique_type_key_uuid")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,8 +39,8 @@ class Evidence:
|
||||||
self.doc = None
|
self.doc = None
|
||||||
self.created = None
|
self.created = None
|
||||||
self.dmi = None
|
self.dmi = None
|
||||||
self.annotations = []
|
self.annotations = []
|
||||||
self.components = []
|
self.components = []
|
||||||
self.default = "n/a"
|
self.default = "n/a"
|
||||||
|
|
||||||
self.get_owner()
|
self.get_owner()
|
||||||
|
@ -87,7 +89,7 @@ class Evidence:
|
||||||
return self.components
|
return self.components
|
||||||
|
|
||||||
def get_manufacturer(self):
|
def get_manufacturer(self):
|
||||||
if self.doc.get("type") == "WebSnapshot":
|
if self.is_new_snapshot():
|
||||||
kv = self.doc.get('kv', {})
|
kv = self.doc.get('kv', {})
|
||||||
if len(kv) < 1:
|
if len(kv) < 1:
|
||||||
return ""
|
return ""
|
||||||
|
@ -99,7 +101,7 @@ class Evidence:
|
||||||
return self.dmi.manufacturer().strip()
|
return self.dmi.manufacturer().strip()
|
||||||
|
|
||||||
def get_model(self):
|
def get_model(self):
|
||||||
if self.doc.get("type") == "WebSnapshot":
|
if self.is_new_snapshot():
|
||||||
kv = self.doc.get('kv', {})
|
kv = self.doc.get('kv', {})
|
||||||
if len(kv) < 2:
|
if len(kv) < 2:
|
||||||
return ""
|
return ""
|
||||||
|
@ -122,6 +124,11 @@ class Evidence:
|
||||||
return k
|
return k
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def get_serial_number(self):
|
||||||
|
if self.is_legacy():
|
||||||
|
return self.doc['device']['serialNumber']
|
||||||
|
return self.dmi.serial_number().strip()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all(cls, user):
|
def get_all(cls, user):
|
||||||
return Annotation.objects.filter(
|
return Annotation.objects.filter(
|
||||||
|
@ -136,3 +143,6 @@ class Evidence:
|
||||||
|
|
||||||
def is_legacy(self):
|
def is_legacy(self):
|
||||||
return self.doc.get("software") != "workbench-script"
|
return self.doc.get("software") != "workbench-script"
|
||||||
|
|
||||||
|
def is_new_snapshot(self):
|
||||||
|
return self.doc.get("type") == "WebSnapshot"
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import logging
|
import logging
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
# Colors
|
# Colors
|
||||||
RED = "\033[91m"
|
RED = "\033[91m"
|
||||||
|
@ -25,11 +24,6 @@ class CustomFormatter(logging.Formatter):
|
||||||
record.msg = self.highlight_args(record.msg, record.args, color)
|
record.msg = self.highlight_args(record.msg, record.args, color)
|
||||||
record.args = ()
|
record.args = ()
|
||||||
|
|
||||||
# provide trace when DEBUG config
|
|
||||||
if settings.DEBUG:
|
|
||||||
import traceback
|
|
||||||
print(traceback.format_exc())
|
|
||||||
|
|
||||||
return super().format(record)
|
return super().format(record)
|
||||||
|
|
||||||
def highlight_args(self, message, args, color):
|
def highlight_args(self, message, args, color):
|
||||||
|
|
Loading…
Reference in New Issue