comparison sat_frontends/jp/cmd_file.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents 4c3361e2bf55
children 2594e1951cf7
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
80 "--encrypt", 80 "--encrypt",
81 action="store_true", 81 action="store_true",
82 help=_("end-to-end encrypt the file transfer") 82 help=_("end-to-end encrypt the file transfer")
83 ) 83 )
84 84
85 async def onProgressStarted(self, metadata): 85 async def on_progress_started(self, metadata):
86 self.disp(_("File copy started"), 2) 86 self.disp(_("File copy started"), 2)
87 87
88 async def onProgressFinished(self, metadata): 88 async def on_progress_finished(self, metadata):
89 self.disp(_("File sent successfully"), 2) 89 self.disp(_("File sent successfully"), 2)
90 90
91 async def onProgressError(self, error_msg): 91 async def on_progress_error(self, error_msg):
92 if error_msg == C.PROGRESS_ERROR_DECLINED: 92 if error_msg == C.PROGRESS_ERROR_DECLINED:
93 self.disp(_("The file has been refused by your contact")) 93 self.disp(_("The file has been refused by your contact"))
94 else: 94 else:
95 self.disp(_("Error while sending file: {}").format(error_msg), error=True) 95 self.disp(_("Error while sending file: {}").format(error_msg), error=True)
96 96
97 async def gotId(self, data, file_): 97 async def got_id(self, data, file_):
98 """Called when a progress id has been received 98 """Called when a progress id has been received
99 99
100 @param pid(unicode): progress id 100 @param pid(unicode): progress id
101 @param file_(str): file path 101 @param file_(str): file path
102 """ 102 """
132 if self.args.encrypt: 132 if self.args.encrypt:
133 extra["encrypted"] = True 133 extra["encrypted"] = True
134 134
135 if self.args.bz2: 135 if self.args.bz2:
136 with tempfile.NamedTemporaryFile("wb", delete=False) as buf: 136 with tempfile.NamedTemporaryFile("wb", delete=False) as buf:
137 self.host.addOnQuitCallback(os.unlink, buf.name) 137 self.host.add_on_quit_callback(os.unlink, buf.name)
138 self.disp(_("bz2 is an experimental option, use with caution")) 138 self.disp(_("bz2 is an experimental option, use with caution"))
139 # FIXME: check free space 139 # FIXME: check free space
140 self.disp(_("Starting compression, please wait...")) 140 self.disp(_("Starting compression, please wait..."))
141 sys.stdout.flush() 141 sys.stdout.flush()
142 bz2 = tarfile.open(mode="w:bz2", fileobj=buf) 142 bz2 = tarfile.open(mode="w:bz2", fileobj=buf)
148 bz2.add(file_) 148 bz2.add(file_)
149 bz2.close() 149 bz2.close()
150 self.disp(_("Done !"), 1) 150 self.disp(_("Done !"), 1)
151 151
152 try: 152 try:
153 send_data = await self.host.bridge.fileSend( 153 send_data = await self.host.bridge.file_send(
154 self.args.jid, 154 self.args.jid,
155 buf.name, 155 buf.name,
156 self.args.name or archive_name, 156 self.args.name or archive_name,
157 "", 157 "",
158 data_format.serialise(extra), 158 data_format.serialise(extra),
160 ) 160 )
161 except Exception as e: 161 except Exception as e:
162 self.disp(f"can't send file: {e}", error=True) 162 self.disp(f"can't send file: {e}", error=True)
163 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 163 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
164 else: 164 else:
165 await self.gotId(send_data, file_) 165 await self.got_id(send_data, file_)
166 else: 166 else:
167 for file_ in self.args.files: 167 for file_ in self.args.files:
168 path = os.path.abspath(file_) 168 path = os.path.abspath(file_)
169 try: 169 try:
170 send_data = await self.host.bridge.fileSend( 170 send_data = await self.host.bridge.file_send(
171 self.args.jid, 171 self.args.jid,
172 path, 172 path,
173 self.args.name, 173 self.args.name,
174 "", 174 "",
175 data_format.serialise(extra), 175 data_format.serialise(extra),
177 ) 177 )
178 except Exception as e: 178 except Exception as e:
179 self.disp(f"can't send file {file_!r}: {e}", error=True) 179 self.disp(f"can't send file {file_!r}: {e}", error=True)
180 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 180 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
181 else: 181 else:
182 await self.gotId(send_data, file_) 182 await self.got_id(send_data, file_)
183 183
184 184
185 class Request(base.CommandBase): 185 class Request(base.CommandBase):
186 def __init__(self, host): 186 def __init__(self, host):
187 super(Request, self).__init__( 187 super(Request, self).__init__(
239 "--force", 239 "--force",
240 action="store_true", 240 action="store_true",
241 help=_("overwrite existing file without confirmation"), 241 help=_("overwrite existing file without confirmation"),
242 ) 242 )
243 243
244 async def onProgressStarted(self, metadata): 244 async def on_progress_started(self, metadata):
245 self.disp(_("File copy started"), 2) 245 self.disp(_("File copy started"), 2)
246 246
247 async def onProgressFinished(self, metadata): 247 async def on_progress_finished(self, metadata):
248 self.disp(_("File received successfully"), 2) 248 self.disp(_("File received successfully"), 2)
249 249
250 async def onProgressError(self, error_msg): 250 async def on_progress_error(self, error_msg):
251 if error_msg == C.PROGRESS_ERROR_DECLINED: 251 if error_msg == C.PROGRESS_ERROR_DECLINED:
252 self.disp(_("The file request has been refused")) 252 self.disp(_("The file request has been refused"))
253 else: 253 else:
254 self.disp(_("Error while requesting file: {}").format(error_msg), error=True) 254 self.disp(_("Error while requesting file: {}").format(error_msg), error=True)
255 255
265 265
266 if os.path.exists(path) and not self.args.force: 266 if os.path.exists(path) and not self.args.force:
267 message = _("File {path} already exists! Do you want to overwrite?").format( 267 message = _("File {path} already exists! Do you want to overwrite?").format(
268 path=path 268 path=path
269 ) 269 )
270 await self.host.confirmOrQuit(message, _("file request cancelled")) 270 await self.host.confirm_or_quit(message, _("file request cancelled"))
271 271
272 self.full_dest_jid = await self.host.get_full_jid(self.args.jid) 272 self.full_dest_jid = await self.host.get_full_jid(self.args.jid)
273 extra = {} 273 extra = {}
274 if self.args.path: 274 if self.args.path:
275 extra["path"] = self.args.path 275 extra["path"] = self.args.path
276 if self.args.namespace: 276 if self.args.namespace:
277 extra["namespace"] = self.args.namespace 277 extra["namespace"] = self.args.namespace
278 try: 278 try:
279 progress_id = await self.host.bridge.fileJingleRequest( 279 progress_id = await self.host.bridge.file_jingle_request(
280 self.full_dest_jid, 280 self.full_dest_jid,
281 path, 281 path,
282 self.args.name, 282 self.args.name,
283 self.args.hash, 283 self.args.hash,
284 self.args.hash_algo if self.args.hash else "", 284 self.args.hash_algo if self.args.hash else "",
301 use_verbose=True, 301 use_verbose=True,
302 help=_("wait for a file to be sent by a contact"), 302 help=_("wait for a file to be sent by a contact"),
303 ) 303 )
304 self._overwrite_refused = False # True when one overwrite as already been refused 304 self._overwrite_refused = False # True when one overwrite as already been refused
305 self.action_callbacks = { 305 self.action_callbacks = {
306 C.META_TYPE_FILE: self.onFileAction, 306 C.META_TYPE_FILE: self.on_file_action,
307 C.META_TYPE_OVERWRITE: self.onOverwriteAction, 307 C.META_TYPE_OVERWRITE: self.on_overwrite_action,
308 C.META_TYPE_NOT_IN_ROSTER_LEAK: self.onNotInRosterAction, 308 C.META_TYPE_NOT_IN_ROSTER_LEAK: self.on_not_in_roster_action,
309 } 309 }
310 310
311 def add_parser_options(self): 311 def add_parser_options(self):
312 self.parser.add_argument( 312 self.parser.add_argument(
313 "jids", 313 "jids",
333 default=".", 333 default=".",
334 metavar="DIR", 334 metavar="DIR",
335 help=_("destination path (default: working directory)"), 335 help=_("destination path (default: working directory)"),
336 ) 336 )
337 337
338 async def onProgressStarted(self, metadata): 338 async def on_progress_started(self, metadata):
339 self.disp(_("File copy started"), 2) 339 self.disp(_("File copy started"), 2)
340 340
341 async def onProgressFinished(self, metadata): 341 async def on_progress_finished(self, metadata):
342 self.disp(_("File received successfully"), 2) 342 self.disp(_("File received successfully"), 2)
343 if metadata.get("hash_verified", False): 343 if metadata.get("hash_verified", False):
344 try: 344 try:
345 self.disp( 345 self.disp(
346 _("hash checked: {metadata['hash_algo']}:{metadata['hash']}"), 1 346 _("hash checked: {metadata['hash_algo']}:{metadata['hash']}"), 1
348 except KeyError: 348 except KeyError:
349 self.disp(_("hash is checked but hash value is missing", 1), error=True) 349 self.disp(_("hash is checked but hash value is missing", 1), error=True)
350 else: 350 else:
351 self.disp(_("hash can't be verified"), 1) 351 self.disp(_("hash can't be verified"), 1)
352 352
353 async def onProgressError(self, e): 353 async def on_progress_error(self, e):
354 self.disp(_("Error while receiving file: {e}").format(e=e), error=True) 354 self.disp(_("Error while receiving file: {e}").format(e=e), error=True)
355 355
356 def getXmluiId(self, action_data): 356 def get_xmlui_id(self, action_data):
357 # FIXME: we temporarily use ElementTree, but a real XMLUI managing module 357 # FIXME: we temporarily use ElementTree, but a real XMLUI managing module
358 # should be available in the futur 358 # should be available in the futur
359 # TODO: XMLUI module 359 # TODO: XMLUI module
360 try: 360 try:
361 xml_ui = action_data["xmlui"] 361 xml_ui = action_data["xmlui"]
366 xmlui_id = ui.get("submit") 366 xmlui_id = ui.get("submit")
367 if not xmlui_id: 367 if not xmlui_id:
368 self.disp(_("Invalid XMLUI received"), error=True) 368 self.disp(_("Invalid XMLUI received"), error=True)
369 return xmlui_id 369 return xmlui_id
370 370
371 async def onFileAction(self, action_data, action_id, security_limit, profile): 371 async def on_file_action(self, action_data, action_id, security_limit, profile):
372 xmlui_id = self.getXmluiId(action_data) 372 xmlui_id = self.get_xmlui_id(action_data)
373 if xmlui_id is None: 373 if xmlui_id is None:
374 return self.host.quitFromSignal(1) 374 return self.host.quit_from_signal(1)
375 try: 375 try:
376 from_jid = jid.JID(action_data["meta_from_jid"]) 376 from_jid = jid.JID(action_data["meta_from_jid"])
377 except KeyError: 377 except KeyError:
378 self.disp(_("Ignoring action without from_jid data"), 1) 378 self.disp(_("Ignoring action without from_jid data"), 1)
379 return 379 return
384 return 384 return
385 385
386 if not self.bare_jids or from_jid.bare in self.bare_jids: 386 if not self.bare_jids or from_jid.bare in self.bare_jids:
387 if self._overwrite_refused: 387 if self._overwrite_refused:
388 self.disp(_("File refused because overwrite is needed"), error=True) 388 self.disp(_("File refused because overwrite is needed"), error=True)
389 await self.host.bridge.launchAction( 389 await self.host.bridge.action_launch(
390 xmlui_id, {"cancelled": C.BOOL_TRUE}, profile_key=profile 390 xmlui_id, {"cancelled": C.BOOL_TRUE}, profile_key=profile
391 ) 391 )
392 return self.host.quitFromSignal(2) 392 return self.host.quit_from_signal(2)
393 await self.set_progress_id(progress_id) 393 await self.set_progress_id(progress_id)
394 xmlui_data = {"path": self.path} 394 xmlui_data = {"path": self.path}
395 await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) 395 await self.host.bridge.action_launch(xmlui_id, xmlui_data, profile_key=profile)
396 396
397 async def onOverwriteAction(self, action_data, action_id, security_limit, profile): 397 async def on_overwrite_action(self, action_data, action_id, security_limit, profile):
398 xmlui_id = self.getXmluiId(action_data) 398 xmlui_id = self.get_xmlui_id(action_data)
399 if xmlui_id is None: 399 if xmlui_id is None:
400 return self.host.quitFromSignal(1) 400 return self.host.quit_from_signal(1)
401 try: 401 try:
402 progress_id = action_data["meta_progress_id"] 402 progress_id = action_data["meta_progress_id"]
403 except KeyError: 403 except KeyError:
404 self.disp(_("ignoring action without progress id"), 1) 404 self.disp(_("ignoring action without progress id"), 1)
405 return 405 return
410 self.disp(_("Overwrite accepted"), 2) 410 self.disp(_("Overwrite accepted"), 2)
411 else: 411 else:
412 self.disp(_("Refused to overwrite"), 2) 412 self.disp(_("Refused to overwrite"), 2)
413 self._overwrite_refused = True 413 self._overwrite_refused = True
414 414
415 xmlui_data = {"answer": C.boolConst(self.args.force)} 415 xmlui_data = {"answer": C.bool_const(self.args.force)}
416 await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) 416 await self.host.bridge.action_launch(xmlui_id, xmlui_data, profile_key=profile)
417 417
418 async def onNotInRosterAction(self, action_data, action_id, security_limit, profile): 418 async def on_not_in_roster_action(self, action_data, action_id, security_limit, profile):
419 xmlui_id = self.getXmluiId(action_data) 419 xmlui_id = self.get_xmlui_id(action_data)
420 if xmlui_id is None: 420 if xmlui_id is None:
421 return self.host.quitFromSignal(1) 421 return self.host.quit_from_signal(1)
422 try: 422 try:
423 from_jid = jid.JID(action_data["meta_from_jid"]) 423 from_jid = jid.JID(action_data["meta_from_jid"])
424 except ValueError: 424 except ValueError:
425 self.disp( 425 self.disp(
426 _('invalid "from_jid" value received, ignoring: {value}').format( 426 _('invalid "from_jid" value received, ignoring: {value}').format(
440 self.disp(_("Sender confirmed because she or he is explicitly expected"), 1) 440 self.disp(_("Sender confirmed because she or he is explicitly expected"), 1)
441 else: 441 else:
442 xmlui = xmlui_manager.create(self.host, action_data["xmlui"]) 442 xmlui = xmlui_manager.create(self.host, action_data["xmlui"])
443 confirmed = await self.host.confirm(xmlui.dlg.message) 443 confirmed = await self.host.confirm(xmlui.dlg.message)
444 444
445 xmlui_data = {"answer": C.boolConst(confirmed)} 445 xmlui_data = {"answer": C.bool_const(confirmed)}
446 await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) 446 await self.host.bridge.action_launch(xmlui_id, xmlui_data, profile_key=profile)
447 if not confirmed and not self.args.multiple: 447 if not confirmed and not self.args.multiple:
448 self.disp(_("Session refused for {from_jid}").format(from_jid=from_jid)) 448 self.disp(_("Session refused for {from_jid}").format(from_jid=from_jid))
449 self.host.quitFromSignal(0) 449 self.host.quit_from_signal(0)
450 450
451 async def start(self): 451 async def start(self):
452 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids] 452 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids]
453 self.path = os.path.abspath(self.args.path) 453 self.path = os.path.abspath(self.args.path)
454 if not os.path.isdir(self.path): 454 if not os.path.isdir(self.path):
487 self.parser.add_argument( 487 self.parser.add_argument(
488 "attachment", type=str, 488 "attachment", type=str,
489 help=_("URI of the file to retrieve or JSON of the whole attachment") 489 help=_("URI of the file to retrieve or JSON of the whole attachment")
490 ) 490 )
491 491
492 async def onProgressStarted(self, metadata): 492 async def on_progress_started(self, metadata):
493 self.disp(_("File download started"), 2) 493 self.disp(_("File download started"), 2)
494 494
495 async def onProgressFinished(self, metadata): 495 async def on_progress_finished(self, metadata):
496 self.disp(_("File downloaded successfully"), 2) 496 self.disp(_("File downloaded successfully"), 2)
497 497
498 async def onProgressError(self, error_msg): 498 async def on_progress_error(self, error_msg):
499 self.disp(_("Error while downloading file: {}").format(error_msg), error=True) 499 self.disp(_("Error while downloading file: {}").format(error_msg), error=True)
500 500
501 async def gotId(self, data): 501 async def got_id(self, data):
502 """Called when a progress id has been received""" 502 """Called when a progress id has been received"""
503 try: 503 try:
504 await self.set_progress_id(data["progress"]) 504 await self.set_progress_id(data["progress"])
505 except KeyError: 505 except KeyError:
506 if "xmlui" in data: 506 if "xmlui" in data:
530 dest_file = Path(dest_file).expanduser().resolve() 530 dest_file = Path(dest_file).expanduser().resolve()
531 if dest_file.exists() and not self.args.force: 531 if dest_file.exists() and not self.args.force:
532 message = _("File {path} already exists! Do you want to overwrite?").format( 532 message = _("File {path} already exists! Do you want to overwrite?").format(
533 path=dest_file 533 path=dest_file
534 ) 534 )
535 await self.host.confirmOrQuit(message, _("file download cancelled")) 535 await self.host.confirm_or_quit(message, _("file download cancelled"))
536 536
537 options = {} 537 options = {}
538 538
539 try: 539 try:
540 download_data_s = await self.host.bridge.fileDownload( 540 download_data_s = await self.host.bridge.file_download(
541 data_format.serialise(attachment), 541 data_format.serialise(attachment),
542 str(dest_file), 542 str(dest_file),
543 data_format.serialise(options), 543 data_format.serialise(options),
544 self.profile, 544 self.profile,
545 ) 545 )
546 download_data = data_format.deserialise(download_data_s) 546 download_data = data_format.deserialise(download_data_s)
547 except Exception as e: 547 except Exception as e:
548 self.disp(f"error while trying to download a file: {e}", error=True) 548 self.disp(f"error while trying to download a file: {e}", error=True)
549 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 549 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
550 else: 550 else:
551 await self.gotId(download_data) 551 await self.got_id(download_data)
552 552
553 553
554 class Upload(base.CommandBase): 554 class Upload(base.CommandBase):
555 def __init__(self, host): 555 def __init__(self, host):
556 super(Upload, self).__init__( 556 super(Upload, self).__init__(
574 "--ignore-tls-errors", 574 "--ignore-tls-errors",
575 action="store_true", 575 action="store_true",
576 help=_(r"ignore invalide TLS certificate (/!\ Dangerous /!\)"), 576 help=_(r"ignore invalide TLS certificate (/!\ Dangerous /!\)"),
577 ) 577 )
578 578
579 async def onProgressStarted(self, metadata): 579 async def on_progress_started(self, metadata):
580 self.disp(_("File upload started"), 2) 580 self.disp(_("File upload started"), 2)
581 581
582 async def onProgressFinished(self, metadata): 582 async def on_progress_finished(self, metadata):
583 self.disp(_("File uploaded successfully"), 2) 583 self.disp(_("File uploaded successfully"), 2)
584 try: 584 try:
585 url = metadata["url"] 585 url = metadata["url"]
586 except KeyError: 586 except KeyError:
587 self.disp("download URL not found in metadata") 587 self.disp("download URL not found in metadata")
588 else: 588 else:
589 self.disp(_("URL to retrieve the file:"), 1) 589 self.disp(_("URL to retrieve the file:"), 1)
590 # XXX: url is displayed alone on a line to make parsing easier 590 # XXX: url is displayed alone on a line to make parsing easier
591 self.disp(url) 591 self.disp(url)
592 592
593 async def onProgressError(self, error_msg): 593 async def on_progress_error(self, error_msg):
594 self.disp(_("Error while uploading file: {}").format(error_msg), error=True) 594 self.disp(_("Error while uploading file: {}").format(error_msg), error=True)
595 595
596 async def gotId(self, data, file_): 596 async def got_id(self, data, file_):
597 """Called when a progress id has been received 597 """Called when a progress id has been received
598 598
599 @param pid(unicode): progress id 599 @param pid(unicode): progress id
600 @param file_(str): file path 600 @param file_(str): file path
601 """ 601 """
631 if self.args.encrypt: 631 if self.args.encrypt:
632 options["encryption"] = C.ENC_AES_GCM 632 options["encryption"] = C.ENC_AES_GCM
633 633
634 path = os.path.abspath(file_) 634 path = os.path.abspath(file_)
635 try: 635 try:
636 upload_data = await self.host.bridge.fileUpload( 636 upload_data = await self.host.bridge.file_upload(
637 path, 637 path,
638 "", 638 "",
639 self.full_dest_jid, 639 self.full_dest_jid,
640 data_format.serialise(options), 640 data_format.serialise(options),
641 self.profile, 641 self.profile,
642 ) 642 )
643 except Exception as e: 643 except Exception as e:
644 self.disp(f"error while trying to upload a file: {e}", error=True) 644 self.disp(f"error while trying to upload a file: {e}", error=True)
645 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 645 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
646 else: 646 else:
647 await self.gotId(upload_data, file_) 647 await self.got_id(upload_data, file_)
648 648
649 649
650 class ShareAffiliationsSet(base.CommandBase): 650 class ShareAffiliationsSet(base.CommandBase):
651 def __init__(self, host): 651 def __init__(self, host):
652 super(ShareAffiliationsSet, self).__init__( 652 super(ShareAffiliationsSet, self).__init__(
685 ) 685 )
686 686
687 async def start(self): 687 async def start(self):
688 affiliations = dict(self.args.affiliations) 688 affiliations = dict(self.args.affiliations)
689 try: 689 try:
690 affiliations = await self.host.bridge.FISAffiliationsSet( 690 affiliations = await self.host.bridge.fis_affiliations_set(
691 self.args.jid, 691 self.args.jid,
692 self.args.namespace, 692 self.args.namespace,
693 self.args.path, 693 self.args.path,
694 affiliations, 694 affiliations,
695 self.profile, 695 self.profile,
728 help=_("jid of sharing entity"), 728 help=_("jid of sharing entity"),
729 ) 729 )
730 730
731 async def start(self): 731 async def start(self):
732 try: 732 try:
733 affiliations = await self.host.bridge.FISAffiliationsGet( 733 affiliations = await self.host.bridge.fis_affiliations_get(
734 self.args.jid, 734 self.args.jid,
735 self.args.namespace, 735 self.args.namespace,
736 self.args.path, 736 self.args.path,
737 self.profile, 737 self.profile,
738 ) 738 )
791 ) 791 )
792 792
793 async def start(self): 793 async def start(self):
794 configuration = dict(self.args.fields) 794 configuration = dict(self.args.fields)
795 try: 795 try:
796 configuration = await self.host.bridge.FISConfigurationSet( 796 configuration = await self.host.bridge.fis_configuration_set(
797 self.args.jid, 797 self.args.jid,
798 self.args.namespace, 798 self.args.namespace,
799 self.args.path, 799 self.args.path,
800 configuration, 800 configuration,
801 self.profile, 801 self.profile,
834 help=_("jid of sharing entity"), 834 help=_("jid of sharing entity"),
835 ) 835 )
836 836
837 async def start(self): 837 async def start(self):
838 try: 838 try:
839 configuration = await self.host.bridge.FISConfigurationGet( 839 configuration = await self.host.bridge.fis_configuration_get(
840 self.args.jid, 840 self.args.jid,
841 self.args.namespace, 841 self.args.namespace,
842 self.args.path, 842 self.args.path,
843 self.profile, 843 self.profile,
844 ) 844 )
898 return name 898 return name
899 899
900 def _size_filter(self, size, row): 900 def _size_filter(self, size, row):
901 if not size: 901 if not size:
902 return "" 902 return ""
903 return A.color(A.BOLD, utils.getHumanSize(size)) 903 return A.color(A.BOLD, utils.get_human_size(size))
904 904
905 def default_output(self, files_data): 905 def default_output(self, files_data):
906 """display files a way similar to ls""" 906 """display files a way similar to ls"""
907 files_data.sort(key=lambda d: d["name"].lower()) 907 files_data.sort(key=lambda d: d["name"].lower())
908 show_header = False 908 show_header = False
912 keys = headers = ("name", "type", "size") 912 keys = headers = ("name", "type", "size")
913 elif self.verbosity > 1: 913 elif self.verbosity > 1:
914 show_header = True 914 show_header = True
915 keys = ("name", "type", "size", "file_hash") 915 keys = ("name", "type", "size", "file_hash")
916 headers = ("name", "type", "size", "hash") 916 headers = ("name", "type", "size", "hash")
917 table = common.Table.fromListDict( 917 table = common.Table.from_list_dict(
918 self.host, 918 self.host,
919 files_data, 919 files_data,
920 keys=keys, 920 keys=keys,
921 headers=headers, 921 headers=headers,
922 filters={"name": self._name_filter, "size": self._size_filter}, 922 filters={"name": self._name_filter, "size": self._size_filter},
924 ) 924 )
925 table.display_blank(show_header=show_header, hide_cols=["type"]) 925 table.display_blank(show_header=show_header, hide_cols=["type"])
926 926
927 async def start(self): 927 async def start(self):
928 try: 928 try:
929 files_data = await self.host.bridge.FISList( 929 files_data = await self.host.bridge.fis_list(
930 self.args.jid, 930 self.args.jid,
931 self.args.path, 931 self.args.path,
932 {}, 932 {},
933 self.profile, 933 self.profile,
934 ) 934 )
985 if jids: 985 if jids:
986 access = {"read": {"type": "whitelist", "jids": jids}} 986 access = {"read": {"type": "whitelist", "jids": jids}}
987 else: 987 else:
988 access = {} 988 access = {}
989 try: 989 try:
990 name = await self.host.bridge.FISSharePath( 990 name = await self.host.bridge.fis_share_path(
991 self.args.name, 991 self.args.name,
992 self.path, 992 self.path,
993 json.dumps(access, ensure_ascii=False), 993 json.dumps(access, ensure_ascii=False),
994 self.profile, 994 self.profile,
995 ) 995 )
1057 if not self.args.thumbnail.startswith("http"): 1057 if not self.args.thumbnail.startswith("http"):
1058 self.parser.error(_("only http(s) links are allowed with --thumbnail")) 1058 self.parser.error(_("only http(s) links are allowed with --thumbnail"))
1059 else: 1059 else:
1060 extra["thumb_url"] = self.args.thumbnail 1060 extra["thumb_url"] = self.args.thumbnail
1061 try: 1061 try:
1062 await self.host.bridge.FISInvite( 1062 await self.host.bridge.fis_invite(
1063 self.args.jid, 1063 self.args.jid,
1064 self.args.service, 1064 self.args.service,
1065 self.args.type, 1065 self.args.type,
1066 self.args.namespace, 1066 self.args.namespace,
1067 self.path, 1067 self.path,