Skip to content

Commit 93cac52

Browse files
authored
Merge pull request #25 from sgaisser/spelling_and_documentation
Spelling and documentation
2 parents 4d84e8b + 63043f8 commit 93cac52

File tree

9 files changed

+85
-43
lines changed

9 files changed

+85
-43
lines changed

docs/api/cfdp.handler.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Destination Handler Module
2525
:undoc-members:
2626
:show-inheritance:
2727

28-
Defintions Module
28+
Definitions Module
2929
-------------------------------------
3030

3131
.. automodule:: cfdppy.handler.defs

docs/examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ which cross-tests the `cfdp-py` CFDP implementation with the
1414

1515
Finally, you can see a more complex example also featuring more features of the CFDP state machines
1616
`here <https://github.com/us-irs/cfdp-py/tree/main/examples/cfdp-cli-udp>`_. This example
17-
uses UDP servers for communication and explicitely separates the local and remote entity
17+
uses UDP servers for communication and explicitly separates the local and remote entity
1818
application.

docs/introduction.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ The CCSDS File Delivery Protocol (CFDP)
33
=========================================
44

55
The basic idea of CFDP is to convert files of any size into a stream of packets called packet
6-
data units (PDU). CFPD has an unacknowledged and acknowledged mode, with the option to request
6+
data units (PDU). CFDP has an unacknowledged and acknowledged mode, with the option to request
77
a transaction closure for the unacknowledged mode. Using the unacknowledged mode with no
88
transaction closure is applicable for simplex communication paths, while the unacknowledged mode
99
with closure is the easiest way to get a confirmation of a successful file transfer, including a
1010
CRC check on the remote side to verify file integrity. The acknowledged mode is the most complex
11-
mode which includes multiple mechanism to ensure succesfull packet transaction even for unreliable
11+
mode which includes multiple mechanism to ensure successful packet transaction even for unreliable
1212
connections, including lost segment detection. As such, it can be compared to a specialized TCP
1313
for file transfers with remote systems.
1414

@@ -23,7 +23,7 @@ The :py:class:`cfdppy.handler.source.SourceHandler` converts a
2323
:py:class:`cfdppy.request.PutRequest` into all packet data units (PDUs) which need to be
2424
sent to a remote CFDP entity to perform a File Copy operation to a remote entity.
2525

26-
The source entity allows freedom of communcation by only generating the packets required to be
26+
The source entity allows freedom of communication by only generating the packets required to be
2727
sent, and leaving the actual transmission of those packets to the user. The packets are returned
2828
to the user using the :py:meth:`cfdppy.handler.source.SourceHandler.get_next_packet` call.
2929
It should be noted that for regular file transfers, each state machine call will map to one
@@ -64,7 +64,7 @@ example generated by the :py:class:`spacepackets.cfdp.pdu.file_data.FileDataPdu`
6464
into the destination handler and will be assembled into a file.
6565

6666
A destination entity might still generate packets which need to be sent back to the source entity
67-
of the file transfer. However, it allows freedom of communcation like the source entity by leaving
67+
of the file transfer. However, it allows freedom of communication like the source entity by leaving
6868
the actual transmission of generated packets to the user. The packets are returned to the user
6969
using the :py:meth:`cfdppy.handler.dest.DestHandler.get_next_packet` call.
7070

examples/cfdp-simple/file-copy-example.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
"""This example shows a end-to-end transfer of a small file using the CFDP high level
2+
"""This example shows an end-to-end transfer of a small file using the CFDP high level
33
components provided by the tmtccmd package."""
44

55
import argparse
@@ -105,7 +105,7 @@ def abandoned_cb(
105105
self, transaction_id: TransactionId, cond: ConditionCode, progress: int
106106
) -> None:
107107
_LOGGER.warning(
108-
f"Received Abanadoned Fault for transaction {transaction_id!r} with condition "
108+
f"Received Abandoned Fault for transaction {transaction_id!r} with condition "
109109
f"code {cond!r}. Progress: {progress}"
110110
)
111111

@@ -283,10 +283,8 @@ def main() -> None:
283283
source_thread.join()
284284
dest_thread.join()
285285

286-
src_file_content = None
287286
with open(SOURCE_FILE) as file:
288287
src_file_content = file.read()
289-
dest_file_content = None
290288
with open(DEST_FILE) as file:
291289
dest_file_content = file.read()
292290
assert src_file_content == dest_file_content

src/cfdppy/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class InvalidTransactionSeqNum(Exception):
8080
def __init__(self, expected: UnsignedByteField, received: UnsignedByteField):
8181
self.expected = expected
8282
self.received = received
83-
super().__init__(f"expected sequence number {expected}, reiceved {self.received}")
83+
super().__init__(f"expected sequence number {expected}, received {self.received}")
8484

8585

8686
class BusyError(Exception):
@@ -98,7 +98,7 @@ class PduIgnoredForSourceReason(enum.IntEnum):
9898
ACK_MODE_PACKET_INVALID_MODE = 0
9999
# Received a Finished PDU, but source handler is currently not expecting one.
100100
NOT_WAITING_FOR_FINISHED_PDU = 1
101-
# Received a ACK PDU, but source handler is currently not expecting one.
101+
# Received an ACK PDU, but source handler is currently not expecting one.
102102
NOT_WAITING_FOR_ACK = 2
103103

104104

src/cfdppy/filestore.py

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
"""Contains the Filestore Interface and a Native Filestore implementation."""
2+
13
from __future__ import annotations # Python 3.9 compatibility for | syntax
24

35
import abc
46
import logging
57
import os
68
import platform
79
import shutil
8-
from typing import TYPE_CHECKING, BinaryIO, NoReturn
10+
from typing import TYPE_CHECKING, BinaryIO
911

1012
from crcmod.predefined import PredefinedCrc
1113
from spacepackets.cfdp.defs import NULL_CHECKSUM_U32, ChecksumType
@@ -23,45 +25,87 @@
2325

2426

2527
class VirtualFilestore(abc.ABC):
28+
"""Interface for a virtual filestore implementation."""
29+
2630
@abc.abstractmethod
2731
def read_data(self, file: Path, offset: int | None, read_len: int) -> bytes:
28-
"""This is not used as part of a filestore request, it is used to read a file, for example
29-
to send it"""
30-
raise NotImplementedError("Reading file not implemented in virtual filestore")
32+
"""Read data from a provided Path at a specific offset.
33+
34+
This is not used as part of a filestore request.
35+
It is used to read a file, for example to send it.
36+
37+
:param file: File to read
38+
:param offset: Offset to read from
39+
:param read_len: Number of bytes to read
40+
:return: The read data
41+
:raises PermissionError: In case the file is not readable
42+
:raises FileNotFoundError: In case the file does not exist.
43+
"""
3144

3245
@abc.abstractmethod
33-
def read_from_opened_file(self, bytes_io: BinaryIO, offset: int, read_len: int) -> NoReturn:
34-
raise NotImplementedError("Reading from opened file not implemented in virtual filestore")
46+
def read_from_opened_file(self, bytes_io: BinaryIO, offset: int, read_len: int) -> bytes:
47+
"""Read data from an already opened file object.
48+
49+
:param bytes_io: File object
50+
:param offset: Offset to read from
51+
:param read_len: Number of bytes to read
52+
:return: The read data
53+
"""
3554

3655
@abc.abstractmethod
3756
def is_directory(self, path: Path) -> bool:
38-
pass
57+
"""Check if a given path is a directory.
58+
59+
:param path: Path to check
60+
:return: True if the path is a directory
61+
"""
3962

4063
@abc.abstractmethod
4164
def filename_from_full_path(self, path: Path) -> str | None:
42-
pass
65+
"""Get the filename from a full path.
66+
67+
:param path: Full path
68+
:return: Filename
69+
"""
4370

4471
@abc.abstractmethod
4572
def file_exists(self, path: Path) -> bool:
46-
pass
73+
"""Check if a file exists at the given path.
74+
75+
:param path: Path to check
76+
:return: True if the file exists
77+
"""
4778

4879
@abc.abstractmethod
4980
def truncate_file(self, file: Path) -> None:
50-
pass
81+
"""Truncate a file to zero bytes.
82+
83+
:param file: File to truncate
84+
:raises FileNotFoundError: In case the file does not exist
85+
"""
5186

5287
@abc.abstractmethod
5388
def file_size(self, file: Path) -> int:
54-
pass
89+
"""Get the size of a file.
90+
91+
:param file: File to get the size of as number of bytes
92+
:return: Size of the file in bytes
93+
:raises FileNotFoundError: In case the file does not exist
94+
"""
5595

5696
@abc.abstractmethod
57-
def write_data(self, file: Path, data: bytes, offset: int | None) -> NoReturn:
97+
def write_data(self, file: Path, data: bytes, offset: int | None) -> None:
5898
"""This is not used as part of a filestore request, it is used to build up the received
5999
file.
60100
61-
:raises PermissionError:
62-
:raises FileNotFoundError:
101+
The file needs to exist before writing to it.
102+
103+
:param file: File to write to
104+
:param data: Data to write
105+
:param offset: Offset to write, may be None for no offset
106+
:raises PermissionError: In case the file is not writable
107+
:raises FileNotFoundError: In case the file does not exist
63108
"""
64-
raise NotImplementedError("Writing to data not implemented in virtual filestore")
65109

66110
@abc.abstractmethod
67111
def create_file(self, file: Path) -> FilestoreResponseStatusCode:

src/cfdppy/handler/dest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class TransactionStep(enum.Enum):
122122
the deferred lost segments detection procedure."""
123123
TRANSFER_COMPLETION = 7
124124
"""File transfer complete. Perform checksum verification and notice of completion. Please
125-
note that this does not necessarily mean that the file transfer was completed succesfully."""
125+
note that this does not necessarily mean that the file transfer was completed successfully."""
126126
SENDING_FINISHED_PDU = 8
127127
WAITING_FOR_FINISHED_ACK = 9
128128

@@ -498,7 +498,7 @@ def _reset_internal(self, clear_packet_queue: bool) -> None:
498498
self._pdus_to_be_sent.clear()
499499

500500
def reset(self) -> None:
501-
"""This function is public to allow completely resetting the handler, but it is explicitely
501+
"""This function is public to allow completely resetting the handler, but it is explicitly
502502
discouraged to do this. CFDP generally has mechanism to detect issues and errors on itself.
503503
"""
504504
self._reset_internal(False)
@@ -782,7 +782,7 @@ def _handle_waiting_for_finished_ack(self, packet_holder: PduHolder) -> None:
782782
):
783783
ack_pdu = packet_holder.to_ack_pdu()
784784
if ack_pdu.directive_code_of_acked_pdu != DirectiveType.FINISHED_PDU:
785-
_LOGGER.warn(
785+
_LOGGER.warning(
786786
f"received ACK PDU with invalid ACKed directive code "
787787
f" {ack_pdu.directive_code_of_acked_pdu}"
788788
)
@@ -801,7 +801,7 @@ def _handle_positive_ack_procedures(self) -> FsmResult | None:
801801
):
802802
self._declare_fault(ConditionCode.POSITIVE_ACK_LIMIT_REACHED)
803803
# This is a bit of a hack: We want the transfer completion and the corresponding
804-
# re-send of the Finished PDU to happen in the same FSM cycle. However, the call
804+
# Finished PDU to be re-sent in the same FSM cycle. However, the call
805805
# order in the FSM prevents this from happening, so we just call the state machine
806806
# again manually.
807807
if self._params.completion_disposition == CompletionDisposition.CANCELED:
@@ -999,7 +999,7 @@ def _handle_no_error_eof(self) -> bool:
999999
)
10001000
if self._params.fp.file_size_eof != self._params.fp.file_size:
10011001
# Can or should this ever happen for a No Error EOF? Treat this like a non-fatal
1002-
# error for now..
1002+
# error for now.
10031003
_LOGGER.warning("missmatch of EOF file size and Metadata File Size for success EOF")
10041004
if (
10051005
self.transmission_mode == TransmissionMode.UNACKNOWLEDGED
@@ -1163,6 +1163,6 @@ def _notice_of_suspension(self) -> None:
11631163
pass
11641164

11651165
def _abandon_transaction(self) -> None:
1166-
# I guess an abandoned transaction just stops whatever it is doing.. The implementation
1166+
# I guess an abandoned transaction just stops whatever it is doing. The implementation
11671167
# for this is quite easy.
11681168
self.reset()

src/cfdppy/handler/source.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class SourceHandler:
211211
source-to-destination file transfer. This class does not send the CFDP PDU packets directly
212212
to allow for greater flexibility. For example, a user might want to wrap the CFDP packet
213213
entities into a CCSDS space packet or into a special frame type. The handler can handle
214-
both unacknowledged (class 1) and acknowledged (class 2) file tranfers.
214+
both unacknowledged (class 1) and acknowledged (class 2) file transfers.
215215
216216
The following core functions are the primary interface:
217217
@@ -308,10 +308,10 @@ def num_packets_ready(self) -> int:
308308
def put_request(self, request: PutRequest) -> bool:
309309
"""This function is used to pass a put request to the source handler, which is
310310
also used to start a file copy operation. As such, this function models the Put.request
311-
CFDP primtiive.
311+
CFDP primitive.
312312
313313
Please note that the source handler can also process one put request at a time.
314-
The caller is responsible of creating a new source handler, one handler can only handle
314+
The caller is responsible for creating a new source handler, one handler can only handle
315315
one file copy request at a time.
316316
317317
@@ -328,7 +328,7 @@ def put_request(self, request: PutRequest) -> bool:
328328
Returns
329329
--------
330330
331-
False if the handler is busy. True if the handling of the request was successfull.
331+
False if the handler is busy. True if the handling of the request was finished successfully.
332332
"""
333333
if self.states.state != CfdpState.IDLE:
334334
_LOGGER.debug("CFDP source handler is busy, can't process put request")
@@ -483,7 +483,7 @@ def transaction_id(self) -> TransactionId | None:
483483
return self._params.transaction_id
484484

485485
def _reset_internal(self, clear_packet_queue: bool) -> None:
486-
"""This function is public to allow completely resetting the handler, but it is explicitely
486+
"""This function is public to allow completely resetting the handler, but it is explicitly
487487
discouraged to do this. CFDP generally has mechanism to detect issues and errors on itself.
488488
"""
489489
self.states.step = TransactionStep.IDLE
@@ -493,7 +493,7 @@ def _reset_internal(self, clear_packet_queue: bool) -> None:
493493
self._params.reset()
494494

495495
def reset(self) -> None:
496-
"""This function is public to allow completely resetting the handler, but it is explicitely
496+
"""This function is public to allow completely resetting the handler, but it is explicitly
497497
discouraged to do this. CFDP generally has mechanism to detect issues and errors on itself.
498498
"""
499499
self._reset_internal(True)
@@ -544,7 +544,7 @@ def _transaction_start(self) -> None:
544544
def _check_for_originating_id(self) -> TransactionId | None:
545545
"""This function only returns an originating ID for if not proxy put response is
546546
contained in the message to user list. This special logic is in place to avoid permanent
547-
loop which would occur when the user uses the orignating ID to register active proxy put
547+
loop which would occur when the user uses the originating ID to register active proxy put
548548
request, and this ID would also be generated for proxy put responses."""
549549
contains_proxy_put_response = False
550550
contains_originating_id = False
@@ -952,7 +952,7 @@ def _declare_fault(self, cond: ConditionCode) -> None:
952952
self.cfg.default_fault_handlers.report_fault(transaction_id, cond, progress)
953953

954954
def _notice_of_cancellation(self, condition_code: ConditionCode) -> bool:
955-
"""Returns whether the fault declaration handler can returns prematurely."""
955+
"""Returns whether the fault declaration handler can return prematurely."""
956956
# CFDP standard 4.11.2.2.3: Any fault declared in the course of transferring
957957
# the EOF (cancel) PDU must result in abandonment of the transaction.
958958
if (
@@ -980,7 +980,7 @@ def _notice_of_suspension(self) -> None:
980980
pass
981981

982982
def _abandon_transaction(self) -> None:
983-
# I guess an abandoned transaction just stops whatever it is doing.. The implementation
983+
# I guess an abandoned transaction just stops whatever it is doing. The implementation
984984
# for this is quite easy.
985985
self.reset()
986986

src/cfdppy/mib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class RemoteEntityCfg:
181181
**Notes on Positive Acknowledgment Procedures**
182182
183183
The ``positive_ack_timer_interval_seconds`` and ``positive_ack_timer_expiration_limit`` will
184-
be used for positive acknowledgement procedures as specified in CFDP chapter 4.7. The sending
184+
be used for positive acknowledgment procedures as specified in CFDP chapter 4.7. The sending
185185
entity will start the timer for any PDUs where an acknowledgment is required (e.g. EOF PDU).
186186
Once the expected ACK response has not been received for that interval, as counter will be
187187
incremented and the timer will be reset. Once the counter exceeds the

0 commit comments

Comments
 (0)