Specify device name in file to autodownload

Uses the cache from previous commits
This commit is contained in:
Emilia Allison 2024-01-11 09:49:34 -05:00
parent dfb285d239
commit 6038953471
Signed by: emilia
GPG Key ID: 05D5D1107E5100A1
5 changed files with 30 additions and 13 deletions

View File

@ -2,7 +2,7 @@ from os import listdir, mkdir, path
import re import re
import fetch import fetch
NAME_REGEX = r'(.*\..*)(_)' NAME_REGEX = r'(.+\..+?)(_)'
class Cache: class Cache:
@ -11,9 +11,9 @@ class Cache:
self._cache = dict() self._cache = dict()
self._scan_cache() self._scan_cache()
def get(self, name: str): def get(self, name: str) -> str:
if name in self._cache: if name in self._cache:
return path.abspath(self.dir + self._cache[name]) return path.abspath(path.join(self.dir, self._cache[name]))
try: try:
driver = fetch.get_driver_by_exact_name(name) driver = fetch.get_driver_by_exact_name(name)
@ -22,7 +22,7 @@ class Cache:
raise Exception("Could not fetch driver", e) raise Exception("Could not fetch driver", e)
self._cache[name] = file 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): def _scan_cache(self):
try: try:

View File

@ -1,4 +1,5 @@
import requests import requests
from os import path
class DriverUrl: class DriverUrl:
@ -78,7 +79,7 @@ def get_hrb_artifact_url(master_url: str) -> str:
return master_url + "/lastSuccessfulBuild/artifact/" + hrb_url 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() user, token = read_credentials()
master_branch_url = find_master_branch(driver) master_branch_url = find_master_branch(driver)
@ -89,7 +90,11 @@ def download_driver(driver: DriverUrl, output: str):
if res.status_code != 200: if res.status_code != 200:
raise Exception("Failed to download file", res.status_code) 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): for chunk in res.iter_content(chunk_size=128):
file.write(chunk) file.write(chunk)

View File

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

View File

@ -1,5 +1,8 @@
from enum import StrEnum, auto from enum import StrEnum, auto
from adg_control import AdgClient from adg_control import AdgClient
from cache import Cache
import ntpath
from adg_control import ADG_DIR
class CommandType(StrEnum): class CommandType(StrEnum):
@ -25,19 +28,25 @@ class Command():
except KeyError as e: except KeyError as e:
raise Exception("Required argument not found!", e) raise Exception("Required argument not found!", e)
def execute(self, client: AdgClient): def execute(self, client: AdgClient, cache: Cache):
match self.type: match self.type:
case CommandType.NEWDB: case CommandType.NEWDB:
client.create_database(self.name) client.create_database(self.name)
case CommandType.NORMAL: 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( client.create_normal_resource(
self.name, self.name,
self.location, self.location,
self.envelope, self.envelope,
driver_path=self.driver_path driver_path=self.driver_path
if hasattr(self, "driver_path") else "", if hasattr(self, "driver_path") else "",
package_path=self.package_path package_path=package_path
if hasattr(self, "package_path") else "", if not hasattr(self, "driver_description") else "",
driver_description=self.driver_description driver_description=self.driver_description
if hasattr(self, "driver_description") else "", if hasattr(self, "driver_description") else "",
connection_parameters=self.connection_parameters connection_parameters=self.connection_parameters
@ -60,6 +69,7 @@ class Command():
self.name = kwargs["name"] self.name = kwargs["name"]
self.location = kwargs["location"] self.location = kwargs["location"]
self.envelope = kwargs["envelope"] self.envelope = kwargs["envelope"]
self.device = kwargs["device"]
if "driver_path" in kwargs: if "driver_path" in kwargs:
self.driver_path = kwargs["driver_path"] self.driver_path = kwargs["driver_path"]

2
test
View File

@ -1,3 +1,3 @@
newdb;name=horsedb newdb;name=horsedb
newsystem; 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