From f14cd91b8ef56d51914dfe9c4fc57fba1c105759 Mon Sep 17 00:00:00 2001 From: Ircama Date: Wed, 31 Jul 2024 07:35:20 +0200 Subject: [PATCH] Fix waste counter conversion for some printers --- README.md | 4 ++-- parse_devices.py | 20 +++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6ad8019..f7c2c28 100644 --- a/README.md +++ b/README.md @@ -218,8 +218,8 @@ The `-m` option is optional and is used to filter the printer model in scope. If Program usage: ``` -parse_devices.py [-h] [-m PRINTER_MODEL] [-l LINE_LENGTH] [-i] [-d] [-t] [-v] [-f] [-e] [-c CONFIG_FILE] [-s DEFAULT_MODEL] -a HOSTNAME [-p PICKLE_FILE] [-I] - [-N] [-A] [-S] +parse_devices.py [-h] [-m PRINTER_MODEL] [-l LINE_LENGTH] [-i] [-d] [-t] [-v] [-f] [-e] [-c CONFIG_FILE] + [-s DEFAULT_MODEL] [-a HOSTNAME] [-p PICKLE_FILE] [-I] [-N] [-A] [-S] optional arguments: -h, --help show this help message and exit diff --git a/parse_devices.py b/parse_devices.py index 586e08a..7b724e3 100644 --- a/parse_devices.py +++ b/parse_devices.py @@ -170,20 +170,19 @@ def generate_config(config, traverse, add_fatal_errors, full, printer_model): for ncounter in counter: if ncounter.tag == "entry": if "oids" in waste: - waste["oids"] += text_to_bytes( - ncounter.text - ) + waste["oids"] += text_to_bytes(ncounter.text) else: - waste["oids"] = text_to_bytes( - ncounter.text - ) + waste["oids"] = text_to_bytes(ncounter.text) if ncounter.tag == "max": - waste["divider"] = ( - int(ncounter.text) / 100 - ) + waste["divider"] = int(ncounter.text) / 100 if full: for filter in ncounter: waste["filter"] = filter.text + if counter.text: + if "oids" in waste: + waste["oids"] += text_to_bytes(counter.text) + else: + waste["oids"] = text_to_bytes(counter.text) chars[waste_string[count]] = waste count += 1 if item.tag == "serial": @@ -389,8 +388,7 @@ if __name__ == "__main__": '--address', dest='hostname', action="store", - help='Default printer host name or IP address. (Example: -a 192.168.1.87)', - required=True + help='Default printer host name or IP address. (Example: -a 192.168.1.87)' ) parser.add_argument( '-p',