Skip to content

Commit c7bc799

Browse files
committed
Add method to run a file action
1 parent 66318cc commit c7bc799

10 files changed

Lines changed: 565 additions & 254 deletions

File tree

yamcs-client/src/yamcs/filetransfer/client.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import functools
22
import json
3-
from typing import Any, Callable, Iterable, List, Mapping, Optional
3+
from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional
44

5+
from google.protobuf import json_format, struct_pb2
56
from yamcs.core.context import Context
67
from yamcs.core.exceptions import NotFound
78
from yamcs.core.futures import WebSocketSubscriptionFuture
@@ -260,20 +261,40 @@ def get_filelist(
260261
message.ParseFromString(response.content)
261262
return RemoteFileListing(message)
262263

263-
def pause_transfer(self, id: str):
264+
def pause_transfer(self, id: str) -> None:
264265
url = f"/filetransfer/{self._instance}/{self._service}/transfers/{id}:pause"
265266
self.ctx.post_proto(url)
266267

267-
def resume_transfer(self, id: str):
268+
def resume_transfer(self, id: str) -> None:
268269
url = f"/filetransfer/{self._instance}/{self._service}/transfers/{id}:resume"
269270
self.ctx.post_proto(url)
270271

271-
def cancel_transfer(self, id: str):
272+
def cancel_transfer(self, id: str) -> None:
272273
url = f"/filetransfer/{self._instance}/{self._service}/transfers/{id}:cancel"
273274
self.ctx.post_proto(url)
274275

276+
def run_file_action(
277+
self,
278+
file: str,
279+
action: str,
280+
message: Optional[Mapping[str, Any]] = None,
281+
) -> Dict[str, Any]:
282+
req = filetransfer_pb2.RunFileActionRequest()
283+
req.file = file
284+
req.action = action
285+
if message:
286+
req.message.update(message)
287+
288+
url = f"/filetransfer/{self._instance}/{self._service}/files:runFileAction"
289+
response = self.ctx.post_proto(url, data=req.SerializeToString())
290+
response_message = struct_pb2.Struct()
291+
response_message.ParseFromString(response.content)
292+
return json_format.MessageToDict(response_message)
293+
275294
def create_transfer_subscription(
276-
self, on_data: Optional[Callable[[Transfer], None]] = None, timeout: float = 60
295+
self,
296+
on_data: Optional[Callable[[Transfer], None]] = None,
297+
timeout: float = 60,
277298
) -> TransferSubscription:
278299
options = filetransfer_pb2.SubscribeTransfersRequest()
279300
options.instance = self._instance

yamcs-client/src/yamcs/filetransfer/model.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import datetime
22
import threading
3-
from typing import TYPE_CHECKING, Any, Callable, List, Mapping, Optional
3+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Mapping, Optional
44

55
from yamcs.core.helpers import parse_server_time
66
from yamcs.protobuf.filetransfer import filetransfer_pb2
77

88
if TYPE_CHECKING:
9-
from yamcs.filetransfer.client import ServiceClient
9+
from yamcs.filetransfer.client import (
10+
FileListSubscription,
11+
ServiceClient,
12+
TransferSubscription,
13+
)
1014

1115

1216
class Service:
@@ -170,29 +174,54 @@ def get_filelist(
170174
options=options,
171175
)
172176

173-
def pause_transfer(self, id: str):
177+
def pause_transfer(self, id: str) -> None:
174178
"""
175179
Pauses a transfer
176180
"""
177181
self._service_client.pause_transfer(id)
178182

179-
def resume_transfer(self, id: str):
183+
def resume_transfer(self, id: str) -> None:
180184
"""
181185
Resume a transfer
182186
"""
183187
self._service_client.resume_transfer(id)
184188

185-
def cancel_transfer(self, id: str):
189+
def cancel_transfer(self, id: str) -> None:
186190
"""
187191
Cancel a transfer
188192
"""
189193
self._service_client.cancel_transfer(id)
190194

195+
def run_file_action(
196+
self,
197+
file: str,
198+
action: str,
199+
message: Optional[Mapping[str, Any]] = None,
200+
) -> Dict[str, Any]:
201+
"""
202+
Run an action on a remote file.
203+
204+
Available actions depend on the specific file transfer implementation that
205+
is in use use.
206+
207+
.. versionadded:: 1.9.6
208+
209+
:param file:
210+
Remote file identifier
211+
:param action:
212+
Action identifier
213+
:param message:
214+
Action message
215+
:return:
216+
Action result (if the action returns anything)
217+
"""
218+
return self._service_client.run_file_action(file, action, message)
219+
191220
def create_transfer_subscription(
192221
self,
193222
on_data: Optional[Callable[["Transfer"], None]] = None,
194223
timeout: float = 60,
195-
):
224+
) -> "TransferSubscription":
196225
"""
197226
Create a new transfer subscription.
198227
@@ -213,7 +242,7 @@ def create_filelist_subscription(
213242
self,
214243
on_data: Optional[Callable[["RemoteFileListing"], None]] = None,
215244
timeout: float = 60,
216-
):
245+
) -> "FileListSubscription":
217246
"""
218247
Create a new filelist subscription.
219248

yamcs-client/src/yamcs/link/client.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import functools
2-
from typing import Callable, Mapping, Optional
2+
from typing import Any, Callable, Dict, Mapping, Optional
33

4+
from google.protobuf import json_format, struct_pb2
45
from yamcs.core.context import Context
56
from yamcs.core.futures import WebSocketSubscriptionFuture
67
from yamcs.core.subscriptions import WebSocketSubscriptionManager
@@ -106,21 +107,30 @@ def disable_link(self):
106107
url = f"/links/{self._instance}/{self._link}:disable"
107108
self.ctx.post_proto(url, data=req.SerializeToString())
108109

109-
def run_action(self, action: str, message: Optional[Mapping] = None):
110+
def run_action(
111+
self,
112+
action: str,
113+
message: Optional[Mapping[str, Any]] = None,
114+
) -> Dict[str, Any]:
110115
"""
111116
Runs the given action for this link
112117
113118
:param action:
114119
action identifier
115120
:param message:
116121
action message
122+
:return:
123+
Action result (if the action returns anything)
117124
"""
118125
req = links_pb2.RunActionRequest()
119126
if message:
120127
req.message.update(message)
121128

122129
url = f"/links/{self._instance}/{self._link}/actions/{action}"
123-
self.ctx.post_proto(url, data=req.message.SerializeToString())
130+
response = self.ctx.post_proto(url, data=req.message.SerializeToString())
131+
response_message = struct_pb2.Struct()
132+
response_message.ParseFromString(response.content)
133+
return json_format.MessageToDict(response_message)
124134

125135
def get_cop1_config(self) -> Cop1Config:
126136
"""

yamcs-client/src/yamcs/protobuf/actions/actions_pb2.py

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)