From 53fa24cd96f87ae416101eea09284818929b9fba Mon Sep 17 00:00:00 2001 From: tke Date: Fri, 22 Mar 2024 14:28:54 +0100 Subject: [PATCH 1/4] Added Libarchive-Version tarsums --- tools/libarchivesum.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tools/libarchivesum.py diff --git a/tools/libarchivesum.py b/tools/libarchivesum.py new file mode 100644 index 0000000..b8bb348 --- /dev/null +++ b/tools/libarchivesum.py @@ -0,0 +1,34 @@ +import hashlib +import argparse +import sys + +try: + import libarchive +except ImportError: + sys.stderr.write('The libarchive package is missing. Please install libarchive-c first.\n\nsudo apt install python3-libarchive-c\n\n') + sys.exit(1) + +parser = argparse.ArgumentParser() +parser.add_argument('infile', nargs="+") +parser.add_argument('-c', '--hashtype', default="md5", choices=hashlib.algorithms_available) +args = parser.parse_args() + +def hash_files_in_archive(archive_path): + try: + with libarchive.file_reader(archive_path) as archive: + for entry in archive: + hasher = hashlib.new(args.hashtype) + for block in entry.get_blocks(): + hasher.update(block) + print(f'{hasher.hexdigest()} {entry.pathname}') + except AttributeError: + sys.stderr.write("It seems you're using a version of libarchive that doesn't have the 'file_reader' attribute. " + "This script requires 'python-libarchive-c'. Please ensure it's installed.\n") + sys.exit(2) + +# Example usage: +for infile in args.infile: + try: + hash_files_in_archive(infile) + except libarchive.exception.ArchiveError as e: + sys.stderr.write(f'Failed to open archive file {infile}: {e}\n') From 34008877129b9d14e3c8e8658e796590e4533b2a Mon Sep 17 00:00:00 2001 From: tke Date: Mon, 25 Mar 2024 11:14:06 +0100 Subject: [PATCH 2/4] Update libarchive error handling; improve error message formatting --- tools/libarchivesum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/libarchivesum.py b/tools/libarchivesum.py index b8bb348..fb1796a 100644 --- a/tools/libarchivesum.py +++ b/tools/libarchivesum.py @@ -31,4 +31,4 @@ for infile in args.infile: try: hash_files_in_archive(infile) except libarchive.exception.ArchiveError as e: - sys.stderr.write(f'Failed to open archive file {infile}: {e}\n') + print(f'Failed to open archive file {infile}: {e}\n', file=sys.stderr) From d3eebe328f9a4afe88304239a6ae8488b4989128 Mon Sep 17 00:00:00 2001 From: tke Date: Mon, 6 May 2024 07:47:47 +0200 Subject: [PATCH 3/4] improve errorhandling in get_ntp --- tools/get_ntp.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/get_ntp.py b/tools/get_ntp.py index a362400..df37ace 100755 --- a/tools/get_ntp.py +++ b/tools/get_ntp.py @@ -6,5 +6,8 @@ c = ntplib.NTPClient() try: response = c.request(sys.argv[1]) print(ctime(response.tx_time)) -except: - print("ERROR") +except ntplib.NTPException as e: + print(f"ERROR during NTP request: {e}") + print("Usage: ntp-client.py ") + sys.exit(-1) + From 6f2402a963abbd549f500da24bdec54049b931c3 Mon Sep 17 00:00:00 2001 From: tke Date: Wed, 8 May 2024 16:28:21 +0200 Subject: [PATCH 4/4] Fixed issue with tke-hide-col plugin --- config/visidataplugins/hidecol.py | 38 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/config/visidataplugins/hidecol.py b/config/visidataplugins/hidecol.py index 83d9fd0..88a3712 100644 --- a/config/visidataplugins/hidecol.py +++ b/config/visidataplugins/hidecol.py @@ -1,5 +1,5 @@ __version__ = "0.1.0" -__author__ = "Your Name " +__author__ = "Tabledevil " from visidata import Sheet, BaseSheet, vd @@ -10,26 +10,30 @@ def hide_empty_and_superfluous_cols(sheet): Given a sheet, hides columns that are empty or superfluous (contain the same value in every row). """ - # Create a dictionary to keep track of which columns to hide - cols_to_hide = {} - + # Count how many columns were hidden + counter = 0 # Check each column for being empty or superfluous for col in sheet.visibleCols: - # Check if the column is empty (all cells are empty or None) - if all([col.getValue(row) in (None, "") for row in sheet.rows]): - cols_to_hide[col] = True - continue + # If the column is not hidden + if col.width and col.width > 0: + # Check if the column is empty (all cells are empty or None) + if all([col.getValue(row) in (None, "", "null") for row in sheet.rows]): + # Hide the column + col.width = 0 + counter += 1 + # Skip the next check for same values since all cells are empty or None + continue - # Check if the column is superfluous (contains the same value in every row) - values = set([col.getValue(row) for row in sheet.rows if col.getValue(row) not in (None, "", "null")]) - if len(values) == 1: - cols_to_hide[col] = True + # Check if the column is superfluous (contains the same value in every row) + # collect all values in the column as strings + values = set([f'{col.getValue(row)}' for row in sheet.rows if col.getValue(row) not in (None, "", "null")]) + # If there is only one value in the column + if len(values) == 1: + # Hide the column + col.width = 0 + counter += 1 - # Hide the columns that were flagged - if cols_to_hide: - for col in cols_to_hide: - col.width=0 - vd.status(f"Hid {len(cols_to_hide)} empty/superfluous columns.") + vd.status(f"Hid {counter} empty/superfluous columns.") else: vd.status("No empty/superfluous columns to hide.")