Specify device name in file to autodownload
Uses the cache from previous commits
This commit is contained in:
parent
dfb285d239
commit
6038953471
8
cache.py
8
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:
|
||||
|
|
9
fetch.py
9
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)
|
||||
|
||||
|
|
8
main.py
8
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__":
|
||||
|
|
16
parser.py
16
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"]
|
||||
|
|
Loading…
Reference in New Issue