# HG changeset patch # User Goffi # Date 1665064925 -7200 # Node ID 1877c5c477ecccd971cbd7ee335e603539b4360e # Parent 900bf04d87c8832309b8fbd3c4962b76c08196df cli (file/get): handle full JSON attachment following change in backend: rel 379 diff -r 900bf04d87c8 -r 1877c5c477ec sat_frontends/jp/cmd_file.py --- a/sat_frontends/jp/cmd_file.py Thu Oct 06 16:02:05 2022 +0200 +++ b/sat_frontends/jp/cmd_file.py Thu Oct 06 16:02:05 2022 +0200 @@ -38,6 +38,7 @@ import json __commands__ = ["File"] +DEFAULT_DEST = "downloaded_file" class Send(base.CommandBase): @@ -475,7 +476,10 @@ action="store_true", help=_("overwrite existing file without confirmation"), ) - self.parser.add_argument("uri", type=str, help=_("URI of the file to retrieve")) + self.parser.add_argument( + "attachment", type=str, + help=_("URI of the file to retrieve or JSON of the whole attachment") + ) async def onProgressStarted(self, metadata): self.disp(_("File download started"), 2) @@ -499,11 +503,21 @@ self.host.quit(C.EXIT_ERROR) async def start(self): - uri = self.args.uri + try: + attachment = json.loads(self.args.attachment) + except json.JSONDecodeError: + attachment = {"uri": self.args.attachment} dest_file = self.args.dest_file if not dest_file: - parsed_uri = urlparse(uri) - dest_file = Path(parsed_uri.path).name.strip() or "downloaded_file" + try: + dest_file = attachment["name"].replace("/", "-").strip() + except KeyError: + try: + dest_file = Path(urlparse(attachment["uri"]).path).name.strip() + except KeyError: + pass + if not dest_file: + dest_file = "downloaded_file" dest_file = Path(dest_file).expanduser().resolve() if dest_file.exists() and not self.args.force: @@ -515,12 +529,13 @@ options = {} try: - download_data = await self.host.bridge.fileDownload( - uri, + download_data_s = await self.host.bridge.fileDownload( + data_format.serialise(attachment), str(dest_file), data_format.serialise(options), self.profile, ) + download_data = data_format.deserialise(download_data_s) except Exception as e: self.disp(f"error while trying to download a file: {e}", error=True) self.host.quit(C.EXIT_BRIDGE_ERRBACK)