diff --git a/main.py b/main.py index 9ee44d5..ff2e537 100644 --- a/main.py +++ b/main.py @@ -8,14 +8,8 @@ def main(): client = AdgClient(ADG_EXE, ADG_DIR) cache = Cache() - c1 = parser.commands[0] - c1.execute(client, cache) - - c2 = parser.commands[1] - c2.execute(client, cache) - - c3 = parser.commands[2] - c3.execute(client, cache) + for command in parser.commands: + command.execute(client, cache) if __name__ == "__main__": diff --git a/parser.py b/parser.py index be93f7e..f376571 100644 --- a/parser.py +++ b/parser.py @@ -2,7 +2,7 @@ from enum import StrEnum, auto from adg_control import AdgClient from cache import Cache import ntpath -from adg_control import ADG_DIR +from adg_control import ADG_DIR, StorageType class CommandType(StrEnum): @@ -24,7 +24,7 @@ class Command(): elif self.type == CommandType.NEWSYSTEM: self._init_system(**kwargs) elif self.type == CommandType.HOTEL: - pass + self._init_hotel(**kwargs) except KeyError as e: raise Exception("Required argument not found!", e) @@ -37,7 +37,7 @@ class Command(): case CommandType.NEWSYSTEM: self._execute_newsystem(client, cache) case CommandType.HOTEL: - pass + self._execute_hotel(client, cache) def _init_newdb(self, **kwargs): self.name = kwargs["name"] @@ -59,6 +59,22 @@ class Command(): if "system" in kwargs: self.system = kwargs["system"] + def _init_hotel(self, **kwargs): + self.name = kwargs["name"] + self.location = kwargs["location"] + self.envelope = kwargs["location"] + + if "rows" in kwargs: + self.rows = int(kwargs["rows"]) + if "storage_type" in kwargs: + storage_type_str = kwargs["storage_type"] + if storage_type_str in list(StorageType): + self.storage_type = StorageType(storage_type_str) + else: + raise ValueError("StorageType passed was invalid: " + + f"{storage_type_str} not in " + + "{RANDOM,SERIAL}") + def _init_system(self, **kwargs): if "name" in kwargs: self.name = kwargs["name"] @@ -99,6 +115,15 @@ class Command(): if hasattr(self, "connection_parameters") else "", system=self.system if hasattr(self, "system") else "") + def _execute_hotel(self, client: AdgClient, cache: Cache): + client.create_platehotel( + self.name, + self.location, + self.envelope, + rows=self.rows if hasattr(self, "rows") else -1, + type=self.storage_type if hasattr(self, "storage_type") else None + ) + class Parser(): def __init__(self, path: str): diff --git a/test b/test index 74d3ade..e223b47 100644 --- a/test +++ b/test @@ -1,3 +1,4 @@ newdb;name=horsedb newsystem; -normal;name=PlateOrient 1.1;location=0;envelope=0;device=HRB.PlateOrient +normal;name=PlateOrient 1.1;location=0;envelope=1;device=HRB.PlateOrient +hotel;name=PlateHotel 1.1;location=100;envelope=1;rows=8;storage_type=random