Skip to content

Commit 425cf57

Browse files
authored
Remove unused variables (#30)
1 parent 2273d6d commit 425cf57

File tree

5 files changed

+35
-54
lines changed

5 files changed

+35
-54
lines changed

README.md

+26-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# icepap-ipassign
22

3-
Remotely configure IcePAP network settings.
3+
Remotely configure IcePAP network settings.
4+
[![Total alerts](https://img.shields.io/lgtm/alerts/g/cydanil/icepap-ipassign.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/cydanil/icepap-ipassign/alerts/) [![Python 3.9 application](https://github.com/cydanil/icepap-ipassign/actions/workflows/python39.yml/badge.svg)](https://github.com/cydanil/icepap-ipassign/actions/workflows/python39.yml)
45

56
IPAssign is a tool developed within ESRF's DEG (Detector and Electronics Group).
67
Its aim is to provide an easy way to set-up network settings over UDP multicast,
@@ -46,7 +47,6 @@ ipassing sending a new configuration to a device.
4647
Acknowledgements are sent by a device upon applying a new configuration.
4748
These are not sent if the device was requested to reboot.
4849

49-
5050
A typical exchange of information has the following format:
5151

5252
[ipassign] who's there? discovery packet
@@ -59,11 +59,9 @@ A typical exchange of information has the following format:
5959

6060
For demonstration purposes, a simple listener is available in `utils/listener.py` and can be invoked so:
6161

62-
```bash
63-
$ ipassign-listener
62+
$ ipassign-listener
6463

65-
Waiting for messages...
66-
```
64+
Waiting for messages...
6765

6866
Messages seen in the multicast group will then be displayed in human readable format.
6967

@@ -101,13 +99,12 @@ An IPAssign packet has the following structure:
10199

102100
`target count` is called so, to maintain consistency with other legacy code.
103101
It was originally envisioned that several devices could be targeted by a single
104-
message, hence its uint16 format.
102+
message, hence its uint16 format.
105103
In practice, however, it is effectively used as a boolean: it should be
106-
understood as `is_not_broadcasting`.
104+
understood as `is_not_broadcasting`.
107105

108106
---
109107

110-
111108
### Discovery Messages
112109

113110
Here is the anatomy of a discovery message:
@@ -210,6 +207,7 @@ An acknowledgment payload has the following structure:
210207
- `[error code]` is a status code of having applied the received settings.
211208

212209
Here is an acknowledgement payload:
210+
213211
```python
214212
from ipassign import acknowledgements, Acknowledgement
215213

@@ -244,26 +242,18 @@ For development, a mock IcePAP server can be found in `utils/mock_icepap`.
244242
This mock server behaves like real hardware, and will send the appropriate
245243
replies:
246244

247-
```bash
248-
$ python ipa_utils/mock_icepap
249-
Working with e3:cd:77:a0:18:30 and dvepklrlyq, no ack: False
250-
```
245+
$ python ipa_utils/mock_icepap
246+
Working with e3:cd:77:a0:18:30 and dvepklrlyq, no ack: False
251247

252248
The script also accepts a mac address as argument:
253249

254-
```bash
255-
$ python ipa_utils/mock_icepap 00:0B:AD:C0:FF:EE
256-
Working with 00:0b:ad:c0:ff:ee and kqifwchhiz, no ack: False
257-
```
250+
$ python ipa_utils/mock_icepap 00:0B:AD:C0:FF:EE
251+
Working with 00:0b:ad:c0:ff:ee and kqifwchhiz, no ack: False
258252

259253
It's also possible to make the script not send acknowledgements:
260254

261-
```bash
262-
$ python ipa_utils/mock_icepap --nack
263-
Working with 53:2e:d2:f9:7b:af and kvdkkleuqc, no ack: True
264-
```
265-
266-
255+
$ python ipa_utils/mock_icepap --nack
256+
Working with 53:2e:d2:f9:7b:af and kvdkkleuqc, no ack: True
267257

268258
## Embedded IcePAP Considerations
269259

@@ -277,21 +267,19 @@ the `listener` crash.
277267
To restart it, telnet as `root` in the IcePAP device, and execute
278268
`/usr/sbin/icepap_startup_local restart`:
279269

280-
```bash
281-
$ telnet icepap
282-
icepap login: root
283-
Password:
284-
285-
root@icepap > /usr/sbin/icepap_startup_local restart
286-
Stopping ipassign listener......done
287-
Stopping icepap communication...done
288-
Removing icepap driver..........done
289-
Removing blisspipe driver.......done
290-
Loading icepap driver..........done
291-
Loading blisspipe driver.......done
292-
Starting icepap communication...done
293-
Starting ipassign listener......done
294-
```
270+
$ telnet icepap
271+
icepap login: root
272+
Password:
273+
274+
root@icepap > /usr/sbin/icepap_startup_local restart
275+
Stopping ipassign listener......done
276+
Stopping icepap communication...done
277+
Removing icepap driver..........done
278+
Removing blisspipe driver.......done
279+
Loading icepap driver..........done
280+
Loading blisspipe driver.......done
281+
Starting icepap communication...done
282+
Starting ipassign listener......done
295283

296284
The device will then appear in `ipassign` upon doing a `Refresh`.
297285

ipa_gui/configurations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def validator(self):
123123
if ok:
124124
color = GREEN
125125

126-
if color is GREEN:
126+
if color == GREEN:
127127
self.pbApply.setEnabled(True)
128128
sender.setStyleSheet('QLineEdit { background-color: %s }' % color)
129129

ipa_gui/networking.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import socket
2-
import struct
32

43
import netifaces
54

@@ -41,8 +40,6 @@ def __init__(self):
4140

4241
# Tell the operating system to add the socket to the multicast group
4342
# on all interfaces.
44-
group = socket.inet_aton(MULTICAST_ADDR)
45-
mreq = struct.pack('4sL', group, socket.INADDR_ANY)
4643
mreq = socket.inet_aton(MULTICAST_ADDR) + socket.inet_aton('0.0.0.0')
4744
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
4845

ipa_utils/listener.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ def main():
2020
# Bind to the server address
2121
sock.bind(('', MULTICAST_PORT))
2222

23-
try:
24-
while True:
25-
print('\nWaiting for messages...')
26-
data, address = sock.recvfrom(MAX_PACKET_LENGTH)
27-
print(Message.from_bytes(data))
28-
except KeyboardInterrupt:
29-
pass
30-
finally:
31-
sock.close()
23+
with sock:
24+
try:
25+
while True:
26+
print('\nWaiting for messages...')
27+
data, address = sock.recvfrom(MAX_PACKET_LENGTH)
28+
print(Message.from_bytes(data))
29+
except KeyboardInterrupt:
30+
pass
3231

3332

3433
if __name__ == '__main__':

ipa_utils/mock_icepap.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import random
22
import socket
33
import string
4-
import struct
54
import sys
65

76
from ipassign import (acknowledgements, Acknowledgement,
@@ -19,8 +18,6 @@
1918

2019
# Tell the operating system to add the socket to
2120
# the multicast group on all interfaces.
22-
group = socket.inet_aton(MULTICAST_ADDR)
23-
mreq = struct.pack('4sL', group, socket.INADDR_ANY)
2421
mreq = socket.inet_aton(MULTICAST_ADDR) + socket.inet_aton('0.0.0.0')
2522
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
2623

0 commit comments

Comments
 (0)