Mercurial > libervia-backend
comparison libervia/cli/cmd_application.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 47401850dec6 |
children |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
27 class List(base.CommandBase): | 27 class List(base.CommandBase): |
28 """List available applications""" | 28 """List available applications""" |
29 | 29 |
30 def __init__(self, host): | 30 def __init__(self, host): |
31 super(List, self).__init__( | 31 super(List, self).__init__( |
32 host, "list", use_profile=False, use_output=C.OUTPUT_LIST, | 32 host, |
33 help=_("list available applications") | 33 "list", |
34 use_profile=False, | |
35 use_output=C.OUTPUT_LIST, | |
36 help=_("list available applications"), | |
34 ) | 37 ) |
35 | 38 |
36 def add_parser_options(self): | 39 def add_parser_options(self): |
37 # FIXME: "extend" would be better here, but it's only available from Python 3.8+ | 40 # FIXME: "extend" would be better here, but it's only available from Python 3.8+ |
38 # so we use "append" until minimum version of Python is raised. | 41 # so we use "append" until minimum version of Python is raised. |
50 # FIXME: this is only needed because we can't use "extend" in | 53 # FIXME: this is only needed because we can't use "extend" in |
51 # add_parser_options, see note there | 54 # add_parser_options, see note there |
52 if self.args.filters: | 55 if self.args.filters: |
53 self.args.filters = list(set(self.args.filters)) | 56 self.args.filters = list(set(self.args.filters)) |
54 else: | 57 else: |
55 self.args.filters = ['available'] | 58 self.args.filters = ["available"] |
56 | 59 |
57 try: | 60 try: |
58 found_apps = await self.host.bridge.applications_list(self.args.filters) | 61 found_apps = await self.host.bridge.applications_list(self.args.filters) |
59 except Exception as e: | 62 except Exception as e: |
60 self.disp(f"can't get applications list: {e}", error=True) | 63 self.disp(f"can't get applications list: {e}", error=True) |
121 *args, | 124 *args, |
122 "", | 125 "", |
123 ) | 126 ) |
124 except Exception as e: | 127 except Exception as e: |
125 if self.args.name is not None: | 128 if self.args.name is not None: |
126 self.disp( | 129 self.disp(f"can't stop application {self.args.name!r}: {e}", error=True) |
127 f"can't stop application {self.args.name!r}: {e}", error=True) | |
128 else: | 130 else: |
129 self.disp( | 131 self.disp( |
130 f"can't stop application instance with id {self.args.id!r}: {e}", | 132 f"can't stop application instance with id {self.args.id!r}: {e}", |
131 error=True) | 133 error=True, |
134 ) | |
132 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 135 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
133 else: | 136 else: |
134 self.host.quit() | 137 self.host.quit() |
135 | 138 |
136 | 139 |
137 class Exposed(base.CommandBase): | 140 class Exposed(base.CommandBase): |
138 | 141 |
139 def __init__(self, host): | 142 def __init__(self, host): |
140 super(Exposed, self).__init__( | 143 super(Exposed, self).__init__( |
141 host, "exposed", use_profile=False, use_output=C.OUTPUT_DICT, | 144 host, |
142 help=_("show data exposed by a running application") | 145 "exposed", |
146 use_profile=False, | |
147 use_output=C.OUTPUT_DICT, | |
148 help=_("show data exposed by a running application"), | |
143 ) | 149 ) |
144 | 150 |
145 def add_parser_options(self): | 151 def add_parser_options(self): |
146 id_group = self.parser.add_mutually_exclusive_group(required=True) | 152 id_group = self.parser.add_mutually_exclusive_group(required=True) |
147 id_group.add_argument( | 153 id_group.add_argument( |
167 ) | 173 ) |
168 except Exception as e: | 174 except Exception as e: |
169 if self.args.name is not None: | 175 if self.args.name is not None: |
170 self.disp( | 176 self.disp( |
171 f"can't get values exposed from application {self.args.name!r}: {e}", | 177 f"can't get values exposed from application {self.args.name!r}: {e}", |
172 error=True) | 178 error=True, |
179 ) | |
173 else: | 180 else: |
174 self.disp( | 181 self.disp( |
175 f"can't values exposed from application instance with id {self.args.id!r}: {e}", | 182 f"can't values exposed from application instance with id {self.args.id!r}: {e}", |
176 error=True) | 183 error=True, |
184 ) | |
177 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 185 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
178 else: | 186 else: |
179 exposed_data = data_format.deserialise(exposed_data_raw) | 187 exposed_data = data_format.deserialise(exposed_data_raw) |
180 await self.output(exposed_data) | 188 await self.output(exposed_data) |
181 self.host.quit() | 189 self.host.quit() |
184 class Application(base.CommandBase): | 192 class Application(base.CommandBase): |
185 subcommands = (List, Start, Stop, Exposed) | 193 subcommands = (List, Start, Stop, Exposed) |
186 | 194 |
187 def __init__(self, host): | 195 def __init__(self, host): |
188 super(Application, self).__init__( | 196 super(Application, self).__init__( |
189 host, "application", use_profile=False, help=_("manage applications"), | 197 host, |
190 aliases=['app'], | 198 "application", |
191 ) | 199 use_profile=False, |
200 help=_("manage applications"), | |
201 aliases=["app"], | |
202 ) |