From 21ea76204ce3cc1869257fc8f1585c78d5c4d088 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sat, 24 Jul 2021 00:23:18 -0400 Subject: Whack with club until all links pass linkchecker Most of these weren't really links at all, just unquoted CamelCase. --- kludge-camelcase-oopsies.py | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 kludge-camelcase-oopsies.py (limited to 'kludge-camelcase-oopsies.py') diff --git a/kludge-camelcase-oopsies.py b/kludge-camelcase-oopsies.py new file mode 100755 index 0000000..ab5658d --- /dev/null +++ b/kludge-camelcase-oopsies.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# +# Kludges specific to converting the Cryptech wiki + +import os, re + +brute_force = ( + ("{filename}DNSSEC/Requirements", "{filename}DNSSEC-Requirements"), + ("[OpenDNSSEC](OpenDNSSEC)", "[OpenDNSSEC]({filename}OpenDNSSEC.md)"), + ("[PKCS11Proxy](PKCS11Proxy)", "[PKCS11Proxy]({filename}PKCS11Proxy.md)"), + ('[Collection about side-channel attacks and detection, mitigation methods"]({filename}SideChannel".md)', + '[Collection about side-channel attacks and detection, mitigation methods]({filename}SideChannel.md)'), + ("[Joachim Strömbergson](Joachim Strömbergson)", "[Joachim Strömbergson]({filename}Joachim Strömbergson.md)"), + ('EDAToolchainSurvey"', 'EDAToolchainSurvey'), + ("[for Tor?](1024)", "\[ 1024 for Tor? \]"), + ("[done, nothing using it yet](Mechanism)", "\[Mechanism done, nothing using it yet\]"), + ("[but waiting on a BSD-friendly license](Done,)", "\[Done, but waiting on a BSD-friendly license\]"), + ("[done](Mechanism)", "\[Mechanism done\]"), + ("[Done]", "\[Done\]"), + ("[done]", "\[done\]"), +) + +camel_regexp = re.compile(r"\[(.+?)\]\((?:{filename})?\1.md\)") +foot_regexp = re.compile(r"\[\(([0-9]+)\)\]\(=#fn[0-9]+\)") + +def camel_replacer(dn, m): + if os.path.exists(os.path.join(dn, m.group(1) + ".md")): + return m.group(0) + else: + return m.group(1) + +for root, dirs, files in os.walk("pelican/content"): + for fn in files: + if not fn.endswith(".md"): + continue + fn = os.path.join(root, fn) + dn = os.path.dirname(fn) + with open(fn) as f: + lines = f.readlines() + changes = False + for i, line in enumerate(lines): + for old, new in brute_force: + line = line.replace(old, new) + line = foot_regexp.sub(r"\1.", line) + line = camel_regexp.sub(lambda m: camel_replacer(dn, m), line) + if line != lines[i]: + changes = True + lines[i] = line + if changes: + tn = fn + ".tmp" + with open(tn, "w") as f: + for line in lines: + f.write(line) + os.rename(tn, fn) -- cgit v1.2.3