Skip to content

Commit 5953399

Browse files
committed
add helptext exporters (html, txt)
1 parent d26a944 commit 5953399

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

scripts/help2html.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python3
2+
3+
import re
4+
import subprocess as sp
5+
6+
7+
# to convert the copyparty --help to html, run this in xfce4-terminal @ 140x43:
8+
_ = r""""
9+
echo; for a in '' -accounts -flags -handlers -hooks -urlform -exp -ls -dbd -pwhash -zm; do
10+
./copyparty-sfx.py --help$a 2>/dev/null; printf '\n\n\n%0139d\n\n\n'; done # xfce4-terminal @ 140x43
11+
"""
12+
# click [edit] => [select all]
13+
# click [edit] => [copy as html]
14+
# and then run this script
15+
16+
17+
def readclip():
18+
cmds = [
19+
"xsel -ob",
20+
"xclip -selection CLIPBOARD -o",
21+
"pbpaste",
22+
]
23+
for cmd in cmds:
24+
try:
25+
return sp.check_output(cmd.split()).decode("utf-8")
26+
except:
27+
pass
28+
29+
30+
def cnv(src):
31+
yield '<html style="background:#222;color:#fff"><body>'
32+
skip_sfx = False
33+
in_sfx = 0
34+
in_salt = 0
35+
36+
while True:
37+
ln = next(src)
38+
if "<font" in ln:
39+
if not ln.startswith("<pre>"):
40+
ln = "<pre>" + ln
41+
yield ln
42+
break
43+
44+
for ln in src:
45+
ln = ln.rstrip()
46+
if re.search(r"^<font[^>]+>copyparty v[0-9]", ln):
47+
in_sfx = 3
48+
if in_sfx:
49+
in_sfx -= 1
50+
if not skip_sfx:
51+
yield ln
52+
continue
53+
if '">uuid:' in ln:
54+
ln = re.sub(r">uuid:[0-9a-f-]{36}<", ">autogenerated<", ln)
55+
if "-salt SALT" in ln:
56+
in_salt = 3
57+
if in_salt:
58+
in_salt -= 1
59+
t = ln
60+
ln = re.sub(r">[0-9a-zA-Z/+]{24}<", ">24-character-autogenerated<", ln)
61+
ln = re.sub(r">[0-9a-zA-Z/+]{40}<", ">40-character-autogenerated<", ln)
62+
if t != ln:
63+
in_salt = 0
64+
ln = ln.replace(">/home/ed/", ">~/")
65+
if ln.startswith("0" * 20):
66+
skip_sfx = True
67+
yield ln
68+
69+
yield "</pre>eof</body></html>"
70+
71+
72+
def main():
73+
src = readclip()
74+
src = re.split("0{100,200}", src[::-1], 1)[1][::-1]
75+
with open("helptext.html", "wb") as fo:
76+
for ln in cnv(iter(src.split("\n")[:-3])):
77+
fo.write(ln.encode("utf-8") + b"\r\n")
78+
79+
80+
if __name__ == "__main__":
81+
main()

scripts/help2txt.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -e
3+
4+
( xsel -ob | sed -r '
5+
s`/home/ed/`~/`;
6+
s/uuid:[0-9a-f-]{36}/autogenerated/;
7+
s/(-salt SALT.*default: )[0-9a-zA-Z/+]{24}\)/\124-character-autogenerated)/;
8+
s/(-salt SALT.*default: )[0-9a-zA-Z/+]{40}\)/\140-character-autogenerated)/;
9+
' | awk '
10+
/^copyparty/{a=1} !a{next}
11+
/^0{20}/{b=1} b&&/^copyparty v[0-9]+\./{s=3}
12+
s{s-=1;next} 1' |
13+
head -n-6; echo eof ) >helptext.txt
14+
exit 0
15+
16+
17+
# =====================================================================
18+
# end of script; below is the explanation how to use this:
19+
20+
21+
# first open an infinitely wide console (this is why you own an ultrawide) and copypaste this into it:
22+
for a in '' -accounts -flags -handlers -hooks -urlform -exp -ls -dbd -pwhash -zm; do
23+
./copyparty-sfx.py --help$a 2>/dev/null; printf '\n\n\n%0255d\n\n\n'; done
24+
25+
# then copypaste all of the output by pressing ctrl-shift-a, ctrl-shift-c
26+
# and finally actually run this script which should produce helptext.txt

0 commit comments

Comments
 (0)