Mercurial > libervia-backend
comparison sat_frontends/jp/cmd_list.py @ 3573:813595f88612
merge changes from main branch
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 17 Jun 2021 13:05:58 +0200 |
parents | 04283582966f |
children | 524856bd7b19 |
comparison
equal
deleted
inserted
replaced
3541:888109774673 | 3573:813595f88612 |
---|---|
59 self.args.items, | 59 self.args.items, |
60 "", | 60 "", |
61 self.getPubsubExtra(), | 61 self.getPubsubExtra(), |
62 self.profile, | 62 self.profile, |
63 ), | 63 ), |
64 type_check=list | 64 type_check=list, |
65 ) | 65 ) |
66 except Exception as e: | 66 except Exception as e: |
67 self.disp(f"can't get lists: {e}", error=True) | 67 self.disp(f"can't get lists: {e}", error=True) |
68 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 68 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
69 else: | 69 else: |
70 await self.output(lists_data[0]) | 70 await self.output(lists_data[0]) |
71 self.host.quit(C.EXIT_OK) | 71 self.host.quit(C.EXIT_OK) |
72 | 72 |
73 | 73 |
74 class Set(base.CommandBase): | 74 class Set(base.CommandBase): |
75 | |
76 def __init__(self, host): | 75 def __init__(self, host): |
77 base.CommandBase.__init__( | 76 base.CommandBase.__init__( |
78 self, | 77 self, |
79 host, | 78 host, |
80 "set", | 79 "set", |
126 try: | 125 try: |
127 item_id = await self.host.bridge.listSet( | 126 item_id = await self.host.bridge.listSet( |
128 self.args.service, | 127 self.args.service, |
129 self.args.node, | 128 self.args.node, |
130 values, | 129 values, |
131 '', | 130 "", |
132 self.args.item, | 131 self.args.item, |
133 data_format.serialise(extra), | 132 data_format.serialise(extra), |
134 self.profile | 133 self.profile, |
135 ) | 134 ) |
136 except Exception as e: | 135 except Exception as e: |
137 self.disp(f"can't set list item: {e}", error=True) | 136 self.disp(f"can't set list item: {e}", error=True) |
138 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 137 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
139 else: | 138 else: |
140 self.disp(f"item {str(item_id or self.args.item)!r} set successfully") | 139 self.disp(f"item {str(item_id or self.args.item)!r} set successfully") |
141 self.host.quit(C.EXIT_OK) | 140 self.host.quit(C.EXIT_OK) |
142 | 141 |
143 | 142 |
144 class Delete(base.CommandBase): | 143 class Delete(base.CommandBase): |
145 | |
146 def __init__(self, host): | 144 def __init__(self, host): |
147 base.CommandBase.__init__( | 145 base.CommandBase.__init__( |
148 self, | 146 self, |
149 host, | 147 host, |
150 "delete", | 148 "delete", |
181 self.args.item, | 179 self.args.item, |
182 self.args.notify, | 180 self.args.notify, |
183 self.profile, | 181 self.profile, |
184 ) | 182 ) |
185 except Exception as e: | 183 except Exception as e: |
186 self.disp(_(f"can't delete item: {e}"), error=True) | 184 self.disp(_("can't delete item: {e}").format(e=e), error=True) |
187 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 185 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
188 else: | 186 else: |
189 self.disp(_(f"item {self.args.item} has been deleted")) | 187 self.disp(_("item {item} has been deleted").format(item=self.args.item)) |
190 self.host.quit(C.EXIT_OK) | 188 self.host.quit(C.EXIT_OK) |
191 | 189 |
192 | 190 |
193 class Import(base.CommandBase): | 191 class Import(base.CommandBase): |
194 # TODO: factorize with blog/import | 192 # TODO: factorize with blog/import |
260 | 258 |
261 async def onProgressFinished(self, metadata): | 259 async def onProgressFinished(self, metadata): |
262 self.disp(_("Tickets uploaded successfully"), 2) | 260 self.disp(_("Tickets uploaded successfully"), 2) |
263 | 261 |
264 async def onProgressError(self, error_msg): | 262 async def onProgressError(self, error_msg): |
265 self.disp(_(f"Error while uploading tickets: {error_msg}"), error=True) | 263 self.disp( |
264 _("Error while uploading tickets: {error_msg}").format(error_msg=error_msg), | |
265 error=True, | |
266 ) | |
266 | 267 |
267 async def start(self): | 268 async def start(self): |
268 if self.args.location is None: | 269 if self.args.location is None: |
269 # no location, the list of importer or description is requested | 270 # no location, the list of importer or description is requested |
270 for name in ("option", "service", "node"): | 271 for name in ("option", "service", "node"): |
271 if getattr(self.args, name): | 272 if getattr(self.args, name): |
272 self.parser.error( | 273 self.parser.error( |
273 _(f"{name} argument can't be used without location argument")) | 274 _( |
275 "{name} argument can't be used without location argument" | |
276 ).format(name=name) | |
277 ) | |
274 if self.args.importer is None: | 278 if self.args.importer is None: |
275 self.disp( | 279 self.disp( |
276 "\n".join( | 280 "\n".join( |
277 [ | 281 [ |
278 f"{name}: {desc}" | 282 f"{name}: {desc}" |
295 # we have a location, an import is requested | 299 # we have a location, an import is requested |
296 | 300 |
297 if self.args.progress: | 301 if self.args.progress: |
298 # we use a custom progress bar template as we want a counter | 302 # we use a custom progress bar template as we want a counter |
299 self.pbar_template = [ | 303 self.pbar_template = [ |
300 _("Progress: "), ["Percentage"], " ", ["Bar"], " ", | 304 _("Progress: "), |
301 ["Counter"], " ", ["ETA"] | 305 ["Percentage"], |
306 " ", | |
307 ["Bar"], | |
308 " ", | |
309 ["Counter"], | |
310 " ", | |
311 ["ETA"], | |
302 ] | 312 ] |
303 | 313 |
304 options = {key: value for key, value in self.args.option} | 314 options = {key: value for key, value in self.args.option} |
305 fields_map = dict(self.args.map) | 315 fields_map = dict(self.args.map) |
306 if fields_map: | 316 if fields_map: |
307 if FIELDS_MAP in options: | 317 if FIELDS_MAP in options: |
308 self.parser.error( | 318 self.parser.error( |
309 _("fields_map must be specified either preencoded in --option or " | 319 _( |
310 "using --map, but not both at the same time") | 320 "fields_map must be specified either preencoded in --option or " |
321 "using --map, but not both at the same time" | |
322 ) | |
311 ) | 323 ) |
312 options[FIELDS_MAP] = json.dumps(fields_map) | 324 options[FIELDS_MAP] = json.dumps(fields_map) |
313 | 325 |
314 try: | 326 try: |
315 progress_id = await self.host.bridge.ticketsImport( | 327 progress_id = await self.host.bridge.ticketsImport( |
320 self.args.node, | 332 self.args.node, |
321 self.profile, | 333 self.profile, |
322 ) | 334 ) |
323 except Exception as e: | 335 except Exception as e: |
324 self.disp( | 336 self.disp( |
325 _(f"Error while trying to import tickets: {e}"), | 337 _("Error while trying to import tickets: {e}").format(e=e), |
326 error=True, | 338 error=True, |
327 ) | 339 ) |
328 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 340 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
329 else: | 341 else: |
330 await self.set_progress_id(progress_id) | 342 await self.set_progress_id(progress_id) |