blob: e46974a9bc9e7e63b0b6d54e61ab8525ba9f6508 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/usr/bin/env python3
class Serial:
modulus = 2 ** 32
def __init__(self, val):
self._val = int(val)
if self._val < 0 or self._val >= self.modulus:
raise ValueError
def __add__(self, val):
val = int(val)
if val < 0 or val > (self.modulus - 1) >> 1:
raise ValueError
return type(self)((self._val + val) & (self.modulus - 1))
def __le__(self, other):
return (self.modulus - int(self) + int(other)) & (self.modulus >> 1) == 0
def __ge__(self, other):
return (self.modulus + int(self) - int(other)) & (self.modulus >> 1) == 0
def __eq__(self, other):
return int(self) == int(other)
def __ne__(self, other):
return int(self) != int(other)
def __lt__(self, other):
return self != other and self <= other
def __gt__(self, other):
return self != other and self >= other
def __int__(self):
return self._val
def __str__(self):
return f"{int(self):{len(str(self.modulus))}d}"
def find_intermediate(start, finish):
while not (start < finish): # sic: serial numbers are not (quite) integers
start += ((Serial.modulus >> 1) - 1)
yield start
def main():
from argparse import ArgumentParser
ap = ArgumentParser()
ap.add_argument("start", type = Serial)
ap.add_argument("finish", type = Serial)
args = ap.parse_args()
print(f"Start at {args.start!s}")
if args.start < args.finish:
print("No step needed")
else:
for wrap in find_intermediate(args.start, args.finish):
print(f"Step via {wrap!s}")
print(f"End at {args.finish!s}")
if __name__ == "__main__":
main()
|