comparison sat_frontends/jp/cmd_avatar.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 82e616b70a2a
children 4b842c1fb686
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
45 self.parser.add_argument( 45 self.parser.add_argument(
46 "-s", "--show", action="store_true", help=_("show avatar") 46 "-s", "--show", action="store_true", help=_("show avatar")
47 ) 47 )
48 self.parser.add_argument("jid", nargs='?', default='', help=_("entity")) 48 self.parser.add_argument("jid", nargs='?', default='', help=_("entity"))
49 49
50 async def showImage(self, path): 50 async def show_image(self, path):
51 sat_conf = config.parseMainConf() 51 sat_conf = config.parse_main_conf()
52 cmd = config.getConfig(sat_conf, C.CONFIG_SECTION, "image_cmd") 52 cmd = config.config_get(sat_conf, C.CONFIG_SECTION, "image_cmd")
53 cmds = [cmd] + DISPLAY_CMD if cmd else DISPLAY_CMD 53 cmds = [cmd] + DISPLAY_CMD if cmd else DISPLAY_CMD
54 for cmd in cmds: 54 for cmd in cmds:
55 try: 55 try:
56 process = await asyncio.create_subprocess_exec(cmd, path) 56 process = await asyncio.create_subprocess_exec(cmd, path)
57 ret = await process.wait() 57 ret = await process.wait()
70 70
71 webbrowser.open(path) 71 webbrowser.open(path)
72 72
73 async def start(self): 73 async def start(self):
74 try: 74 try:
75 avatar_data_raw = await self.host.bridge.avatarGet( 75 avatar_data_raw = await self.host.bridge.avatar_get(
76 self.args.jid, 76 self.args.jid,
77 not self.args.no_cache, 77 not self.args.no_cache,
78 self.profile, 78 self.profile,
79 ) 79 )
80 except Exception as e: 80 except Exception as e:
89 89
90 avatar_path = avatar_data['path'] 90 avatar_path = avatar_data['path']
91 91
92 self.disp(avatar_path) 92 self.disp(avatar_path)
93 if self.args.show: 93 if self.args.show:
94 await self.showImage(avatar_path) 94 await self.show_image(avatar_path)
95 95
96 self.host.quit() 96 self.host.quit()
97 97
98 98
99 class Set(base.CommandBase): 99 class Set(base.CommandBase):
115 if not os.path.exists(path): 115 if not os.path.exists(path):
116 self.disp(_("file {path} doesn't exist!").format(path=repr(path)), error=True) 116 self.disp(_("file {path} doesn't exist!").format(path=repr(path)), error=True)
117 self.host.quit(C.EXIT_BAD_ARG) 117 self.host.quit(C.EXIT_BAD_ARG)
118 path = os.path.abspath(path) 118 path = os.path.abspath(path)
119 try: 119 try:
120 await self.host.bridge.avatarSet(path, self.args.jid, self.profile) 120 await self.host.bridge.avatar_set(path, self.args.jid, self.profile)
121 except Exception as e: 121 except Exception as e:
122 self.disp(f"can't set avatar: {e}", error=True) 122 self.disp(f"can't set avatar: {e}", error=True)
123 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 123 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
124 else: 124 else:
125 self.disp(_("avatar has been set"), 1) 125 self.disp(_("avatar has been set"), 1)