More fixes

This commit is contained in:
Emilia Allison 2024-01-09 17:20:55 -05:00
parent 3eb104e1e3
commit d5df4b8f3d
Signed by: emilia
GPG Key ID: 05D5D1107E5100A1
3 changed files with 135 additions and 0 deletions

20
main.py Normal file
View File

@ -0,0 +1,20 @@
from adg_control import AdgClient, ADG_EXE, ADG_DIR
from parser import Parser
def main():
parser = Parser("./test")
client = AdgClient(ADG_EXE, ADG_DIR)
c1 = parser.commands[0]
c1.execute(client)
c2 = parser.commands[1]
c2.execute(client)
c3 = parser.commands[2]
c3.execute(client)
if __name__ == "__main__":
main()

112
parser.py Normal file
View File

@ -0,0 +1,112 @@
from enum import StrEnum, auto
from adg_control import AdgClient
class CommandType(StrEnum):
NEWDB = auto(),
NORMAL = auto(),
NEWSYSTEM = auto(),
HOTEL = auto()
class Command():
def __init__(self, type: CommandType, **kwargs):
self.type = type
try:
if self.type == CommandType.NEWDB:
self._init_newdb(**kwargs)
elif self.type == CommandType.NORMAL:
self._init_normal(**kwargs)
elif self.type == CommandType.NEWSYSTEM:
self._init_system(**kwargs)
elif self.type == CommandType.HOTEL:
pass
except KeyError as e:
raise Exception("Required argument not found!", e)
def execute(self, client: AdgClient):
match self.type:
case CommandType.NEWDB:
client.create_database(self.name)
case CommandType.NORMAL:
client.create_normal_resource(
self.name,
self.location,
self.envelope,
driver_path=self.driver_path
if hasattr(self, "driver_path") else "",
package_path=self.package_path
if hasattr(self, "package_path") else "",
driver_description=self.driver_description
if hasattr(self, "driver_description") else "",
connection_parameters=self.connection_parameters
if hasattr(self, "connection_parameters") else "",
system=self.system if hasattr(self, "system") else "")
case CommandType.NEWSYSTEM:
client.create_system(
name=self.name if hasattr(self, "name") else "",
switch_ip=self.switch_ip
if hasattr(self, "switch_ip") else "",
host_name=self.host_name
if hasattr(self, "host_name") else "")
case CommandType.HOTEL:
pass
def _init_newdb(self, **kwargs):
self.name = kwargs["name"]
def _init_normal(self, **kwargs):
self.name = kwargs["name"]
self.location = kwargs["location"]
self.envelope = kwargs["envelope"]
if "driver_path" in kwargs:
self.driver_path = kwargs["driver_path"]
if "package_path" in kwargs:
self.package_path = kwargs["package_path"]
if "driver_description" in kwargs:
self.driver_description = kwargs["package_path"]
if "connection_parameters" in kwargs:
self.connection_parameters = kwargs["connection_parameters"]
if "system" in kwargs:
self.system = kwargs["system"]
def _init_system(self, **kwargs):
if "name" in kwargs:
self.name = kwargs["name"]
if "switch_ip" in kwargs:
self.switch_ip = kwargs["switch_ip"]
if "host_name" in kwargs:
self.host_name = kwargs["host_name"]
class Parser():
def __init__(self, path: str):
self.path = path
self._read_lines()
def _read_lines(self):
with open(self.path) as file:
commands = []
for line in file:
commands.append(Parser._read_line(line.strip()))
self.commands = commands
def _read_line(line: str) -> Command:
args = line.split(';')
command_type_str = args[0].lower().strip()
if command_type_str not in list(CommandType):
raise KeyError("Invalid command type found!")
type = CommandType(command_type_str)
args_dict = dict()
for arg in args[1:]:
if not arg:
continue
key, value = [x.strip() for x in arg.split('=')]
args_dict[key.lower()] = value
return Command(type, **args_dict)

3
test Normal file
View File

@ -0,0 +1,3 @@
newdb;name=horsedb
newsystem;
normal;name=PlateOrient 1.1;location=0;envelope=0;package_path=Resources\\HRB.PlateOrient_B32_maste_4.0.0.32.hrb