Skip to content

Commit c9eaf55

Browse files
authored
Merge pull request #98 from jacomago/ruff
Add the ruff linter and formatter to recceiver
2 parents 1ced068 + 1228339 commit c9eaf55

20 files changed

+852
-748
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
repos:
2-
# - repo: https://github.com/psf/black
3-
# rev: 22.8.0
4-
# hooks:
5-
# - id: black
6-
# - repo: https://github.com/charliermarsh/ruff-pre-commit
7-
# rev: v0.0.238
8-
# hooks:
9-
# - id: ruff
102
- repo: https://github.com/pre-commit/pre-commit-hooks
113
rev: v4.4.0
124
hooks:
135
- id: end-of-file-fixer
146
- id: trailing-whitespace
7+
- repo: https://github.com/astral-sh/ruff-pre-commit
8+
# Ruff version.
9+
rev: v0.9.0
10+
hooks:
11+
# Run the linter.
12+
- id: ruff
13+
args: [ --fix ]
14+
# Run the formatter.
15+
- id: ruff-format
1516
#- repo: https://github.com/pre-commit/mirrors-clang-format
1617
# rev: v15.0.7
1718
# hooks:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ RecSync
22
=======
33

44
The record synchronizer project includes two parts.
5-
A client (RecCaster) which runing as part of an EPICS
6-
IOC, and a server (RecCeiver) which is a stand alone
5+
A client ([RecCaster](./client/README.md)) which runing as part of an EPICS
6+
IOC, and a server ([RecCeiver](./server/README.md)) which is a stand alone
77
daemon. Together they work to ensure the the server(s)
88
have a complete list of all records currently provided
99
by the client IOCs.

client/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Reccaster

server/README

Lines changed: 0 additions & 28 deletions
This file was deleted.

server/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Recceiver
2+
3+
Application for talking between IOCs (via [reccaster](../client)) and ChannelFinder (via [pyCFClient](https://github.com/ChannelFinder/pyCFClient)).
4+
5+
Written using [twistd](https://twisted.org/).
6+
7+
## Formatting and Linting
8+
9+
Recceiver uses [ruff](https://docs.astral.sh/ruff/) for formatting and linting. See website for installation instructions.
10+
11+
12+
```bash
13+
ruff check
14+
```
15+
16+
```bash
17+
ruff check --fix
18+
```
19+
20+
```bash
21+
ruff format
22+
```
23+
24+
25+
## Server testing
26+
27+
Setup
28+
29+
```bash
30+
sqlite3 test.db -init recceiver.sqlite3 .exit
31+
```
32+
33+
Run (for twistd <= 16.0.3)
34+
35+
```bash
36+
twistd -n recceiver -f demo.conf
37+
```
38+
39+
or (see below for discussion)
40+
41+
```bash
42+
twistd -r poll -n recceiver -f demo.conf
43+
```
44+
45+
46+
Run (for twistd >= 16.0.4)
47+
48+
```bash
49+
PYTHONPATH=$PWD twistd -r poll -n recceiver -f demo.conf
50+
```
51+
52+
At some point 'twistd' stopped implicitly searching the working directory.
53+
54+
May need to uncomment `addrlist = 127.255.255.255:5049` in demo.conf
55+
when doing local testing on a computer w/ a firewall.
56+
57+
Twisted 14.0.2 seems to have a problem with the epoll() reactor
58+
which raises 'IOError: [Errno 2] No such file or directory'
59+
during startup. Try with the poll() reactor.
60+
61+
```bash
62+
twistd -r poll -n recceiver -f demo.conf
63+
```

server/recceiver/announce.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,69 @@
44
import struct
55

66
from twisted.internet import protocol
7+
from twisted.internet.error import MessageLengthError
78
import logging
89

910
_log = logging.getLogger(__name__)
1011

1112

12-
_Ann = struct.Struct('>HH4sHHI')
13+
_Ann = struct.Struct(">HH4sHHI")
14+
15+
__all__ = ["Announcer"]
1316

14-
__all__ = ['Announcer']
1517

1618
class Announcer(protocol.DatagramProtocol):
17-
def __init__(self, tcpport, key=0,
18-
tcpaddr='\xff\xff\xff\xff',
19-
udpaddrs=[('<broadcast>',5049)],
20-
period=15.0):
19+
def __init__(
20+
self,
21+
tcpport,
22+
key=0,
23+
tcpaddr="\xff\xff\xff\xff",
24+
udpaddrs=[("<broadcast>", 5049)],
25+
period=15.0,
26+
):
2127
from twisted.internet import reactor
2228

2329
self.reactor = reactor
2430

2531
if sys.version_info[0] < 3:
2632
self.msg = _Ann.pack(0x5243, 0, tcpaddr, tcpport, 0, key)
2733
else:
28-
self.msg = _Ann.pack(0x5243, 0, tcpaddr.encode('latin-1'), tcpport, 0, key)
34+
self.msg = _Ann.pack(0x5243, 0, tcpaddr.encode("latin-1"), tcpport, 0, key)
2935

3036
self.delay = period
3137
self.udps = udpaddrs
3238
self.udpErr = set()
3339
self.D = None
34-
if len(self.udps)==0:
35-
raise RuntimeError('Announce list is empty at start time...')
40+
if len(self.udps) == 0:
41+
raise RuntimeError("Announce list is empty at start time...")
3642

3743
def startProtocol(self):
38-
_log.info('Setup Announcer')
44+
_log.info("Setup Announcer")
3945
self.D = self.reactor.callLater(0, self.sendOne)
4046
# we won't process any receieved traffic, so no reason to wake
4147
# up for it...
4248
self.transport.pauseProducing()
4349

4450
def stopProtocol(self):
45-
_log.info('Stop Announcer')
51+
_log.info("Stop Announcer")
4652
self.D.cancel()
4753
del self.D
4854

4955
def datagramReceived(self, src):
50-
pass # ignore
56+
pass # ignore
5157

5258
def sendOne(self):
5359
self.D = self.reactor.callLater(self.delay, self.sendOne)
5460
for A in self.udps:
5561
try:
56-
_log.debug('announce to {s}'.format(s=A))
62+
_log.debug("announce to {s}".format(s=A))
5763
self.transport.write(self.msg, A)
5864
try:
5965
self.udpErr.remove(A)
60-
_log.warning('announce OK to {s}'.format(s=A))
66+
_log.warning("announce OK to {s}".format(s=A))
6167
except KeyError:
6268
pass
63-
except:
69+
except MessageLengthError:
6470
if A not in self.udpErr:
6571
self.udpErr.add(A)
66-
_log.exception('announce Error to {s}'.format(s=A))
72+
_log.exception("announce Error to {s}".format(s=A))

0 commit comments

Comments
 (0)