diff --git a/cache.py b/cache.py index feb8648..bc13602 100644 --- a/cache.py +++ b/cache.py @@ -2,7 +2,7 @@ from os import listdir, mkdir, path import re import fetch -NAME_REGEX = r'(.*\..*)(_)' +NAME_REGEX = r'(.+\..+?)(_)' class Cache: @@ -11,9 +11,9 @@ class Cache: self._cache = dict() self._scan_cache() - def get(self, name: str): + def get(self, name: str) -> str: if name in self._cache: - return path.abspath(self.dir + self._cache[name]) + return path.abspath(path.join(self.dir, self._cache[name])) try: driver = fetch.get_driver_by_exact_name(name) @@ -22,7 +22,7 @@ class Cache: raise Exception("Could not fetch driver", e) self._cache[name] = file - return path.abspath(self.dir + self._cache[name]) + return path.abspath(path.join(self.dir, self._cache[name])) def _scan_cache(self): try: diff --git a/fetch.py b/fetch.py index a40a167..179e076 100644 --- a/fetch.py +++ b/fetch.py @@ -1,4 +1,5 @@ import requests +from os import path class DriverUrl: @@ -78,7 +79,7 @@ def get_hrb_artifact_url(master_url: str) -> str: return master_url + "/lastSuccessfulBuild/artifact/" + hrb_url -def download_driver(driver: DriverUrl, output: str): +def download_driver(driver: DriverUrl, dir: str): user, token = read_credentials() master_branch_url = find_master_branch(driver) @@ -89,7 +90,11 @@ def download_driver(driver: DriverUrl, output: str): if res.status_code != 200: raise Exception("Failed to download file", res.status_code) - with open(output, 'xb') as file: + file_name = hrb_url.strip().split('/')[-1] + output_location = path.join(dir, file_name) + print("trying to save to: ", output_location) + + with open(output_location, 'xb') as file: for chunk in res.iter_content(chunk_size=128): file.write(chunk) diff --git a/main.py b/main.py index 9ba54a7..9ee44d5 100644 --- a/main.py +++ b/main.py @@ -1,19 +1,21 @@ from adg_control import AdgClient, ADG_EXE, ADG_DIR from parser import Parser +from cache import Cache def main(): parser = Parser("./test") client = AdgClient(ADG_EXE, ADG_DIR) + cache = Cache() c1 = parser.commands[0] - c1.execute(client) + c1.execute(client, cache) c2 = parser.commands[1] - c2.execute(client) + c2.execute(client, cache) c3 = parser.commands[2] - c3.execute(client) + c3.execute(client, cache) if __name__ == "__main__": diff --git a/parser.py b/parser.py index 663e024..f8c1453 100644 --- a/parser.py +++ b/parser.py @@ -1,5 +1,8 @@ from enum import StrEnum, auto from adg_control import AdgClient +from cache import Cache +import ntpath +from adg_control import ADG_DIR class CommandType(StrEnum): @@ -25,19 +28,25 @@ class Command(): except KeyError as e: raise Exception("Required argument not found!", e) - def execute(self, client: AdgClient): + def execute(self, client: AdgClient, cache: Cache): match self.type: case CommandType.NEWDB: client.create_database(self.name) 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=self.package_path - if hasattr(self, "package_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 @@ -60,6 +69,7 @@ class Command(): self.name = kwargs["name"] self.location = kwargs["location"] self.envelope = kwargs["envelope"] + self.device = kwargs["device"] if "driver_path" in kwargs: self.driver_path = kwargs["driver_path"] diff --git a/test b/test index a229455..74d3ade 100644 --- a/test +++ b/test @@ -1,3 +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 +normal;name=PlateOrient 1.1;location=0;envelope=0;device=HRB.PlateOrient