added missing code; got deleted, probably amnesia

This commit is contained in:
Thomas Nahuel Rusiecki 2024-11-07 16:21:37 -03:00
parent cdf4771b7d
commit ae991be924
1 changed files with 21 additions and 4 deletions

View File

@ -1,12 +1,18 @@
import os import os
import json import json
import logging
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.conf import settings
from utils.save_snapshots import move_json, save_in_disk
from evidence.parse import Build from evidence.parse import Build
logger = logging.getLogger('django')
User = get_user_model() User = get_user_model()
@ -31,9 +37,11 @@ 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()
def read_directory(self, directory): def read_directory(self, directory):
for filename in os.listdir(directory): for filename in os.listdir(directory):
filepath = os.path.join(directory, filename) filepath = os.path.join(directory, filename)
@ -53,6 +61,15 @@ class Command(BaseCommand):
except Exception: except Exception:
raise Exception(f"Oops! Something went wrong there") raise Exception(f"Oops! Something went wrong there")
def parsing(self): def parsing(self):
for s in self.snapshots: for s, p in self.snapshots:
self.devices.append(Build(s, self.user)) try:
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 = "It is not possible to parse snapshot: %s"
logger.error(txt, snapshot_id)