diff --git a/tools/python/swupdateclient/README.md b/tools/python/swupdateclient/README.md index 50bd8cf8a..5d90cd66a 100644 --- a/tools/python/swupdateclient/README.md +++ b/tools/python/swupdateclient/README.md @@ -21,12 +21,12 @@ pipenv install ### pip ``` -swupdateclient [port] +swupdateclient [port] [route] ``` ### pipenv ``` -pipenv run swupdateclient [port] +pipenv run swupdateclient [port] [route] ``` diff --git a/tools/python/swupdateclient/swupdateclient/main.py b/tools/python/swupdateclient/swupdateclient/main.py index 26e5c0bf4..28334a4f3 100644 --- a/tools/python/swupdateclient/swupdateclient/main.py +++ b/tools/python/swupdateclient/swupdateclient/main.py @@ -56,13 +56,14 @@ def format(self, record): class SWUpdater: """Python helper class for SWUpdate""" - url_upload = "http://{}:{}/upload" - url_status = "ws://{}:{}/ws" + url_upload = "http://{}:{}{}/upload" + url_status = "ws://{}:{}{}/ws" - def __init__(self, path_image, host_name, port=8080, logger=None, log_level=logging.DEBUG): + def __init__(self, path_image, host_name, port=8080, route="", logger=None, log_level=logging.DEBUG): self._image = path_image self._host_name = host_name self._port = port + self._route = route if logger is not None: self._logger = logger else: @@ -76,7 +77,7 @@ async def wait_update_finished(self): self._logger.info("Waiting for messages on websocket connection") try: async with websockets.connect( - self.url_status.format(self._host_name, self._port) + self.url_status.format(self._host_name, self._port, self._route) ) as websocket: while True: try: @@ -112,7 +113,7 @@ async def wait_update_finished(self): def sync_upload(self, swu_file, timeout): return requests.post( - self.url_upload.format(self._host_name, self._port), + self.url_upload.format(self._host_name, self._port, self._route), files={"file": swu_file}, headers={"Cache-Control": "no-cache"}, timeout=timeout, @@ -172,6 +173,13 @@ def client (args: List[str]) -> None: parser.add_argument("swu_file", help="Path to swu image") parser.add_argument("host_name", help="Host name") parser.add_argument("port", help="Port", type=int, default=8080, nargs="?") + parser.add_argument( + "route", + help="Name of the API route (e.g. /ROUTE)", + type=str, + default="", + nargs="?" + ) parser.add_argument( "--timeout", help="Timeout for the whole swupdate process", @@ -201,6 +209,7 @@ def client (args: List[str]) -> None: args.swu_file, args.host_name, args.port, + args.route, log_level=args.log_level.upper()) updater.update(timeout=args.timeout)