From bafe7f5a0997864b13f3b8b126521c91ebe27271 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 24 Nov 2024 21:28:21 +0000 Subject: [PATCH] improve helptext exporters --- scripts/help2html.py | 39 ++++++++++++++++++++++++++++++++++++++- scripts/help2txt.sh | 4 ++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/scripts/help2html.py b/scripts/help2html.py index 7bd3318a..876b406f 100755 --- a/scripts/help2html.py +++ b/scripts/help2html.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import re +import socket import subprocess as sp @@ -25,13 +26,20 @@ def readclip(): return sp.check_output(cmd.split()).decode("utf-8") except: pass + raise Exception("need one of these: xsel xclip pbpaste") def cnv(src): + hostname = str(socket.gethostname()).split(".")[0] + yield '' skip_sfx = False in_sfx = 0 in_salt = 0 + in_name = 0 + in_cores = 0 + in_hash_mt = False + in_th_ram_max = 0 while True: ln = next(src) @@ -43,6 +51,7 @@ def cnv(src): for ln in src: ln = ln.rstrip() + t = ln if re.search(r"^]+>copyparty v[0-9]", ln): in_sfx = 3 if in_sfx: @@ -56,11 +65,39 @@ def cnv(src): in_salt = 3 if in_salt: in_salt -= 1 - t = ln ln = re.sub(r">[0-9a-zA-Z/+]{24}<", ">24-character-autogenerated<", ln) ln = re.sub(r">[0-9a-zA-Z/+]{40}<", ">40-character-autogenerated<", ln) if t != ln: in_salt = 0 + if "--name TXT" in ln: + in_name = 3 + if in_name: + in_name -= 1 + ln = ln.replace(">" + hostname + "<", ">hostname<") + if t != ln: + in_name = 0 + if "--hash-mt CORES" in ln: + in_cores = 3 + in_hash_mt = True + if "--mtag-mt CORES" in ln or "--th-mt CORES" in ln: + in_cores = 3 + if in_cores: + in_cores -= 1 + zs = ">numCores" + if in_hash_mt: + zs += " if 5 or less" + ln = re.sub(r">[0-9]{1,2}<", zs + "<", ln) + if t != ln: + in_cores = 0 + in_hash_mt = False + if "--th-ram-max GB" in ln: + in_th_ram_max = 3 + if in_th_ram_max: + in_th_ram_max -= 1 + ln = re.sub(r">[0-9]{1,2}\.[0-9]<", ">dynamic<", ln) + if t != ln: + in_th_ram_max = 0 + ln = ln.replace(">/home/ed/", ">~/") if ln.startswith("0" * 20): skip_sfx = True diff --git a/scripts/help2txt.sh b/scripts/help2txt.sh index 4efbd6f7..3345a885 100755 --- a/scripts/help2txt.sh +++ b/scripts/help2txt.sh @@ -6,6 +6,10 @@ s`/home/ed/`~/`; s/uuid:[0-9a-f-]{36}/autogenerated/; s/(-salt SALT.*default: )[0-9a-zA-Z/+]{24}\)/\124-character-autogenerated)/; s/(-salt SALT.*default: )[0-9a-zA-Z/+]{40}\)/\140-character-autogenerated)/; +s/(--name TXT.*default: )[^)]+/\1hostname/; +s/(--hash-mt CORES.*default: )[0-9]+/\1numCores if 5 or less/; +s/(--mtag-mt|th-mt)( CORES.*default: )[0-9]+/\1\2numCores/; +s/(--th-ram-max GB.*default: )[0-9\.]+/\1dynamic/; ' | awk ' /^copyparty/{a=1} !a{next} /^0{20}/{b=1} b&&/^copyparty v[0-9]+\./{s=3}