annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
3 # Libervia CLI
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3377
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from . import base
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 from libervia.backend.tools.common import data_format
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
22 from libervia.cli.constants import Const as C
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
23
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 __commands__ = ["Application"]
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 class List(base.CommandBase):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 """List available applications"""
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 def __init__(self, host):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 super(List, self).__init__(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
32 host,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
33 "list",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
34 use_profile=False,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
35 use_output=C.OUTPUT_LIST,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
36 help=_("list available applications"),
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 def add_parser_options(self):
3377
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
40 # FIXME: "extend" would be better here, but it's only available from Python 3.8+
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
41 # so we use "append" until minimum version of Python is raised.
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self.parser.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 "-f",
3377
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
44 "--filter",
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
45 dest="filters",
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
46 action="append",
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 choices=["available", "running"],
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 help=_("show applications with this status"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 async def start(self):
3377
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
52
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
53 # FIXME: this is only needed because we can't use "extend" in
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
54 # add_parser_options, see note there
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
55 if self.args.filters:
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
56 self.args.filters = list(set(self.args.filters))
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
57 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
58 self.args.filters = ["available"]
3377
297389b1563c jp (application/list): don't use `extend` in argument as in it Python 3.8+ only
Goffi <goffi@goffi.org>
parents: 3374
diff changeset
59
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3563
diff changeset
61 found_apps = await self.host.bridge.applications_list(self.args.filters)
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 except Exception as e:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 self.disp(f"can't get applications list: {e}", error=True)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 await self.output(found_apps)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 self.host.quit()
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
68
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
69
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 class Start(base.CommandBase):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 """Start an application"""
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
72
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 def __init__(self, host):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 super(Start, self).__init__(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 host, "start", use_profile=False, help=_("start an application")
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
77
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def add_parser_options(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self.parser.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 "name",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 help=_("name of the application to start"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
83
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 async def start(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3563
diff changeset
86 await self.host.bridge.application_start(
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 self.args.name,
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 "",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 except Exception as e:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 self.disp(f"can't start {self.args.name}: {e}", error=True)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self.host.quit()
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
95
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
96
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 class Stop(base.CommandBase):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
98
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 def __init__(self, host):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 super(Stop, self).__init__(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 host, "stop", use_profile=False, help=_("stop a running application")
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
103
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 def add_parser_options(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 id_group = self.parser.add_mutually_exclusive_group(required=True)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 id_group.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 "name",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 nargs="?",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 help=_("name of the application to stop"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 id_group.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 "-i",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 "--id",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 help=_("identifier of the instance to stop"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 async def start(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 try:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 if self.args.name is not None:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 args = [self.args.name, "name"]
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 args = [self.args.id, "instance"]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3563
diff changeset
123 await self.host.bridge.application_stop(
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 *args,
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 "",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 except Exception as e:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 if self.args.name is not None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
129 self.disp(f"can't stop application {self.args.name!r}: {e}", error=True)
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 self.disp(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 f"can't stop application instance with id {self.args.id!r}: {e}",
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
133 error=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
134 )
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 self.host.quit()
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
138
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
139
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 class Exposed(base.CommandBase):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
141
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 def __init__(self, host):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 super(Exposed, self).__init__(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
144 host,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
145 "exposed",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
146 use_profile=False,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
147 use_output=C.OUTPUT_DICT,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
148 help=_("show data exposed by a running application"),
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
150
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 def add_parser_options(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 id_group = self.parser.add_mutually_exclusive_group(required=True)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 id_group.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 "name",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 nargs="?",
3563
267e4987b58b doc: fix remaining SàT references/typos + add `libervia-cli` missing commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
156 help=_("name of the application to check"),
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 id_group.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 "-i",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 "--id",
3563
267e4987b58b doc: fix remaining SàT references/typos + add `libervia-cli` missing commands
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
161 help=_("identifier of the instance to check"),
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
163
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 async def start(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 try:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 if self.args.name is not None:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 args = [self.args.name, "name"]
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 args = [self.args.id, "instance"]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3563
diff changeset
170 exposed_data_raw = await self.host.bridge.application_exposed_get(
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 *args,
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 "",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 except Exception as e:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 if self.args.name is not None:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 self.disp(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 f"can't get values exposed from application {self.args.name!r}: {e}",
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
178 error=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
179 )
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 self.disp(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 f"can't values exposed from application instance with id {self.args.id!r}: {e}",
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
183 error=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
184 )
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 exposed_data = data_format.deserialise(exposed_data_raw)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 await self.output(exposed_data)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 self.host.quit()
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
190
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
191
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 class Application(base.CommandBase):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 subcommands = (List, Start, Stop, Exposed)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
194
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 def __init__(self, host):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 super(Application, self).__init__(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
197 host,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
198 "application",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
199 use_profile=False,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
200 help=_("manage applications"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
201 aliases=["app"],
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 )