Refactor parser

Move all execution code into separate functions
This commit is contained in:
Emilia Allison 2024-01-11 09:54:34 -05:00
parent 6038953471
commit 4e4b9f6d1d
Signed by: emilia
GPG Key ID: 05D5D1107E5100A1
1 changed files with 35 additions and 26 deletions

View File

@ -31,34 +31,11 @@ class Command():
def execute(self, client: AdgClient, cache: Cache):
match self.type:
case CommandType.NEWDB:
client.create_database(self.name)
self._execute_newdb(client, cache)
case CommandType.NORMAL:
if hasattr(self, "package_path"):
package_path = self.package_path
else:
abs_path = cache.get(self.device)
package_path = ntpath.relpath(abs_path, start=ADG_DIR)
client.create_normal_resource(
self.name,
self.location,
self.envelope,
driver_path=self.driver_path
if hasattr(self, "driver_path") else "",
package_path=package_path
if not hasattr(self, "driver_description") 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 "")
self._execute_normal(client, cache)
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 "")
self._execute_newsystem(client, cache)
case CommandType.HOTEL:
pass
@ -90,6 +67,38 @@ class Command():
if "host_name" in kwargs:
self.host_name = kwargs["host_name"]
def _execute_newdb(self, client: AdgClient, cache: Cache):
client.create_database(self.name)
def _execute_newsystem(self, client: AdgClient, cache: Cache):
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 "")
def _execute_normal(self, client: AdgClient, cache: Cache):
if hasattr(self, "package_path"):
package_path = self.package_path
else:
abs_path = cache.get(self.device)
package_path = ntpath.relpath(abs_path, start=ADG_DIR)
client.create_normal_resource(
self.name,
self.location,
self.envelope,
driver_path=self.driver_path
if hasattr(self, "driver_path") else "",
package_path=package_path
if not hasattr(self, "driver_description") 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 "")
class Parser():
def __init__(self, path: str):