Skip to content
Snippets Groups Projects
Commit 4d786346 authored by Charlotte Hausman's avatar Charlotte Hausman
Browse files

removed ssa-workspaces dependency

parent 7c6de14c
No related branches found
No related tags found
1 merge request!218removed ssa-workspaces dependency
Pipeline #1513 passed
......@@ -9,7 +9,7 @@ from bs4 import BeautifulSoup
import json
from casa_envoy.interfaces import AuditorIF
from workspaces.system.schema import AbstractFile
from casa_envoy.schema import AbstractTextFile
def get_fields_for(filename: str) -> list:
......@@ -23,7 +23,7 @@ def get_fields_for(filename: str) -> list:
return metadata_list
def get_value_for(filename:str, key:str) -> str:
def get_value_for(filename: str, key: str) -> str:
if ".xml" in filename:
with open(filename) as file:
ppr_content = BeautifulSoup(file.read(), "xml")
......@@ -40,21 +40,21 @@ class AuditFiles(AuditorIF):
self.files = files
self.logger = logging.getLogger("vela")
def read_file(self, filename: str) -> AbstractFile:
def read_file(self, filename: str) -> AbstractTextFile:
if os.path.isfile(filename):
with open(filename) as file:
if ".json" in filename:
metadata = json.loads(file.read())
return AbstractFile(filename, json.dumps(metadata).encode('ascii'))
return AbstractTextFile(filename, json.dumps(metadata))
else:
if ".xml" in filename:
ppr = file.read()
return AbstractFile(filename, ppr.encode('ascii'))
return AbstractTextFile(filename, ppr)
def check_required_fields(self, file: AbstractFile, fields: list) -> bool:
def check_required_fields(self, file: AbstractTextFile, fields: list) -> bool:
missing = []
if ".xml" in file.filename:
ppr_content = BeautifulSoup(file.content.decode(), "xml")
ppr_content = BeautifulSoup(file.content, "xml")
for tag in fields:
try:
ppr_content.find(tag).string
......@@ -63,7 +63,7 @@ class AuditFiles(AuditorIF):
if ".json" in file.filename:
for tag in fields:
metadata = json.loads(file.content.decode())
metadata = json.loads(file.content)
if tag not in metadata or len(metadata[tag]) == 0:
missing.append(tag)
if len(missing) > 0:
......
......@@ -13,7 +13,7 @@ import json
from casa_envoy.auditor import AuditDirectories, AuditFiles
from casa_envoy.interfaces import CasaLauncherIF
from workspaces.system.schema import AbstractFile
from casa_envoy.schema import AbstractTextFile
from pycapo import CapoConfig
import sys
import os
......@@ -30,7 +30,7 @@ logger.addHandler(logging.StreamHandler(sys.stdout))
class CalibrationLauncher(CasaLauncherIF):
def __init__(self, ppr: AbstractFile, metadata: AbstractFile):
def __init__(self, ppr: AbstractTextFile, metadata: AbstractTextFile):
self.ppr = ppr
self.metadata = metadata
......
from __future__ import annotations
from pathlib import Path
"""
Adapted from shared/system to avoid including ssa-workspaces in pex
"""
class JSONSerializable:
def __json__(self, request=None) -> dict:
"""
Allows this object to be converted to JSON
:param request: this parameter is the active Pyramid request, if applicable (None otherwise)
:return: a dictionary which can be converted to JSON using json.dump
"""
pass
@classmethod
def from_json(cls, json: dict) -> any:
pass
class AbstractTextFile(JSONSerializable):
"""
Abstract text file is exactly that, an abstract concept of what a file is, to be
returned from various non-filesystem places.
"""
def __init__(self, filename: str, content: str):
self.filename, self.content = filename, content
def write_to(self, directory: Path):
(directory / self.filename).write_text(self.content)
@classmethod
def from_path(cls, path: Path) -> AbstractTextFile:
return cls(path.name, path.read_text())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment