Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions can/io/asc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def __init__(
file: Union[StringPathLike, TextIO],
base: str = "hex",
relative_timestamp: bool = True,
*args: Any,
**kwargs: Any,
) -> None:
"""
:param file: a path-like object or as file-like object to read from
Expand Down Expand Up @@ -352,6 +354,7 @@ def __init__(
self,
file: Union[StringPathLike, TextIO],
channel: int = 1,
*args: Any,
**kwargs: Any,
) -> None:
"""
Expand Down
9 changes: 7 additions & 2 deletions can/io/blf.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ class BLFReader(MessageReader):

file: BinaryIO

def __init__(self, file: Union[StringPathLike, BinaryIO]) -> None:
def __init__(
self,
file: Union[StringPathLike, BinaryIO],
*args: Any,
**kwargs: Any,
) -> None:
"""
:param file: a path-like object or as file-like object to read from
If this is a file-like object, is has to opened in binary
Expand Down Expand Up @@ -371,7 +376,7 @@ def __init__(
channel: int = 1,
compression_level: int = -1,
*args: Any,
**kwargs: Any
**kwargs: Any,
) -> None:
"""
:param file: a path-like object or as file-like object to write to
Expand Down
13 changes: 10 additions & 3 deletions can/io/canutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"""

import logging
from typing import Generator, TextIO, Union
from typing import Generator, TextIO, Union, Any

from can.message import Message
from .generic import FileIOMessageWriter, MessageReader
from ..typechecking import AcceptedIOType, StringPathLike
from ..typechecking import StringPathLike

log = logging.getLogger("can.io.canutils")

Expand All @@ -34,7 +34,12 @@ class CanutilsLogReader(MessageReader):

file: TextIO

def __init__(self, file: Union[StringPathLike, TextIO]) -> None:
def __init__(
self,
file: Union[StringPathLike, TextIO],
*args: Any,
**kwargs: Any,
) -> None:
"""
:param file: a path-like object or as file-like object to read from
If this is a file-like object, is has to opened in text
Expand Down Expand Up @@ -132,6 +137,8 @@ def __init__(
file: Union[StringPathLike, TextIO],
channel: str = "vcan0",
append: bool = False,
*args: Any,
**kwargs: Any,
):
"""
:param file: a path-like object or as file-like object to write to
Expand Down
15 changes: 12 additions & 3 deletions can/io/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""

from base64 import b64encode, b64decode
from typing import TextIO, Generator, Union
from typing import TextIO, Generator, Union, Any

from can.message import Message
from .generic import FileIOMessageWriter, MessageReader
Expand All @@ -28,7 +28,12 @@ class CSVReader(MessageReader):

file: TextIO

def __init__(self, file: Union[StringPathLike, TextIO]) -> None:
def __init__(
self,
file: Union[StringPathLike, TextIO],
*args: Any,
**kwargs: Any,
) -> None:
"""
:param file: a path-like object or as file-like object to read from
If this is a file-like object, is has to opened in text
Expand Down Expand Up @@ -87,7 +92,11 @@ class CSVWriter(FileIOMessageWriter):
file: TextIO

def __init__(
self, file: Union[StringPathLike, TextIO], append: bool = False
self,
file: Union[StringPathLike, TextIO],
append: bool = False,
*args: Any,
**kwargs: Any,
) -> None:
"""
:param file: a path-like object or a file-like object to write to.
Expand Down
15 changes: 13 additions & 2 deletions can/io/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Iterable,
Type,
ContextManager,
Any,
)
from typing_extensions import Literal
from types import TracebackType
Expand All @@ -28,7 +29,11 @@ class BaseIOHandler(ContextManager, metaclass=ABCMeta):
file: Optional[can.typechecking.FileLike]

def __init__(
self, file: Optional[can.typechecking.AcceptedIOType], mode: str = "rt"
self,
file: Optional[can.typechecking.AcceptedIOType],
mode: str = "rt",
*args: Any,
**kwargs: Any
) -> None:
"""
:param file: a path-like object to open a file, a file-like object
Expand Down Expand Up @@ -82,7 +87,13 @@ class FileIOMessageWriter(MessageWriter, metaclass=ABCMeta):

file: can.typechecking.FileLike

def __init__(self, file: can.typechecking.AcceptedIOType, mode: str = "wt") -> None:
def __init__(
self,
file: can.typechecking.AcceptedIOType,
mode: str = "wt",
*args: Any,
**kwargs: Any
) -> None:
# Not possible with the type signature, but be verbose for user-friendliness
if file is None:
raise ValueError("The given file cannot be None")
Expand Down
2 changes: 1 addition & 1 deletion can/io/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ class SizedRotatingLogger(BaseRotatingLogger):
def __init__(
self,
base_filename: StringPathLike,
*args: Any,
max_bytes: int = 0,
*args: Any,
**kwargs: Any,
) -> None:
"""
Expand Down
8 changes: 6 additions & 2 deletions can/io/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging

from typing import Optional, TextIO, Union
from typing import Optional, TextIO, Union, Any

from ..message import Message
from .generic import MessageWriter
Expand All @@ -26,7 +26,11 @@ class Printer(MessageWriter):
file: Optional[TextIO]

def __init__(
self, file: Optional[Union[StringPathLike, TextIO]] = None, append: bool = False
self,
file: Optional[Union[StringPathLike, TextIO]] = None,
append: bool = False,
*args: Any,
**kwargs: Any
) -> None:
"""
:param file: An optional path-like object or a file-like object to "print"
Expand Down
14 changes: 12 additions & 2 deletions can/io/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ class SqliteReader(MessageReader):
.. note:: The database schema is given in the documentation of the loggers.
"""

def __init__(self, file: StringPathLike, table_name: str = "messages") -> None:
def __init__(
self,
file: StringPathLike,
table_name: str = "messages",
*args: Any,
**kwargs: Any,
) -> None:
"""
:param file: a `str` path like object that points
to the database file to use
Expand Down Expand Up @@ -129,7 +135,11 @@ class SqliteWriter(MessageWriter, BufferedReader):
"""Maximum number of messages to buffer before writing to the database"""

def __init__(
self, file: StringPathLike, table_name: str = "messages", **kwargs: Any
self,
file: StringPathLike,
table_name: str = "messages",
*args: Any,
**kwargs: Any,
) -> None:
"""
:param file: a `str` or path like object that points
Expand Down
25 changes: 17 additions & 8 deletions can/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from typing import Any, Dict, List, Union, Sequence, Tuple

import can
from can.io import BaseRotatingLogger
from can.io.generic import MessageWriter
from . import Bus, BusState, Logger, SizedRotatingLogger
from .typechecking import CanFilter, CanFilters

Expand Down Expand Up @@ -61,10 +63,10 @@ def _create_base_argument_parser(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"extra_args",
nargs=argparse.REMAINDER,
help=r"The remaining arguments will be used for the interface "
r"initialisation. For example, `-i vector -c 1 --app-name="
r"MyCanApp` is the equivalent to opening the bus with `Bus("
r"'vector', channel=1, app_name='MyCanApp')",
help="The remaining arguments will be used for the interface and "
"logger/player initialisation. "
"For example, `-i vector -c 1 --app-name=MyCanApp` is the equivalent "
"to opening the bus with `Bus('vector', channel=1, app_name='MyCanApp')",
)


Expand Down Expand Up @@ -224,7 +226,7 @@ def main() -> None:
raise SystemExit(errno.EINVAL)

results, unknown_args = parser.parse_known_args()
additional_config = _parse_additional_config(unknown_args)
additional_config = _parse_additional_config([*results.extra_args, *unknown_args])
bus = _create_bus(results, can_filters=_parse_filters(results), **additional_config)

if results.active:
Expand All @@ -235,13 +237,20 @@ def main() -> None:
print(f"Connected to {bus.__class__.__name__}: {bus.channel_info}")
print(f"Can Logger (Started on {datetime.now()})")

options = {"append": results.append}
logger: Union[MessageWriter, BaseRotatingLogger]
if results.file_size:
logger = SizedRotatingLogger(
base_filename=results.log_file, max_bytes=results.file_size, **options
base_filename=results.log_file,
max_bytes=results.file_size,
append=results.append,
**additional_config,
)
else:
logger = Logger(filename=results.log_file, **options) # type: ignore
logger = Logger(
filename=results.log_file,
append=results.append,
**additional_config,
)

try:
while True:
Expand Down
4 changes: 2 additions & 2 deletions can/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ def main() -> None:
raise SystemExit(errno.EINVAL)

results, unknown_args = parser.parse_known_args()
additional_config = _parse_additional_config(unknown_args)
additional_config = _parse_additional_config([*results.extra_args, *unknown_args])

verbosity = results.verbosity

error_frames = results.error_frames

with _create_bus(results, **additional_config) as bus:
with LogReader(results.infile) as reader:
with LogReader(results.infile, **additional_config) as reader:

in_sync = MessageSync(
cast(Iterable[Message], reader),
Expand Down
4 changes: 3 additions & 1 deletion can/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,9 @@ def parse_args(args):
else:
data_structs[key] = struct.Struct(fmt)

additional_config = _parse_additional_config(unknown_args)
additional_config = _parse_additional_config(
[*parsed_args.extra_args, *unknown_args]
)
return parsed_args, can_filters, data_structs, additional_config


Expand Down