diff --git a/provisioning/print-esp32-label.py b/provisioning/print-esp32-label.py index 0f2f50416..5901f67c8 100755 --- a/provisioning/print-esp32-label.py +++ b/provisioning/print-esp32-label.py @@ -5,6 +5,7 @@ import sys import argparse import socket +import tinkerforge_util as tfutil # sudo apt install python3-tinkerforge-util BASE58 = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' @@ -18,63 +19,6 @@ COPIES_FORMAT = '^C{0}\r' -def get_tf_printer_host(task): - import re - import os - import sys - import socket - import tkinter.messagebox - - path = '~/tf_printer_host.txt' - x = re.compile(r'^([A-Za-z0-9_-]+)\s+([A-Za-z0-9_\.-]+)$') - host = None - - try: - with open(os.path.expanduser(path), 'r', encoding='utf-8') as f: - for line in f.readlines(): - line = line.strip() - - if len(line) == 0 or line.startswith('#'): - continue - - m = x.match(line) - - if m == None: - message = 'WARNING: Invalid line in {0}: {1}'.format(path, repr(line)) - - print(message) - tkinter.messagebox.showerror(title=path, message=message) - - continue - - other_task = m.group(1) - other_host = m.group(2) - - if other_task != task: - continue - - host = other_host - break - except FileNotFoundError: - pass - - if host == None: - message = 'ERROR: Printer host for task {0} not found in {1}'.format(task, path) - else: - try: - with socket.create_connection((host, 9100), timeout=5) as s: - pass - - return host - except Exception as e: - message = 'ERROR: Coould not connect to printer at {0} for task {1}: {2}'.format(host, task, e) - - print(message) - tkinter.messagebox.showerror(title=path, message=message) - - sys.exit(1) - - def print_esp32_label(ssid, passphrase, copies, stdout): # check SSID if re.match('^(esp32|warp|warp2|warp3|wem)-[{0}]{{3,6}}$'.format(BASE58), ssid) == None: @@ -128,7 +72,7 @@ def print_esp32_label(ssid, passphrase, copies, stdout): sys.stdout.buffer.write(data) sys.stdout.buffer.flush() else: - with socket.create_connection((get_tf_printer_host('esp32'), 9100)) as s: + with socket.create_connection((tfutil.get_tf_printer_host('esp32'), 9100)) as s: s.send(data)