|
| 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() |
0 commit comments