Compare commits

..

5 Commits

7 changed files with 28 additions and 19 deletions

View File

@ -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/

View File

@ -58,7 +58,7 @@
<div class="col-lg-9 col-md-8">{{ object.type }}</div> <div class="col-lg-9 col-md-8">{{ object.type }}</div>
</div> </div>
{% if object.is_websnapshot %} {% if object.is_websnapshot and object.last_user_evidence %}
{% for k, v in object.last_user_evidence %} {% for k, v in object.last_user_evidence %}
<div class="row mb-3"> <div class="row mb-3">
<div class="col-lg-3 col-md-4 label">{{ k }}</div> <div class="col-lg-3 col-md-4 label">{{ k }}</div>

View File

@ -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}"

View File

@ -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)

View File

@ -35,10 +35,14 @@ class UploadForm(forms.Form):
).first() ).first()
if exist_annotation: if exist_annotation:
raise ValidationError("error: {} exist".format(file_name)) raise ValidationError("Error! Snapshot: {} already exists".format(file_name))
except Exception: except json.JSONDecodeError:
raise ValidationError("error in: {}".format(file_name)) raise ValidationError("Error in parsing JSON: '{}'. Check for file integrity.".format(file_name))
except ValidationError as e:
raise e
except Exception as e:
raise ValidationError("Oops! Something went wrong in '{}': {}".format(file_name, str(e)))
self.evidences.append((file_name, file_json)) self.evidences.append((file_name, file_json))

View File

@ -37,6 +37,8 @@ class Command(BaseCommand):
elif os.path.isdir(path): elif os.path.isdir(path):
self.read_directory(path) self.read_directory(path)
else:
raise ValueError(f"The path {path} is neither a file nor a directory")
self.parsing() self.parsing()
@ -47,10 +49,18 @@ class Command(BaseCommand):
self.open(filepath) self.open(filepath)
def open(self, filepath): def open(self, filepath):
with open(filepath, 'r') as file: try:
content = json.loads(file.read()) with open(filepath, 'r') as file:
path_name = save_in_disk(content, self.user.institution.name) content = json.loads(file.read())
self.snapshots.append((content, path_name)) path_name = save_in_disk(content, self.user.institution.name)
self.snapshots.append((content, path_name))
except json.JSONDecodeError as e:
raise e
#or we cath'em all
except Exception:
raise Exception(f"Oops! Something went wrong there")
def parsing(self): def parsing(self):
for s, p in self.snapshots: for s, p in self.snapshots:
@ -58,6 +68,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)

View File

@ -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):