fprime-gds 3.4.0__py3-none-any.whl → 3.4.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastentrypoints.py +115 -0
- fprime_gds/common/encoders/seq_writer.py +2 -2
- fprime_gds/common/files/uplinker.py +4 -4
- fprime_gds/common/loaders/xml_loader.py +9 -36
- fprime_gds/common/pipeline/files.py +5 -4
- fprime_gds/common/pipeline/standard.py +23 -5
- fprime_gds/common/testing_fw/api.py +4 -3
- fprime_gds/executables/cli.py +19 -6
- fprime_gds/executables/comm.py +1 -1
- fprime_gds/executables/run_deployment.py +1 -1
- fprime_gds/executables/utils.py +11 -8
- fprime_gds/flask/app.py +4 -9
- fprime_gds/flask/default_settings.py +1 -12
- fprime_gds/flask/static/addons/commanding/command-history.js +23 -2
- fprime_gds/flask/updown.py +57 -6
- fprime_gds-3.4.2.dist-info/METADATA +441 -0
- {fprime_gds-3.4.0.dist-info → fprime_gds-3.4.2.dist-info}/RECORD +22 -22
- fprime_gds-3.4.2.dist-info/top_level.txt +2 -0
- fprime_gds/flask/flask_uploads.py +0 -542
- fprime_gds-3.4.0.dist-info/METADATA +0 -42
- fprime_gds-3.4.0.dist-info/top_level.txt +0 -1
- {fprime_gds-3.4.0.dist-info → fprime_gds-3.4.2.dist-info}/LICENSE.txt +0 -0
- {fprime_gds-3.4.0.dist-info → fprime_gds-3.4.2.dist-info}/NOTICE.txt +0 -0
- {fprime_gds-3.4.0.dist-info → fprime_gds-3.4.2.dist-info}/WHEEL +0 -0
- {fprime_gds-3.4.0.dist-info → fprime_gds-3.4.2.dist-info}/entry_points.txt +0 -0
fastentrypoints.py
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# noqa: D300,D400
|
2
|
+
# Copyright (c) 2016, Aaron Christianson
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are
|
7
|
+
# met:
|
8
|
+
#
|
9
|
+
# 1. Redistributions of source code must retain the above copyright
|
10
|
+
# notice, this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
17
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
18
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
19
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
22
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
"""
|
28
|
+
Monkey patch setuptools to write faster console_scripts with this format:
|
29
|
+
|
30
|
+
import sys
|
31
|
+
from mymodule import entry_function
|
32
|
+
sys.exit(entry_function())
|
33
|
+
|
34
|
+
This is better.
|
35
|
+
|
36
|
+
(c) 2016, Aaron Christianson
|
37
|
+
https://github.com/ninjaaron/fast-entry_points
|
38
|
+
"""
|
39
|
+
import re
|
40
|
+
|
41
|
+
from setuptools.command import easy_install
|
42
|
+
|
43
|
+
TEMPLATE = r"""
|
44
|
+
# -*- coding: utf-8 -*-
|
45
|
+
# EASY-INSTALL-ENTRY-SCRIPT: '{3}','{4}','{5}'
|
46
|
+
__requires__ = '{3}'
|
47
|
+
import re
|
48
|
+
import sys
|
49
|
+
|
50
|
+
from {0} import {1}
|
51
|
+
|
52
|
+
if __name__ == '__main__':
|
53
|
+
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
|
54
|
+
sys.exit({2}())
|
55
|
+
""".lstrip()
|
56
|
+
|
57
|
+
|
58
|
+
@classmethod
|
59
|
+
def get_args(cls, dist, header=None): # noqa: D205,D400
|
60
|
+
"""
|
61
|
+
Yield write_script() argument tuples for a distribution's
|
62
|
+
console_scripts and gui_scripts entry points.
|
63
|
+
"""
|
64
|
+
if header is None:
|
65
|
+
# pylint: disable=E1101
|
66
|
+
header = cls.get_header()
|
67
|
+
spec = str(dist.as_requirement())
|
68
|
+
for type_ in "console", "gui":
|
69
|
+
group = f'{type_}_scripts'
|
70
|
+
for name, ep in dist.get_entry_map(group).items():
|
71
|
+
# ensure_safe_name
|
72
|
+
if re.search(r"[\\/]", name):
|
73
|
+
raise ValueError("Path separators not allowed in script names")
|
74
|
+
script_text = TEMPLATE.format(
|
75
|
+
ep.module_name, ep.attrs[0], ".".join(ep.attrs), spec, group, name
|
76
|
+
)
|
77
|
+
# pylint: disable=E1101
|
78
|
+
args = cls._get_script_args(type_, name, header, script_text)
|
79
|
+
yield from args
|
80
|
+
|
81
|
+
|
82
|
+
# pylint: disable=E1101
|
83
|
+
easy_install.ScriptWriter.get_args = get_args
|
84
|
+
|
85
|
+
|
86
|
+
def main():
|
87
|
+
import os
|
88
|
+
import shutil
|
89
|
+
import sys
|
90
|
+
|
91
|
+
dests = sys.argv[1:] or ["."]
|
92
|
+
filename = re.sub(r"\.pyc$", ".py", __file__)
|
93
|
+
|
94
|
+
for dst in dests:
|
95
|
+
shutil.copy(filename, dst)
|
96
|
+
manifest_path = os.path.join(dst, "MANIFEST.in")
|
97
|
+
setup_path = os.path.join(dst, "setup.py")
|
98
|
+
|
99
|
+
# Insert the include statement to MANIFEST.in if not present
|
100
|
+
with open(manifest_path, "a+") as manifest:
|
101
|
+
manifest.seek(0)
|
102
|
+
manifest_content = manifest.read()
|
103
|
+
if "include fastentrypoints.py" not in manifest_content:
|
104
|
+
manifest.write(
|
105
|
+
("\n" if manifest_content else "") + "include fastentrypoints.py"
|
106
|
+
)
|
107
|
+
|
108
|
+
# Insert the import statement to setup.py if not present
|
109
|
+
with open(setup_path, "a+") as setup:
|
110
|
+
setup.seek(0)
|
111
|
+
setup_content = setup.read()
|
112
|
+
if "import fastentrypoints" not in setup_content:
|
113
|
+
setup.seek(0)
|
114
|
+
setup.truncate()
|
115
|
+
setup.write("import fastentrypoints\n" + setup_content)
|
@@ -137,9 +137,9 @@ class SeqBinaryWriter:
|
|
137
137
|
for cmd in seq_cmds_list:
|
138
138
|
sequence += self.__binaryCmdRecord(cmd)
|
139
139
|
size = len(sequence)
|
140
|
-
tb_txt =
|
140
|
+
tb_txt = "ANY" if self.__timebase == 0xFFFF else hex(self.__timebase)
|
141
141
|
|
142
|
-
print("Sequence is
|
142
|
+
print(f"Sequence is {size} bytes with timebase {tb_txt}")
|
143
143
|
|
144
144
|
header = b""
|
145
145
|
header += U32Type(
|
@@ -47,7 +47,9 @@ class UplinkQueue:
|
|
47
47
|
self.queue = queue.Queue()
|
48
48
|
self.__file_store = []
|
49
49
|
self.__exit = threading.Event()
|
50
|
-
self.__thread = threading.Thread(
|
50
|
+
self.__thread = threading.Thread(
|
51
|
+
target=self.run, name="UplinkerThread", args=()
|
52
|
+
)
|
51
53
|
self.__thread.start()
|
52
54
|
|
53
55
|
def enqueue(self, filepath, destination):
|
@@ -228,9 +230,7 @@ class FileUplinker(fprime_gds.common.handlers.DataHandler):
|
|
228
230
|
# Prevent multiple uplinks at once
|
229
231
|
if self.state != FileStates.IDLE:
|
230
232
|
msg = f"Currently uplinking file '{self.active.source}' cannot start uplinking '{file_obj.source}'"
|
231
|
-
raise FileUplinkerBusyException(
|
232
|
-
msg
|
233
|
-
)
|
233
|
+
raise FileUplinkerBusyException(msg)
|
234
234
|
self.state = FileStates.RUNNING
|
235
235
|
self.active = file_obj
|
236
236
|
self.active.open(TransmitFileState.READ)
|
@@ -61,6 +61,7 @@ class XmlLoader(dict_loader.DictLoader):
|
|
61
61
|
SER_MEMB_FMT_STR_TAG = "format_specifier"
|
62
62
|
SER_MEMB_DESC_TAG = "description"
|
63
63
|
SER_MEMB_TYPE_TAG = "type"
|
64
|
+
SER_MEMB_SIZE_TAG = "size"
|
64
65
|
|
65
66
|
# Xml section names and tags for array types
|
66
67
|
ARR_SECT = "arrays"
|
@@ -117,23 +118,6 @@ class XmlLoader(dict_loader.DictLoader):
|
|
117
118
|
# Parse xml and get element tree object we can retrieve data from
|
118
119
|
element_tree = etree.parse(fd, parser=xml_parser)
|
119
120
|
root = element_tree.getroot()
|
120
|
-
|
121
|
-
# Check version of the XML before continuing. Versions weren't published before 1.5.4. Only check major minor
|
122
|
-
# and point versions to allow for development versions to be allowed.
|
123
|
-
dict_version_string = root.attrib.get("framework_version", "1.5.4")
|
124
|
-
digits = []
|
125
|
-
# Process through the tokens of the version until we hit something that is not an int
|
126
|
-
for token in dict_version_string.split("."):
|
127
|
-
try:
|
128
|
-
digits.append(int(token))
|
129
|
-
except ValueError:
|
130
|
-
break
|
131
|
-
dict_version = tuple(digits)
|
132
|
-
if (
|
133
|
-
dict_version < MINIMUM_SUPPORTED_FRAMEWORK_VERSION
|
134
|
-
or dict_version > MAXIMUM_SUPPORTED_FRAMEWORK_VERSION
|
135
|
-
):
|
136
|
-
raise UnsupportedDictionaryVersionException(dict_version)
|
137
121
|
return root
|
138
122
|
|
139
123
|
@staticmethod
|
@@ -273,7 +257,15 @@ class XmlLoader(dict_loader.DictLoader):
|
|
273
257
|
fmt_str = memb.get(self.SER_MEMB_FMT_STR_TAG)
|
274
258
|
desc = memb.get(self.SER_MEMB_DESC_TAG)
|
275
259
|
memb_type_name = memb.get(self.SER_MEMB_TYPE_TAG)
|
260
|
+
memb_size = memb.get(self.SER_MEMB_SIZE_TAG)
|
276
261
|
type_obj = self.parse_type(memb_type_name, memb, xml_obj)
|
262
|
+
# memb_size is not None for member array
|
263
|
+
if(memb_size is not None):
|
264
|
+
type_obj = ArrayType.construct_type(
|
265
|
+
f"Array_{type_obj.__name__}_{memb_size}",
|
266
|
+
type_obj,
|
267
|
+
int(memb_size),
|
268
|
+
fmt_str)
|
277
269
|
|
278
270
|
members.append((name, type_obj, fmt_str, desc))
|
279
271
|
|
@@ -401,22 +393,3 @@ class XmlLoader(dict_loader.DictLoader):
|
|
401
393
|
raise exceptions.GseControllerParsingException(
|
402
394
|
msg
|
403
395
|
)
|
404
|
-
|
405
|
-
|
406
|
-
class UnsupportedDictionaryVersionException(Exception):
|
407
|
-
"""Dictionary is of unsupported version"""
|
408
|
-
|
409
|
-
def __init__(self, version):
|
410
|
-
"""Create a dictionary of a specific version"""
|
411
|
-
|
412
|
-
def pretty(version_tuple):
|
413
|
-
"""Pretty print version"""
|
414
|
-
return ".".join([str(item) for item in version_tuple])
|
415
|
-
|
416
|
-
super().__init__(
|
417
|
-
"Dictionary version {} is not in supported range: {}-{}. Please upgrade fprime-gds.".format(
|
418
|
-
pretty(version),
|
419
|
-
pretty(MINIMUM_SUPPORTED_FRAMEWORK_VERSION),
|
420
|
-
pretty(MAXIMUM_SUPPORTED_FRAMEWORK_VERSION),
|
421
|
-
)
|
422
|
-
)
|
@@ -7,7 +7,7 @@ communications layer.
|
|
7
7
|
|
8
8
|
@author mstarch
|
9
9
|
"""
|
10
|
-
import
|
10
|
+
from pathlib import Path
|
11
11
|
import fprime_gds.common.files.downlinker
|
12
12
|
import fprime_gds.common.files.uplinker
|
13
13
|
|
@@ -43,10 +43,11 @@ class Filing:
|
|
43
43
|
)
|
44
44
|
file_decoder.register(self.__downlinker)
|
45
45
|
distributor.register("FW_PACKET_HAND", self.__uplinker)
|
46
|
-
|
46
|
+
try:
|
47
|
+
Path(down_store).mkdir(parents=True, exist_ok=True)
|
48
|
+
except PermissionError:
|
47
49
|
raise PermissionError(
|
48
|
-
f"{down_store} is not writable.
|
49
|
-
"Fix permissions or change storage directory with --file-storage-directory."
|
50
|
+
f"{down_store} is not writable. Fix permissions or change storage directory with --file-storage-directory."
|
50
51
|
)
|
51
52
|
|
52
53
|
@property
|
@@ -44,6 +44,8 @@ class StandardPipeline:
|
|
44
44
|
self.client_socket = None
|
45
45
|
self.logger = None
|
46
46
|
self.dictionary_path = None
|
47
|
+
self.up_store = None
|
48
|
+
self.down_store = None
|
47
49
|
|
48
50
|
self.__dictionaries = dictionaries.Dictionaries()
|
49
51
|
self.__coders = encoding.EncodingDecoding()
|
@@ -52,7 +54,7 @@ class StandardPipeline:
|
|
52
54
|
self.__transport_type = ThreadedTCPSocketClient
|
53
55
|
|
54
56
|
def setup(
|
55
|
-
self, config, dictionary,
|
57
|
+
self, config, dictionary, file_store, logging_prefix=None, packet_spec=None
|
56
58
|
):
|
57
59
|
"""
|
58
60
|
Setup the standard pipeline for moving data from the middleware layer through the GDS layers using the standard
|
@@ -60,11 +62,23 @@ class StandardPipeline:
|
|
60
62
|
|
61
63
|
:param config: config object used when constructing the pipeline.
|
62
64
|
:param dictionary: dictionary path. Used to setup loading of dictionaries.
|
63
|
-
:param
|
65
|
+
:param file_store: uplink/downlink storage directory
|
64
66
|
:param logging_prefix: logging prefix. Defaults to not logging at all.
|
65
67
|
:param packet_spec: location of packetized telemetry XML specification.
|
66
68
|
"""
|
67
|
-
assert
|
69
|
+
assert (
|
70
|
+
dictionary is not None and Path(dictionary).is_file()
|
71
|
+
), f"Dictionary {dictionary} does not exist"
|
72
|
+
# File storage configuration for uplink and downlink
|
73
|
+
self.up_store = Path(file_store) / "fprime-uplink"
|
74
|
+
self.down_store = Path(file_store) / "fprime-downlink"
|
75
|
+
try:
|
76
|
+
self.down_store.mkdir(parents=True, exist_ok=True)
|
77
|
+
self.up_store.mkdir(parents=True, exist_ok=True)
|
78
|
+
except PermissionError:
|
79
|
+
raise PermissionError(
|
80
|
+
f"{file_store} is not writable. Fix permissions or change storage directory with --file-storage-directory."
|
81
|
+
)
|
68
82
|
self.dictionary_path = Path(dictionary)
|
69
83
|
# Loads the distributor and client socket
|
70
84
|
self.distributor = fprime_gds.common.distributor.distributor.Distributor(config)
|
@@ -76,7 +90,7 @@ class StandardPipeline:
|
|
76
90
|
)
|
77
91
|
self.histories.setup_histories(self.coders)
|
78
92
|
self.files.setup_file_handling(
|
79
|
-
down_store,
|
93
|
+
self.down_store,
|
80
94
|
self.coders.file_encoder,
|
81
95
|
self.coders.file_decoder,
|
82
96
|
self.distributor,
|
@@ -152,7 +166,11 @@ class StandardPipeline:
|
|
152
166
|
outgoing_tag: this pipeline will produce data for supplied tag (FSW, GUI). Default: FSW
|
153
167
|
"""
|
154
168
|
# Backwards compatibility with the old method .connect(host, port)
|
155
|
-
if
|
169
|
+
if (
|
170
|
+
isinstance(incoming_tag, int)
|
171
|
+
and ":" not in connection_uri
|
172
|
+
and outgoing_tag == RoutingTag.FSW
|
173
|
+
):
|
156
174
|
connection_uri = f"{connection_uri}:{incoming_tag}"
|
157
175
|
incoming_tag = RoutingTag.GUI
|
158
176
|
self.client_socket.connect(connection_uri, incoming_tag, outgoing_tag)
|
@@ -402,7 +402,7 @@ class IntegrationTestAPI(DataHandler):
|
|
402
402
|
return self.await_event_sequence(events, start=start, timeout=timeout)
|
403
403
|
return self.await_event(events, start=start, timeout=timeout)
|
404
404
|
|
405
|
-
def send_and_assert_command(self, command, args=[], max_delay=None, timeout=5, events=None):
|
405
|
+
def send_and_assert_command(self, command, args=[], max_delay=None, timeout=5, events=None, commander="cmdDisp"):
|
406
406
|
"""
|
407
407
|
This helper will send a command and verify that the command was dispatched and completed
|
408
408
|
within the F' deployment. This helper can retroactively check that the delay between
|
@@ -414,12 +414,13 @@ class IntegrationTestAPI(DataHandler):
|
|
414
414
|
max_delay: the maximum allowable delay between dispatch and completion (int/float)
|
415
415
|
timeout: the number of seconds to wait before terminating the search (int)
|
416
416
|
events: extra event predicates to check between dispatch and complete
|
417
|
+
commander: the command dispatching component. Defaults to cmdDisp
|
417
418
|
Return:
|
418
419
|
returns a list of the EventData objects found by the search
|
419
420
|
"""
|
420
421
|
cmd_id = self.translate_command_name(command)
|
421
|
-
dispatch = [self.get_event_pred("
|
422
|
-
complete = [self.get_event_pred("
|
422
|
+
dispatch = [self.get_event_pred(f"{commander}.OpCodeDispatched", [cmd_id, None])]
|
423
|
+
complete = [self.get_event_pred(f"{commander}.OpCodeCompleted", [cmd_id])]
|
423
424
|
events = dispatch + (events if events else []) + complete
|
424
425
|
results = self.send_and_assert_event(command, args, events, timeout=timeout)
|
425
426
|
if max_delay is not None:
|
fprime_gds/executables/cli.py
CHANGED
@@ -547,18 +547,31 @@ class FileHandlingParser(ParserBase):
|
|
547
547
|
|
548
548
|
return {
|
549
549
|
("--file-storage-directory",): {
|
550
|
-
"dest": "
|
550
|
+
"dest": "files_storage_directory",
|
551
551
|
"action": "store",
|
552
|
-
"default": "/tmp/" + username
|
552
|
+
"default": "/tmp/" + username,
|
553
553
|
"required": False,
|
554
554
|
"type": str,
|
555
|
-
"help": "
|
556
|
-
}
|
555
|
+
"help": "Directory to store uplink and downlink files. Default: %(default)s",
|
556
|
+
},
|
557
|
+
("--remote-sequence-directory",): {
|
558
|
+
"dest": "remote_sequence_directory",
|
559
|
+
"action": "store",
|
560
|
+
"default": "/seq",
|
561
|
+
"required": False,
|
562
|
+
"type": str,
|
563
|
+
"help": "Directory to save command sequence binaries, on the remote FSW. Default: %(default)s",
|
564
|
+
},
|
557
565
|
}
|
558
566
|
|
559
567
|
def handle_arguments(self, args, **kwargs):
|
560
568
|
"""Handle arguments as parsed"""
|
561
|
-
|
569
|
+
try:
|
570
|
+
Path(args.files_storage_directory).mkdir(parents=True, exist_ok=True)
|
571
|
+
except PermissionError:
|
572
|
+
raise PermissionError(
|
573
|
+
f"{args.files_storage_directory} is not writable. Fix permissions or change storage directory with --file-storage-directory."
|
574
|
+
)
|
562
575
|
return args
|
563
576
|
|
564
577
|
|
@@ -584,7 +597,7 @@ class StandardPipelineParser(CompositeParser):
|
|
584
597
|
pipeline_arguments = {
|
585
598
|
"config": ConfigManager(),
|
586
599
|
"dictionary": args_ns.dictionary,
|
587
|
-
"
|
600
|
+
"file_store": args_ns.files_storage_directory,
|
588
601
|
"packet_spec": args_ns.packet_spec,
|
589
602
|
"logging_prefix": args_ns.logs,
|
590
603
|
}
|
fprime_gds/executables/comm.py
CHANGED
@@ -64,7 +64,7 @@ def main():
|
|
64
64
|
)
|
65
65
|
fprime_gds.common.communication.checksum = args.checksum_type
|
66
66
|
if args.comm_adapter == "none":
|
67
|
-
print("[ERROR] Comm adapter set to 'none'. Nothing to do but exit.")
|
67
|
+
print("[ERROR] Comm adapter set to 'none'. Nothing to do but exit.", file=sys.stderr)
|
68
68
|
sys.exit(-1)
|
69
69
|
|
70
70
|
# Create the handling components for either side of this script, adapter for hardware, and ground for the GDS side
|
@@ -168,7 +168,7 @@ def main():
|
|
168
168
|
if parsed_args.adapter == "ip":
|
169
169
|
launchers.append(launch_app)
|
170
170
|
else:
|
171
|
-
print("[WARNING] App cannot be auto-launched without IP adapter")
|
171
|
+
print("[WARNING] App cannot be auto-launched without IP adapter", file=sys.stderr)
|
172
172
|
|
173
173
|
# Launch the desired GUI package
|
174
174
|
if parsed_args.gui == "html":
|
fprime_gds/executables/utils.py
CHANGED
@@ -146,11 +146,12 @@ def get_artifacts_root() -> Path:
|
|
146
146
|
ini_settings = IniSettings.load(ini_file)
|
147
147
|
except FprimeLocationUnknownException:
|
148
148
|
print(
|
149
|
-
"[ERROR] Not in fprime project and no deployment path provided, unable to find dictionary and/or app"
|
149
|
+
"[ERROR] Not in fprime project and no deployment path provided, unable to find dictionary and/or app",
|
150
|
+
file=sys.stderr
|
150
151
|
)
|
151
152
|
sys.exit(-1)
|
152
153
|
except FprimeSettingsException as e:
|
153
|
-
print("[ERROR]", e)
|
154
|
+
print("[ERROR]", e, file=sys.stderr)
|
154
155
|
sys.exit(-1)
|
155
156
|
assert (
|
156
157
|
"install_destination" in ini_settings
|
@@ -165,17 +166,18 @@ def find_app(root: Path) -> Path:
|
|
165
166
|
bin_dir = root / "bin"
|
166
167
|
|
167
168
|
if not bin_dir.exists():
|
168
|
-
print(f"[ERROR] binary location {bin_dir} does not exist")
|
169
|
+
print(f"[ERROR] binary location {bin_dir} does not exist", file=sys.stderr)
|
169
170
|
sys.exit(-1)
|
170
171
|
|
171
172
|
files = [child for child in bin_dir.iterdir() if child.is_file()]
|
172
173
|
if not files:
|
173
|
-
print(f"[ERROR] App not found in {bin_dir}")
|
174
|
+
print(f"[ERROR] App not found in {bin_dir}", file=sys.stderr)
|
174
175
|
sys.exit(-1)
|
175
176
|
|
176
177
|
if len(files) > 1:
|
177
178
|
print(
|
178
|
-
f"[ERROR] Multiple app candidates in binary location {bin_dir}. Specify app manually with --app."
|
179
|
+
f"[ERROR] Multiple app candidates in binary location {bin_dir}. Specify app manually with --app.",
|
180
|
+
file=sys.stderr
|
179
181
|
)
|
180
182
|
sys.exit(-1)
|
181
183
|
|
@@ -186,7 +188,7 @@ def find_dict(root: Path) -> Path:
|
|
186
188
|
dict_dir = root / "dict"
|
187
189
|
|
188
190
|
if not dict_dir.exists():
|
189
|
-
print(f"[ERROR] dictionary location {dict_dir} does not exist")
|
191
|
+
print(f"[ERROR] dictionary location {dict_dir} does not exist", file=sys.stderr)
|
190
192
|
sys.exit(-1)
|
191
193
|
|
192
194
|
files = [
|
@@ -196,12 +198,13 @@ def find_dict(root: Path) -> Path:
|
|
196
198
|
]
|
197
199
|
|
198
200
|
if not files:
|
199
|
-
print(f"[ERROR] No xml dictionary found in dictionary location {dict_dir}")
|
201
|
+
print(f"[ERROR] No xml dictionary found in dictionary location {dict_dir}", file=sys.stderr)
|
200
202
|
sys.exit(-1)
|
201
203
|
|
202
204
|
if len(files) > 1:
|
203
205
|
print(
|
204
|
-
f"[ERROR] Multiple xml dictionaries found in dictionary location {dict_dir}. Specify dictionary manually with --dictionary."
|
206
|
+
f"[ERROR] Multiple xml dictionaries found in dictionary location {dict_dir}. Specify dictionary manually with --dictionary.",
|
207
|
+
file=sys.stderr
|
205
208
|
)
|
206
209
|
sys.exit(-1)
|
207
210
|
|
fprime_gds/flask/app.py
CHANGED
@@ -30,7 +30,6 @@ import fprime_gds.flask.sequence
|
|
30
30
|
import fprime_gds.flask.stats
|
31
31
|
import fprime_gds.flask.updown
|
32
32
|
from fprime_gds.executables.cli import ParserBase, StandardPipelineParser
|
33
|
-
from fprime_gds.flask import flask_uploads
|
34
33
|
|
35
34
|
from . import components
|
36
35
|
|
@@ -49,8 +48,7 @@ def construct_app():
|
|
49
48
|
2. Setup JSON encoding for Flask and flask_restful to handle F prime types natively
|
50
49
|
3. Setup standard pipeline used throughout the system
|
51
50
|
4. Create Restful API for registering flask items
|
52
|
-
5.
|
53
|
-
6. Register all restful endpoints
|
51
|
+
5. Register all restful endpoints
|
54
52
|
|
55
53
|
:return: setup app
|
56
54
|
"""
|
@@ -77,9 +75,6 @@ def construct_app():
|
|
77
75
|
|
78
76
|
# Restful API registration
|
79
77
|
api = fprime_gds.flask.errors.setup_error_handling(app)
|
80
|
-
# File upload configuration, 1 set for everything
|
81
|
-
uplink_set = flask_uploads.UploadSet("uplink", flask_uploads.ALL)
|
82
|
-
flask_uploads.configure_uploads(app, [uplink_set])
|
83
78
|
|
84
79
|
# Application routes
|
85
80
|
api.add_resource(
|
@@ -137,7 +132,7 @@ def construct_app():
|
|
137
132
|
api.add_resource(
|
138
133
|
fprime_gds.flask.updown.FileUploads,
|
139
134
|
"/upload/files",
|
140
|
-
resource_class_args=[pipeline.files.uplinker,
|
135
|
+
resource_class_args=[pipeline.files.uplinker, pipeline.up_store],
|
141
136
|
)
|
142
137
|
api.add_resource(
|
143
138
|
fprime_gds.flask.updown.FileDownload,
|
@@ -150,9 +145,9 @@ def construct_app():
|
|
150
145
|
"/sequence",
|
151
146
|
resource_class_args=[
|
152
147
|
args_ns.dictionary,
|
153
|
-
|
148
|
+
pipeline.up_store,
|
154
149
|
pipeline.files.uplinker,
|
155
|
-
|
150
|
+
args_ns.remote_sequence_directory,
|
156
151
|
],
|
157
152
|
)
|
158
153
|
api.add_resource(
|
@@ -9,23 +9,12 @@
|
|
9
9
|
#
|
10
10
|
####
|
11
11
|
import os
|
12
|
-
import getpass
|
13
|
-
|
14
|
-
# Select uploads directory and create it
|
15
|
-
username = getpass.getuser()
|
16
|
-
uplink_dir = os.environ.get("UP_FILES_DIR", "/tmp/" + username + "/fprime-uplink/")
|
17
|
-
DOWNLINK_DIR = os.environ.get("DOWN_FILES_DIR", "/tmp/" + username + "/fprime-downlink/")
|
18
12
|
|
19
13
|
STANDARD_PIPELINE_ARGUMENTS = os.environ.get("STANDARD_PIPELINE_ARGUMENTS").split("|")
|
20
14
|
|
21
15
|
SERVE_LOGS = os.environ.get("SERVE_LOGS", "YES") == "YES"
|
22
|
-
UPLOADED_UPLINK_DEST = uplink_dir
|
23
|
-
UPLOADS_DEFAULT_DEST = uplink_dir
|
24
|
-
REMOTE_SEQ_DIRECTORY = "/seq"
|
25
|
-
MAX_CONTENT_LENGTH = 32 * 1024 * 1024 # Max length of request is 32MiB
|
26
16
|
|
17
|
+
MAX_CONTENT_LENGTH = 32 * 1024 * 1024 # Max length of request is 32MiB
|
27
18
|
|
28
|
-
for directory in [UPLOADED_UPLINK_DEST, UPLOADS_DEFAULT_DEST, DOWNLINK_DIR]:
|
29
|
-
os.makedirs(directory, exist_ok=True)
|
30
19
|
|
31
20
|
# TODO: load real config
|
@@ -102,8 +102,29 @@ Vue.component("command-history", {
|
|
102
102
|
cmd.full_name = template.full_name;
|
103
103
|
// Can only set command if it is a child of a command input
|
104
104
|
if (this.$parent.selectCmd) {
|
105
|
-
|
105
|
+
// command-input expects an array of strings as arguments
|
106
|
+
this.$parent.selectCmd(cmd.full_name, this.preprocess_args(cmd.args));
|
107
|
+
}
|
108
|
+
},
|
109
|
+
/**
|
110
|
+
* Process the arguments for a command. If the argument is (or contains) a number, it
|
111
|
+
* is converted to a string. Other types that should be pre-processed can be added here.
|
112
|
+
*
|
113
|
+
* @param {*} args
|
114
|
+
* @returns args processed for command input (numbers converted to strings)
|
115
|
+
*/
|
116
|
+
preprocess_args(args) {
|
117
|
+
if (Array.isArray(args)) {
|
118
|
+
return args.map(el => this.preprocess_args(el));
|
119
|
+
} else if (typeof args === 'object' && args !== null) {
|
120
|
+
return Object.fromEntries(
|
121
|
+
Object.entries(args).map(([key, value]) => [key, this.preprocess_args(value)])
|
122
|
+
);
|
123
|
+
} else if (typeof args === 'number') {
|
124
|
+
return args.toString();
|
125
|
+
} else {
|
126
|
+
return args;
|
106
127
|
}
|
107
128
|
}
|
108
129
|
}
|
109
|
-
});
|
130
|
+
});
|
fprime_gds/flask/updown.py
CHANGED
@@ -11,6 +11,9 @@ import os
|
|
11
11
|
|
12
12
|
import flask
|
13
13
|
import flask_restful
|
14
|
+
from werkzeug.datastructures import FileStorage
|
15
|
+
from werkzeug.utils import secure_filename
|
16
|
+
from pathlib import Path
|
14
17
|
|
15
18
|
|
16
19
|
class Destination(flask_restful.Resource):
|
@@ -51,12 +54,12 @@ class FileUploads(flask_restful.Resource):
|
|
51
54
|
A data model for the current uplinking file set.
|
52
55
|
"""
|
53
56
|
|
54
|
-
def __init__(self, uplinker,
|
57
|
+
def __init__(self, uplinker, dest_dir):
|
55
58
|
"""
|
56
59
|
Constructor: setup the uplinker and argument parsing
|
57
60
|
"""
|
58
61
|
self.uplinker = uplinker
|
59
|
-
self.
|
62
|
+
self.dest_dir = dest_dir
|
60
63
|
self.parser = flask_restful.reqparse.RequestParser()
|
61
64
|
self.parser.add_argument(
|
62
65
|
"action", required=True, help="Action to take against files"
|
@@ -99,11 +102,9 @@ class FileUploads(flask_restful.Resource):
|
|
99
102
|
failed = []
|
100
103
|
for key, file in flask.request.files.items():
|
101
104
|
try:
|
102
|
-
filename = self.
|
105
|
+
filename = self.save(file)
|
103
106
|
flask.current_app.logger.info(f"Received file. Saved to: {filename}")
|
104
|
-
self.uplinker.enqueue(
|
105
|
-
os.path.join(self.uplink_set.config.destination, filename)
|
106
|
-
)
|
107
|
+
self.uplinker.enqueue(os.path.join(self.dest_dir, filename))
|
107
108
|
successful.append(key)
|
108
109
|
except Exception as exc:
|
109
110
|
flask.current_app.logger.warning(
|
@@ -112,6 +113,56 @@ class FileUploads(flask_restful.Resource):
|
|
112
113
|
failed.append(key)
|
113
114
|
return {"successful": successful, "failed": failed}
|
114
115
|
|
116
|
+
def save(self, file_storage: FileStorage):
|
117
|
+
"""
|
118
|
+
This saves a `werkzeug.FileStorage` into this upload set.
|
119
|
+
|
120
|
+
:param file_storage: The uploaded file to save.
|
121
|
+
"""
|
122
|
+
if not isinstance(file_storage, FileStorage):
|
123
|
+
raise TypeError("file_storage must be a werkzeug.FileStorage")
|
124
|
+
|
125
|
+
filename = Path(secure_filename(file_storage.filename)).name
|
126
|
+
dest_dir = Path(self.dest_dir)
|
127
|
+
|
128
|
+
try:
|
129
|
+
dest_dir.mkdir(parents=True, exist_ok=True)
|
130
|
+
except PermissionError:
|
131
|
+
raise PermissionError(
|
132
|
+
f"{dest_dir} is not writable. Fix permissions or change storage directory with --file-storage-directory."
|
133
|
+
)
|
134
|
+
|
135
|
+
# resolve conflict may not be needed
|
136
|
+
if (dest_dir / filename).exists():
|
137
|
+
filename = self.resolve_conflict(dest_dir, filename)
|
138
|
+
|
139
|
+
target = dest_dir / filename
|
140
|
+
file_storage.save(str(target))
|
141
|
+
|
142
|
+
return filename
|
143
|
+
|
144
|
+
def resolve_conflict(self, target_folder: Path, filename: str):
|
145
|
+
"""
|
146
|
+
If a file with the selected name already exists in the target folder,
|
147
|
+
this method is called to resolve the conflict. It should return a new
|
148
|
+
filename for the file.
|
149
|
+
|
150
|
+
The default implementation splits the name and extension and adds a
|
151
|
+
suffix to the name consisting of an underscore and a number, and tries
|
152
|
+
that until it finds one that doesn't exist.
|
153
|
+
|
154
|
+
:param target_folder: The absolute path to the target.
|
155
|
+
:param filename: The file's original filename.
|
156
|
+
"""
|
157
|
+
path = Path(filename)
|
158
|
+
name, ext = path.stem, path.suffix
|
159
|
+
count = 0
|
160
|
+
while True:
|
161
|
+
count = count + 1
|
162
|
+
newname = f"{name}_{count}{ext}"
|
163
|
+
if not (Path(target_folder) / newname).exists():
|
164
|
+
return newname
|
165
|
+
|
115
166
|
|
116
167
|
class FileDownload(flask_restful.Resource):
|
117
168
|
""" """
|