Compare commits

..

5 Commits

7 changed files with 28 additions and 19 deletions

View File

@ -1,6 +1,5 @@
DOMAIN=localhost
# note that with DEBUG=true, logs are more verbose (include tracebacks)
DEBUG=true
# note that DEBUG=true make snapshot parsing more verbose
DEMO=true
STATIC_ROOT=/tmp/static/

View File

@ -58,7 +58,7 @@
<div class="col-lg-9 col-md-8">{{ object.type }}</div>
</div>
{% if object.is_websnapshot %}
{% if object.is_websnapshot and object.last_user_evidence %}
{% for k, v in object.last_user_evidence %}
<div class="row mb-3">
<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")
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())
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
./manage.py print_settings
else
echo "DOMAIN: ${DOMAIN}"
fi
# detect if existing deployment (TODO only works with sqlite)

View File

@ -35,10 +35,14 @@ class UploadForm(forms.Form):
).first()
if exist_annotation:
raise ValidationError("error: {} exist".format(file_name))
raise ValidationError("Error! Snapshot: {} already exists".format(file_name))
except Exception:
raise ValidationError("error in: {}".format(file_name))
except json.JSONDecodeError:
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))

View File

@ -37,6 +37,8 @@ class Command(BaseCommand):
elif os.path.isdir(path):
self.read_directory(path)
else:
raise ValueError(f"The path {path} is neither a file nor a directory")
self.parsing()
@ -47,10 +49,18 @@ class Command(BaseCommand):
self.open(filepath)
def open(self, filepath):
with open(filepath, 'r') as file:
content = json.loads(file.read())
path_name = save_in_disk(content, self.user.institution.name)
self.snapshots.append((content, path_name))
try:
with open(filepath, 'r') as file:
content = json.loads(file.read())
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):
for s, p in self.snapshots:
@ -58,6 +68,8 @@ class Command(BaseCommand):
self.devices.append(Build(s, self.user))
move_json(p, self.user.institution.name)
except Exception as err:
if settings.DEBUG:
logger.exception("%s", err)
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)

View File

@ -1,5 +1,4 @@
import logging
from django.conf import settings
# Colors
RED = "\033[91m"
@ -25,11 +24,6 @@ class CustomFormatter(logging.Formatter):
record.msg = self.highlight_args(record.msg, record.args, color)
record.args = ()
# provide trace when DEBUG config
if settings.DEBUG:
import traceback
print(traceback.format_exc())
return super().format(record)
def highlight_args(self, message, args, color):