"""convenience objects
"""
import json
from argparse import ArgumentParser
from dataclasses import dataclass
[docs]@dataclass
class ContainerDescriptor:
"""Class for keeping track of the properties of a container."""
image: str = None
volumes: dict = None
working_dir: str = None
detached: bool = False
[docs] @staticmethod
def argument_parser(parser: ArgumentParser) -> ArgumentParser:
"""Populate a parser with the configuration required to build an instance
Args:
parser (ArgumentParser): Current Parser
Returns:
ArgumentParser: Parser with the configuration additions
"""
parser.add_argument(
"-i", "--image", help="Docker image to use for command", type=str
)
parser.add_argument(
"-v",
"--volumes",
help='dictionary for volume mounting, \
{ local-directory : { "bind": container-directory, "mode": "rw" } }',
type=str,
)
parser.add_argument(
"-w", "--working_dir", help="working directory", type=str
)
parser.add_argument(
"-d", "--detach", help="Run detached", type=bool, default=False
)
return parser
[docs] @classmethod
def from_parser(cls, parser: ArgumentParser):
"""Instantiate a ContainerDescritor from an ArgumentParser
Args:
parser (ArgumentParser): parser with an image, working_dir and volumes
Returns:
ContainerDescriptor
"""
args = parser.parse_args()
volumes_dict = None
if args.volumes is not None:
volumes_dict = json.loads(args.volumes)
instance = cls(
image=args.image,
volumes=volumes_dict,
working_dir=args.working_dir,
detached=args.detach,
)
return instance
[docs]@dataclass
class SourceDescriptor:
"""Class that holds the position and flux of a source. Other parameters may be
added later"""
r_a: float
dec: float
flux: float