comparison sat_frontends/jp/base.py @ 3568:04283582966f

core, frontends: fix invalid translatable strings. Some f-strings where used in translatable text, this has been fixed by using explicit `format()` call (using a script based on `tokenize`). As tokenize messes with spaces, a reformating tool (`black`) has been applied to some files afterwards.
author Goffi <goffi@goffi.org>
date Mon, 14 Jun 2021 18:35:12 +0200
parents 53fec6309fa3
children 5f65f4e9f8cb 43542cf32e5a
comparison
equal deleted inserted replaced
3567:a240748ed686 3568:04283582966f
151 background = self.get_config('background', default='auto') 151 background = self.get_config('background', default='auto')
152 if background == 'auto': 152 if background == 'auto':
153 background = self.guess_background() 153 background = self.guess_background()
154 if background not in ('dark', 'light'): 154 if background not in ('dark', 'light'):
155 raise exceptions.ConfigError(_( 155 raise exceptions.ConfigError(_(
156 f'Invalid value set for "background" ({background!r}), please check ' 156 'Invalid value set for "background" ({background}), please check '
157 f'your settings in libervia.conf')) 157 'your settings in libervia.conf').format(
158 background=repr(background)
159 ))
158 if background == 'light': 160 if background == 'light':
159 C.A_HEADER = A.FG_MAGENTA 161 C.A_HEADER = A.FG_MAGENTA
160 C.A_SUBHEADER = A.BOLD + A.FG_RED 162 C.A_SUBHEADER = A.BOLD + A.FG_RED
161 C.A_LEVEL_COLORS = (C.A_HEADER, A.BOLD + A.FG_BLUE, A.FG_MAGENTA, A.FG_CYAN) 163 C.A_LEVEL_COLORS = (C.A_HEADER, A.BOLD + A.FG_BLUE, A.FG_MAGENTA, A.FG_CYAN)
162 C.A_SUCCESS = A.FG_GREEN 164 C.A_SUCCESS = A.FG_GREEN
447 'description': description 449 'description': description
448 } 450 }
449 if default: 451 if default:
450 if type_ in self.default_output: 452 if type_ in self.default_output:
451 self.disp( 453 self.disp(
452 _(f'there is already a default output for {type_}, ignoring new one') 454 _('there is already a default output for {type}, ignoring new one')
455 .format(type=type_)
453 ) 456 )
454 else: 457 else:
455 self.default_output[type_] = name 458 self.default_output[type_] = name
456 459
457 460
491 try: 494 try:
492 module = import_module(module_path) 495 module = import_module(module_path)
493 self.import_plugin_module(module, type_) 496 self.import_plugin_module(module, type_)
494 except ImportError as e: 497 except ImportError as e:
495 self.disp( 498 self.disp(
496 _(f"Can't import {module_path} plugin, ignoring it: {e}"), 499 _("Can't import {module_path} plugin, ignoring it: {e}")
500 .format(module_path=module_path, e=e),
497 error=True) 501 error=True)
498 except exceptions.CancelError: 502 except exceptions.CancelError:
499 continue 503 continue
500 except exceptions.MissingModule as e: 504 except exceptions.MissingModule as e:
501 self.disp(_("Missing module for plugin {name}: {missing}".format( 505 self.disp(_("Missing module for plugin {name}: {missing}".format(
510 @param type_(str): one of C_PLUGIN_* 514 @param type_(str): one of C_PLUGIN_*
511 """ 515 """
512 try: 516 try:
513 class_names = getattr(module, '__{}__'.format(type_)) 517 class_names = getattr(module, '__{}__'.format(type_))
514 except AttributeError: 518 except AttributeError:
515 log.disp(_(f"Invalid plugin module [{type_}] {module}"), error=True) 519 log.disp(
520 _("Invalid plugin module [{type}] {module}")
521 .format(type=type_, module=module),
522 error=True)
516 raise ImportError 523 raise ImportError
517 else: 524 else:
518 for class_name in class_names: 525 for class_name in class_names:
519 cls = getattr(module, class_name) 526 cls = getattr(module, class_name)
520 cls(self) 527 cls(self)
599 except AttributeError: 606 except AttributeError:
600 item_last = False 607 item_last = False
601 if not item_last: 608 if not item_last:
602 self.args.item = uri_item 609 self.args.item = uri_item
603 else: 610 else:
604 self.parser.error(_(f'XMPP URL is not a pubsub one: {url}')) 611 self.parser.error(
612 _('XMPP URL is not a pubsub one: {url}').format(url=url)
613 )
605 flags = self.args._cmd._pubsub_flags 614 flags = self.args._cmd._pubsub_flags
606 # we check required arguments here instead of using add_arguments' required option 615 # we check required arguments here instead of using add_arguments' required option
607 # because the required argument can be set in URL 616 # because the required argument can be set in URL
608 if C.SERVICE in flags and not self.args.service: 617 if C.SERVICE in flags and not self.args.service:
609 self.parser.error(_("argument -s/--service is required")) 618 self.parser.error(_("argument -s/--service is required"))
645 async def main(self, args, namespace): 654 async def main(self, args, namespace):
646 try: 655 try:
647 await self.bridge.bridgeConnect() 656 await self.bridge.bridgeConnect()
648 except Exception as e: 657 except Exception as e:
649 if isinstance(e, exceptions.BridgeExceptionNoService): 658 if isinstance(e, exceptions.BridgeExceptionNoService):
650 print((_("Can't connect to SàT backend, are you sure it's launched ?"))) 659 print(_("Can't connect to SàT backend, are you sure it's launched ?"))
651 self.quit(C.EXIT_BACKEND_NOT_FOUND, raise_exc=False) 660 self.quit(C.EXIT_BACKEND_NOT_FOUND, raise_exc=False)
652 elif isinstance(e, exceptions.BridgeInitError): 661 elif isinstance(e, exceptions.BridgeInitError):
653 print((_("Can't init bridge"))) 662 print(_("Can't init bridge"))
654 self.quit(C.EXIT_BRIDGE_ERROR, raise_exc=False) 663 self.quit(C.EXIT_BRIDGE_ERROR, raise_exc=False)
655 else: 664 else:
656 print((_(f"Error while initialising bridge: {e}"))) 665 print(
666 _("Error while initialising bridge: {e}").format(e=e)
667 )
657 self.quit(C.EXIT_BRIDGE_ERROR, raise_exc=False) 668 self.quit(C.EXIT_BRIDGE_ERROR, raise_exc=False)
658 return 669 return
659 self.version = await self.bridge.getVersion() 670 self.version = await self.bridge.getVersion()
660 self._bridgeConnected() 671 self._bridgeConnected()
661 self.import_plugins() 672 self.import_plugins()
842 # FIXME: need better exit codes 853 # FIXME: need better exit codes
843 854
844 self.profile = await self.bridge.profileNameGet(self.args.profile) 855 self.profile = await self.bridge.profileNameGet(self.args.profile)
845 856
846 if not self.profile: 857 if not self.profile:
847 log.error(_(f"The profile [{self.args.profile}] doesn't exist")) 858 log.error(
859 _("The profile [{profile}] doesn't exist")
860 .format(profile=self.args.profile)
861 )
848 self.quit(C.EXIT_ERROR) 862 self.quit(C.EXIT_ERROR)
849 863
850 try: 864 try:
851 start_session = self.args.start_session 865 start_session = self.args.start_session
852 except AttributeError: 866 except AttributeError:
859 ) 873 )
860 return 874 return
861 elif not await self.bridge.profileIsSessionStarted(self.profile): 875 elif not await self.bridge.profileIsSessionStarted(self.profile):
862 if not self.args.connect: 876 if not self.args.connect:
863 self.disp(_( 877 self.disp(_(
864 f"Session for [{self.profile}] is not started, please start it " 878 "Session for [{profile}] is not started, please start it "
865 f"before using jp, or use either --start-session or --connect " 879 "before using jp, or use either --start-session or --connect "
866 f"option"), error=True) 880 "option"
881 .format(profile=self.profile)
882 ), error=True)
867 self.quit(1) 883 self.quit(1)
868 elif not getattr(self.args, "connect", False): 884 elif not getattr(self.args, "connect", False):
869 return 885 return
870 886
871 887
880 ) 896 )
881 return 897 return
882 else: 898 else:
883 if not await self.bridge.isConnected(self.profile): 899 if not await self.bridge.isConnected(self.profile):
884 log.error( 900 log.error(
885 _(f"Profile [{self.profile}] is not connected, please connect it " 901 _("Profile [{profile}] is not connected, please connect it "
886 f"before using jp, or use --connect option")) 902 "before using jp, or use --connect option")
903 .format(profile=self.profile)
904 )
887 self.quit(1) 905 self.quit(1)
888 906
889 async def get_full_jid(self, param_jid): 907 async def get_full_jid(self, param_jid):
890 """Return the full jid if possible (add main resource when find a bare jid)""" 908 """Return the full jid if possible (add main resource when find a bare jid)"""
891 # TODO: to be removed, bare jid should work with all commands, notably for file 909 # TODO: to be removed, bare jid should work with all commands, notably for file
1156 async def onProgressError(self, e): 1174 async def onProgressError(self, e):
1157 """Called when a progress failed 1175 """Called when a progress failed
1158 1176
1159 @param error_msg(unicode): error message as sent by bridge.progressError 1177 @param error_msg(unicode): error message as sent by bridge.progressError
1160 """ 1178 """
1161 self.disp(_(f"Error while doing operation: {e}"), error=True) 1179 self.disp(_("Error while doing operation: {e}").format(e=e), error=True)
1162 1180
1163 def disp(self, msg, verbosity=0, error=False, end='\n'): 1181 def disp(self, msg, verbosity=0, error=False, end='\n'):
1164 return self.host.disp(msg, verbosity, error, end) 1182 return self.host.disp(msg, verbosity, error, end)
1165 1183
1166 def output(self, data): 1184 def output(self, data):