From e9749a9b8c64d06e29e439acf084e94b4afff5f9 Mon Sep 17 00:00:00 2001 From: asdf Date: Mon, 29 Jun 2020 16:13:41 +1000 Subject: [PATCH 1/2] Add exists checks before making any changes to the datastore --- config.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 561571c..00e0ca2 100644 --- a/config.py +++ b/config.py @@ -75,7 +75,8 @@ def init(): with defaults if any issues. """ - USER.datadir.mkdir(mode=0o755, exist_ok=True) + if not USER.datadir.exists(): + USER.datadir.mkdir(mode=0o755, exist_ok=True) if not is_readable(USER.datadir.stat().st_mode): print( @@ -84,7 +85,8 @@ def init(): ) USER.datadir.chmod(0o755) - USER.datafile.touch(mode=0o644, exist_ok=True) + if not USER.datafile.exists(): + USER.datafile.touch(mode=0o644, exist_ok=True) if not is_readable(USER.datafile.stat().st_mode): print( From ff0994bd419cda75c4f734e0320d31911f729e71 Mon Sep 17 00:00:00 2001 From: asdf Date: Thu, 2 Jul 2020 15:09:28 +1000 Subject: [PATCH 2/2] Category Details screen now fits terminal width, with aligned columns --- linkulator.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/linkulator.py b/linkulator.py index 8f3a5a4..ce64cee 100755 --- a/linkulator.py +++ b/linkulator.py @@ -4,7 +4,7 @@ ## If this script contains bugs, blame cmccabe. import getpass -import readline # pylint: disable=unused-import +import readline # pylint: disable=unused-import import signal import subprocess import sys @@ -47,8 +47,24 @@ def print_categories(): def print_category_details(view_cat): """produces category detail data, prints it to the console. returns dict containing an index of threads""" - header = "\n{}\n\n{:>4s} {:<15s}{:<12s} #RESP {:<13s}".format( - style_text(view_cat["name"].upper(), "bold"), "ID#", "DATE", "AUTHOR", "DESC" + columns, _ = get_terminal_size() + maxnamelen = len(max(link_data, key=lambda x: len(x[1]))[1]) + namelen = max(maxnamelen, 6) # minimum field width is 6 + desclen = ( + columns - 18 - namelen - 9 - 1 + ) # length of available space for the description field. + # The terminal width, minus the width of ID and Date fields and padding, + # minus the max name length, minus Resp field and padding width, minus the + # unread mark width + + header = "\n{}\n\n {:>3s} {:>10s} {:<{namelen}s} {:<5} {:= config.USER.lastlogin] ) + desc = textwrap.shorten(line[6], width=desclen, placeholder="...") newmarker = "*" if new_replies or line[2] >= config.USER.lastlogin else "" _dt = datetime.fromtimestamp(float(line[2])).strftime("%Y-%m-%d") - out += "{:4d} {:<15s}{:<12s} [{:3d}] {:s}{}\n".format( - link_count, _dt, line[1], len(replies), line[6], newmarker + out += " {:3d} {:>10s} {:<{namelen}s} [{:3d}] {:s}{}\n".format( + link_count, _dt, line[1], len(replies), desc, newmarker, namelen=namelen ) if len(out) > 0: