Skip to content

Commit 86aabcd

Browse files
committed
various cleanups an removed some rotten code
1 parent de59ce5 commit 86aabcd

11 files changed

Lines changed: 80 additions & 94 deletions

File tree

can/CAN.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
however all functionality has been refactored out. This API
88
is left intact for version 2.0 to 2.3 to aide with migration.
99
10-
WARNING:
11-
This module is deprecated an will get removed in version 2.4.
10+
WARNING:
11+
This module is deprecated an will get removed in version 2.4.
1212
Please use `import can` instead.
1313
"""
1414

can/__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# coding: utf-8
33

44
"""
5-
can is an object-orient Controller Area Network interface module.
5+
``can`` is an object-orient Controller Area Network (CAN) interface module.
66
"""
77

88
from __future__ import absolute_import
@@ -15,25 +15,27 @@
1515

1616
rc = dict()
1717

18-
1918
class CanError(IOError):
19+
"""
20+
Indicates an error with the CAN network.
21+
"""
2022
pass
2123

22-
from can.listener import Listener, BufferedReader, RedirectReader
24+
from .listener import Listener, BufferedReader, RedirectReader
2325

24-
from can.io import Logger, Printer, LogReader
25-
from can.io import ASCWriter, ASCReader
26-
from can.io import BLFReader, BLFWriter
27-
from can.io import CanutilsLogReader, CanutilsLogWriter
28-
from can.io import CSVWriter, CSVReader
29-
from can.io import SqliteWriter, SqliteReader
26+
from .io import Logger, Printer, LogReader, MessageSync
27+
from .io import ASCWriter, ASCReader
28+
from .io import BLFReader, BLFWriter
29+
from .io import CanutilsLogReader, CanutilsLogWriter
30+
from .io import CSVWriter, CSVReader
31+
from .io import SqliteWriter, SqliteReader
3032

31-
from can.util import set_logging_level
33+
from .util import set_logging_level
3234

33-
from can.message import Message
34-
from can.bus import BusABC
35-
from can.notifier import Notifier
36-
from can.interfaces import VALID_INTERFACES
35+
from .message import Message
36+
from .bus import BusABC
37+
from .notifier import Notifier
38+
from .interfaces import VALID_INTERFACES
3739
from . import interface
3840
from .interface import Bus, detect_available_configs
3941

can/broadcastmanager.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33

44
"""
55
Exposes several methods for transmitting cyclic messages.
6+
7+
The main entry point to these classes should be through
8+
:meth:`can.BusABC.send_periodic`.
69
"""
710

8-
import can
911
import abc
1012
import logging
1113
import sched
1214
import threading
1315
import time
1416

17+
import can
18+
1519
log = logging.getLogger('can.bcm')
16-
log.debug("Loading base broadcast manager functionality")
1720

1821

1922
class CyclicTask(object):
@@ -39,6 +42,7 @@ def __init__(self, message, period):
3942
"""
4043
self.message = message
4144
self.can_id = message.arbitration_id
45+
self.arbitration_id = message.arbitration_id
4246
self.period = period
4347
super(CyclicSendTaskABC, self).__init__()
4448

@@ -131,9 +135,10 @@ def _run(self):
131135
time.sleep(max(0.0, delay))
132136

133137

134-
def send_periodic(bus, message, period):
138+
def send_periodic(bus, message, period, *args, **kwargs):
135139
"""
136140
Send a message every `period` seconds on the given channel.
137-
138141
"""
139-
return can.interface.CyclicSendTask(bus, message, period)
142+
log.warn("The method `can.send_periodic` is deprecated and will "
143+
"be removed in version 2.3. Please use `can.Bus.send_periodic` instead.")
144+
return bus.send_periodic(message, period, *args, **kwargs)

can/interface.py

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,21 @@
1111

1212
import sys
1313
import importlib
14-
from pkg_resources import iter_entry_points
1514
import logging
1615

1716
import can
1817
from .bus import BusABC
1918
from .broadcastmanager import CyclicSendTaskABC, MultiRateCyclicSendTaskABC
2019
from .util import load_config
20+
from .interfaces import BACKENDS
2121

22+
# Required by "detect_available_configs" for argument interpretation
2223
if sys.version_info.major > 2:
2324
basestring = str
2425

25-
2626
log = logging.getLogger('can.interface')
2727
log_autodetect = log.getChild('detect_available_configs')
2828

29-
# interface_name => (module, classname)
30-
BACKENDS = {
31-
'kvaser': ('can.interfaces.kvaser', 'KvaserBus'),
32-
'socketcan_ctypes': ('can.interfaces.socketcan', 'SocketcanCtypes_Bus'),
33-
'socketcan_native': ('can.interfaces.socketcan', 'SocketcanNative_Bus'),
34-
'serial': ('can.interfaces.serial.serial_can','SerialBus'),
35-
'pcan': ('can.interfaces.pcan', 'PcanBus'),
36-
'usb2can': ('can.interfaces.usb2can', 'Usb2canBus'),
37-
'ixxat': ('can.interfaces.ixxat', 'IXXATBus'),
38-
'nican': ('can.interfaces.nican', 'NicanBus'),
39-
'iscan': ('can.interfaces.iscan', 'IscanBus'),
40-
'virtual': ('can.interfaces.virtual', 'VirtualBus'),
41-
'neovi': ('can.interfaces.ics_neovi', 'NeoViBus'),
42-
'vector': ('can.interfaces.vector', 'VectorBus'),
43-
'slcan': ('can.interfaces.slcan', 'slcanBus')
44-
}
45-
46-
BACKENDS.update({
47-
interface.name: (interface.module_name, interface.attrs[0])
48-
for interface in iter_entry_points('python_can.interface')
49-
})
50-
51-
5229
def _get_class_for_interface(interface):
5330
"""
5431
Returns the main bus class for the given interface.
@@ -189,8 +166,8 @@ def detect_available_configs(interfaces=None):
189166

190167
class CyclicSendTask(CyclicSendTaskABC):
191168

192-
@classmethod
193-
def __new__(cls, other, channel, *args, **kwargs):
169+
@staticmethod
170+
def __new__(cls, channel, *args, **kwargs):
194171

195172
config = load_config(config={'channel': channel})
196173

@@ -209,8 +186,8 @@ def __new__(cls, other, channel, *args, **kwargs):
209186

210187
class MultiRateCyclicSendTask(MultiRateCyclicSendTaskABC):
211188

212-
@classmethod
213-
def __new__(cls, other, channel, *args, **kwargs):
189+
@staticmethod
190+
def __new__(cls, channel, *args, **kwargs):
214191

215192
config = load_config(config={'channel': channel})
216193

can/interfaces/__init__.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@
77

88
from pkg_resources import iter_entry_points
99

10-
# TODO: isn't this a unnecessary information duplicate of `can/interface.py :: BACKENDS`?
11-
VALID_INTERFACES = set(['kvaser', 'serial', 'pcan', 'socketcan_native',
12-
'socketcan_ctypes', 'socketcan', 'usb2can', 'ixxat',
13-
'nican', 'iscan', 'vector', 'virtual', 'neovi',
14-
'slcan'])
10+
# interface_name => (module, classname)
11+
BACKENDS = {
12+
'kvaser': ('can.interfaces.kvaser', 'KvaserBus'),
13+
'socketcan_ctypes': ('can.interfaces.socketcan', 'SocketcanCtypes_Bus'),
14+
'socketcan_native': ('can.interfaces.socketcan', 'SocketcanNative_Bus'),
15+
'serial': ('can.interfaces.serial.serial_can','SerialBus'),
16+
'pcan': ('can.interfaces.pcan', 'PcanBus'),
17+
'usb2can': ('can.interfaces.usb2can', 'Usb2canBus'),
18+
'ixxat': ('can.interfaces.ixxat', 'IXXATBus'),
19+
'nican': ('can.interfaces.nican', 'NicanBus'),
20+
'iscan': ('can.interfaces.iscan', 'IscanBus'),
21+
'virtual': ('can.interfaces.virtual', 'VirtualBus'),
22+
'neovi': ('can.interfaces.ics_neovi', 'NeoViBus'),
23+
'vector': ('can.interfaces.vector', 'VectorBus'),
24+
'slcan': ('can.interfaces.slcan', 'slcanBus')
25+
}
1526

16-
VALID_INTERFACES.update(set([
17-
interface.name for interface in iter_entry_points('python_can.interface')
18-
]))
27+
BACKENDS.update({
28+
interface.name: (interface.module_name, interface.attrs[0])
29+
for interface in iter_entry_points('can.interface')
30+
})
31+
32+
VALID_INTERFACES = frozenset(list(BACKENDS.keys()) + ['socketcan'])

can/io/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
and Writers based off the file extension.
77
"""
88

9+
from __future__ import absolute_import
10+
11+
# Generic
912
from .logger import Logger
10-
from .player import LogReader
11-
from .log import CanutilsLogReader, CanutilsLogWriter
13+
from .player import LogReader, MessageSync
14+
15+
# Format specific
16+
from .canutils import CanutilsLogReader, CanutilsLogWriter
1217
from .asc import ASCWriter, ASCReader
1318
from .blf import BLFReader, BLFWriter
1419
from .csv import CSVWriter, CSVReader

can/io/log.py renamed to can/io/canutils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ class CanutilsLogReader(object):
2929
"""
3030
Iterator over CAN messages from a .log Logging File (candump -L).
3131
32-
.log-format looks like this:
33-
(0.0) vcan0 001#8d00100100820100
32+
.. note::
33+
.log-format looks for example like this:
34+
35+
``(0.0) vcan0 001#8d00100100820100``
3436
"""
3537

3638
def __init__(self, filename):

can/io/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class Logger(object):
3434
be created when instantiating this class.
3535
"""
3636

37-
@classmethod
38-
def __new__(cls, other, filename):
37+
@staticmethod
38+
def __new__(cls, filename):
3939
if not filename:
4040
return Printer()
4141
elif filename.endswith(".asc"):

can/io/player.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
in the recorded order an time intervals.
88
"""
99

10-
from __future__ import print_function
10+
from __future__ import absolute_import, print_function
1111

1212
import time
1313
import logging
@@ -37,13 +37,14 @@ class LogReader(object):
3737
>>> for m in LogReader(my_file):
3838
... print(m)
3939
40-
Note there are no time delays, if you want to reproduce
41-
the measured delays between messages look at the
42-
:class:`can.util.MessageSync` class.
40+
.. note::
41+
There are no time delays, if you want to reproduce
42+
the measured delays between messages look at the
43+
:class:`can.util.MessageSync` class.
4344
"""
4445

45-
@classmethod
46-
def __new__(cls, other, filename):
46+
@staticmethod
47+
def __new__(cls, filename):
4748
if not filename:
4849
raise TypeError("a filename must be given")
4950
elif filename.endswith(".asc"):

can/player.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
88
Similar to canplayer in the can-utils package.
99
"""
10+
1011
from __future__ import print_function
12+
1113
import argparse
1214
import datetime
1315

0 commit comments

Comments
 (0)