Mercurial > libervia-backend
comparison sat_frontends/jp/cmd_profile.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 | be6d91572633 |
children | 4b842c1fb686 |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
96 '-C', '--component', default='', | 96 '-C', '--component', default='', |
97 help=_('set to component import name (entry point) if this is a component')) | 97 help=_('set to component import name (entry point) if this is a component')) |
98 | 98 |
99 async def start(self): | 99 async def start(self): |
100 """Create a new profile""" | 100 """Create a new profile""" |
101 if self.args.profile in await self.host.bridge.profilesListGet(): | 101 if self.args.profile in await self.host.bridge.profiles_list_get(): |
102 self.disp(f"Profile {self.args.profile} already exists.", error=True) | 102 self.disp(f"Profile {self.args.profile} already exists.", error=True) |
103 self.host.quit(C.EXIT_BRIDGE_ERROR) | 103 self.host.quit(C.EXIT_BRIDGE_ERROR) |
104 try: | 104 try: |
105 await self.host.bridge.profileCreate( | 105 await self.host.bridge.profile_create( |
106 self.args.profile, self.args.password, self.args.component) | 106 self.args.profile, self.args.password, self.args.component) |
107 except Exception as e: | 107 except Exception as e: |
108 self.disp(f"can't create profile: {e}", error=True) | 108 self.disp(f"can't create profile: {e}", error=True) |
109 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 109 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
110 | 110 |
111 try: | 111 try: |
112 await self.host.bridge.profileStartSession( | 112 await self.host.bridge.profile_start_session( |
113 self.args.password, self.args.profile) | 113 self.args.password, self.args.profile) |
114 except Exception as e: | 114 except Exception as e: |
115 self.disp(f"can't start profile session: {e}", error=True) | 115 self.disp(f"can't start profile session: {e}", error=True) |
116 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 116 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
117 | 117 |
118 if self.args.jid: | 118 if self.args.jid: |
119 await self.host.bridge.setParam( | 119 await self.host.bridge.param_set( |
120 "JabberID", self.args.jid, "Connection", profile_key=self.args.profile) | 120 "JabberID", self.args.jid, "Connection", profile_key=self.args.profile) |
121 xmpp_pwd = self.args.password or self.args.xmpp_password | 121 xmpp_pwd = self.args.password or self.args.xmpp_password |
122 if xmpp_pwd: | 122 if xmpp_pwd: |
123 await self.host.bridge.setParam( | 123 await self.host.bridge.param_set( |
124 "Password", xmpp_pwd, "Connection", profile_key=self.args.profile) | 124 "Password", xmpp_pwd, "Connection", profile_key=self.args.profile) |
125 | 125 |
126 if self.args.autoconnect is not None: | 126 if self.args.autoconnect is not None: |
127 await self.host.bridge.setParam( | 127 await self.host.bridge.param_set( |
128 "autoconnect_backend", self.args.autoconnect, "Connection", | 128 "autoconnect_backend", self.args.autoconnect, "Connection", |
129 profile_key=self.args.profile) | 129 profile_key=self.args.profile) |
130 | 130 |
131 self.disp(f'profile {self.args.profile} created successfully', 1) | 131 self.disp(f'profile {self.args.profile} created successfully', 1) |
132 self.host.quit() | 132 self.host.quit() |
139 | 139 |
140 def add_parser_options(self): | 140 def add_parser_options(self): |
141 pass | 141 pass |
142 | 142 |
143 async def start(self): | 143 async def start(self): |
144 print(await self.host.bridge.profileNameGet('@DEFAULT@')) | 144 print(await self.host.bridge.profile_name_get('@DEFAULT@')) |
145 self.host.quit() | 145 self.host.quit() |
146 | 146 |
147 | 147 |
148 class ProfileDelete(base.CommandBase): | 148 class ProfileDelete(base.CommandBase): |
149 def __init__(self, host): | 149 def __init__(self, host): |
152 def add_parser_options(self): | 152 def add_parser_options(self): |
153 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) | 153 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) |
154 self.parser.add_argument('-f', '--force', action='store_true', help=_('delete profile without confirmation')) | 154 self.parser.add_argument('-f', '--force', action='store_true', help=_('delete profile without confirmation')) |
155 | 155 |
156 async def start(self): | 156 async def start(self): |
157 if self.args.profile not in await self.host.bridge.profilesListGet(): | 157 if self.args.profile not in await self.host.bridge.profiles_list_get(): |
158 log.error(f"Profile {self.args.profile} doesn't exist.") | 158 log.error(f"Profile {self.args.profile} doesn't exist.") |
159 self.host.quit(C.EXIT_NOT_FOUND) | 159 self.host.quit(C.EXIT_NOT_FOUND) |
160 if not self.args.force: | 160 if not self.args.force: |
161 message = f"Are you sure to delete profile [{self.args.profile}] ?" | 161 message = f"Are you sure to delete profile [{self.args.profile}] ?" |
162 cancel_message = "Profile deletion cancelled" | 162 cancel_message = "Profile deletion cancelled" |
163 await self.host.confirmOrQuit(message, cancel_message) | 163 await self.host.confirm_or_quit(message, cancel_message) |
164 | 164 |
165 await self.host.bridge.asyncDeleteProfile(self.args.profile) | 165 await self.host.bridge.profile_delete_async(self.args.profile) |
166 self.host.quit() | 166 self.host.quit() |
167 | 167 |
168 | 168 |
169 class ProfileInfo(base.CommandBase): | 169 class ProfileInfo(base.CommandBase): |
170 | 170 |
185 self.to_show.append((_("autoconnect (backend)"), "Connection", | 185 self.to_show.append((_("autoconnect (backend)"), "Connection", |
186 "autoconnect_backend")) | 186 "autoconnect_backend")) |
187 data = {} | 187 data = {} |
188 for label, category, name in self.to_show: | 188 for label, category, name in self.to_show: |
189 try: | 189 try: |
190 value = await self.host.bridge.asyncGetParamA( | 190 value = await self.host.bridge.param_get_a_async( |
191 name, category, profile_key=self.host.profile) | 191 name, category, profile_key=self.host.profile) |
192 except Exception as e: | 192 except Exception as e: |
193 self.disp(f"can't get {name}/{category} param: {e}", error=True) | 193 self.disp(f"can't get {name}/{category} param: {e}", error=True) |
194 else: | 194 else: |
195 data[label] = value | 195 data[label] = value |
216 clients, components = True, False | 216 clients, components = True, False |
217 elif self.args.components: | 217 elif self.args.components: |
218 clients, components = False, True | 218 clients, components = False, True |
219 else: | 219 else: |
220 clients, components = True, True | 220 clients, components = True, True |
221 await self.output(await self.host.bridge.profilesListGet(clients, components)) | 221 await self.output(await self.host.bridge.profiles_list_get(clients, components)) |
222 self.host.quit() | 222 self.host.quit() |
223 | 223 |
224 | 224 |
225 class ProfileModify(base.CommandBase): | 225 class ProfileModify(base.CommandBase): |
226 | 226 |
249 | 249 |
250 async def start(self): | 250 async def start(self): |
251 if self.args.disable_password: | 251 if self.args.disable_password: |
252 self.args.password = '' | 252 self.args.password = '' |
253 if self.args.password is not None: | 253 if self.args.password is not None: |
254 await self.host.bridge.setParam( | 254 await self.host.bridge.param_set( |
255 "Password", self.args.password, "General", profile_key=self.host.profile) | 255 "Password", self.args.password, "General", profile_key=self.host.profile) |
256 if self.args.jid is not None: | 256 if self.args.jid is not None: |
257 await self.host.bridge.setParam( | 257 await self.host.bridge.param_set( |
258 "JabberID", self.args.jid, "Connection", profile_key=self.host.profile) | 258 "JabberID", self.args.jid, "Connection", profile_key=self.host.profile) |
259 if self.args.xmpp_password is not None: | 259 if self.args.xmpp_password is not None: |
260 await self.host.bridge.setParam( | 260 await self.host.bridge.param_set( |
261 "Password", self.args.xmpp_password, "Connection", | 261 "Password", self.args.xmpp_password, "Connection", |
262 profile_key=self.host.profile) | 262 profile_key=self.host.profile) |
263 if self.args.default: | 263 if self.args.default: |
264 await self.host.bridge.profileSetDefault(self.host.profile) | 264 await self.host.bridge.profile_set_default(self.host.profile) |
265 if self.args.autoconnect is not None: | 265 if self.args.autoconnect is not None: |
266 await self.host.bridge.setParam( | 266 await self.host.bridge.param_set( |
267 "autoconnect_backend", self.args.autoconnect, "Connection", | 267 "autoconnect_backend", self.args.autoconnect, "Connection", |
268 profile_key=self.host.profile) | 268 profile_key=self.host.profile) |
269 | 269 |
270 self.host.quit() | 270 self.host.quit() |
271 | 271 |