update python
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import usb.core
|
||||
import usb.util
|
||||
import sys
|
||||
import re
|
||||
|
||||
dymo_vid = 0x0922 # Dymo vendor ID
|
||||
dymo_tt_pid = 0x0018 # Dymo Twin Turbo Product ID
|
||||
@@ -48,3 +50,27 @@ def get_serial(dev):
|
||||
else:
|
||||
return rawserial.decode('utf-16-le')
|
||||
|
||||
def fix_serial(uri_line):
|
||||
if not uri_line.startswith("direct usb://DYMO/LabelWriter%20Twin%20Turbo?serial="):
|
||||
return uri_line
|
||||
|
||||
# Extract existing serial
|
||||
match = re.search(r'serial=([^\s]+)', uri_line)
|
||||
if not match:
|
||||
return uri_line
|
||||
|
||||
serial = match.group(1)
|
||||
|
||||
# If the serial is all question marks, replace it
|
||||
if set(serial) == {'?'}:
|
||||
# Generate fallback serial using USB bus/device number from URI line
|
||||
# CUPS output looks like:
|
||||
# direct usb://DYMO/... "DYMO LabelWriter Twin Turbo" usb://...
|
||||
# We'll add a stable dummy fallback here
|
||||
dummy_serial = "DYMOFIX-" + str(abs(hash(uri_line)) % 10000)
|
||||
uri_line = uri_line.replace(f"serial={serial}", f"serial={dummy_serial}")
|
||||
|
||||
return uri_line
|
||||
|
||||
for line in sys.stdin:
|
||||
sys.stdout.write(fix_serial(line))
|
||||
|
Reference in New Issue
Block a user