annotate sat_frontends/jp/cmd_application.py @ 3492:fa796612adad

plugin XEP-0277: better resilience to broken items: - if `author` element can't be found, `publisher` attribute, then `IQ`'s `from` attributes are used as fallback to find author jid - fix categories (tags) parsing if `author` element is not found - remove items which have failed parsing from `mbGet` results (instead of using `None`).
author Goffi <goffi@goffi.org>
date Sat, 27 Mar 2021 14:38:27 +0100
parents be6d91572633
children 267e4987b58b
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
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # jp: a SàT command line tool
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
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.i18n import _
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.tools.common import data_format
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat_frontends.jp.constants import Const as C
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__(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 host, "list", use_profile=False, use_output=C.OUTPUT_LIST,
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 help=_("list available applications")
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 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
37 # 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
38 # 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
39 self.parser.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 "-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
41 "--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
42 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
43 action="append",
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 choices=["available", "running"],
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 help=_("show applications with this status"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 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
49
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
50 # 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
51 # 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
52 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
53 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
54 else:
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 self.args.filters = ['available']
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
3374
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 try:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 found_apps = await self.host.bridge.applicationsList(self.args.filters)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 except Exception as e:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 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
61 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 await self.output(found_apps)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.host.quit()
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 class Start(base.CommandBase):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 """Start an application"""
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 def __init__(self, host):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 super(Start, self).__init__(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 host, "start", use_profile=False, help=_("start an application")
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
74
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def add_parser_options(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.parser.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 "name",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 help=_("name of the application to start"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
80
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 async def start(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 try:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 await self.host.bridge.applicationStart(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self.args.name,
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 "",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 except Exception as e:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 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
89 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 self.host.quit()
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
92
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
93
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 class Stop(base.CommandBase):
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 def __init__(self, host):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 super(Stop, self).__init__(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 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
99 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
100
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 def add_parser_options(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 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
103 id_group.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 "name",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 nargs="?",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 help=_("name of the application to stop"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 id_group.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 "-i",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 "--id",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 help=_("identifier of the instance to stop"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
113
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 async def start(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 try:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 if self.args.name is not None:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 args = [self.args.name, "name"]
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 args = [self.args.id, "instance"]
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 await self.host.bridge.applicationStop(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 *args,
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 "",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 except Exception as e:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 if self.args.name is not None:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self.disp(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 f"can't stop application {self.args.name!r}: {e}", error=True)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 self.disp(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 f"can't stop application instance with id {self.args.id!r}: {e}",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 error=True)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 self.host.quit()
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
135
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
136
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 class Exposed(base.CommandBase):
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 def __init__(self, host):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 super(Exposed, self).__init__(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 host, "exposed", use_profile=False, use_output=C.OUTPUT_DICT,
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 help=_("show data exposed by a running application")
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
144
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 def add_parser_options(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 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
147 id_group.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 "name",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 nargs="?",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 help=_("name of the application to stop"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 id_group.add_argument(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 "-i",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 "--id",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 help=_("identifier of the instance to stop"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 )
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 async def start(self):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 try:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 if self.args.name is not None:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 args = [self.args.name, "name"]
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 args = [self.args.id, "instance"]
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 exposed_data_raw = await self.host.bridge.applicationExposedGet(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 *args,
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 "",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 )
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 except Exception as e:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 if self.args.name is not None:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 self.disp(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 f"can't get values exposed from application {self.args.name!r}: {e}",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 error=True)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 self.disp(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 f"can't values exposed from application instance with id {self.args.id!r}: {e}",
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 error=True)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 else:
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 exposed_data = data_format.deserialise(exposed_data_raw)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 await self.output(exposed_data)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 self.host.quit()
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
182
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
183
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 class Application(base.CommandBase):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 subcommands = (List, Start, Stop, Exposed)
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
186
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 def __init__(self, host):
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 super(Application, self).__init__(
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 host, "application", use_profile=False, help=_("manage applications"),
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 aliases=['app'],
47755614b82a jp (application): new `application` (or `app`) commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 )