aboutsummaryrefslogtreecommitdiff
path: root/kludge-cgit-urls.py
diff options
context:
space:
mode:
Diffstat (limited to 'kludge-cgit-urls.py')
-rwxr-xr-xkludge-cgit-urls.py51
1 files changed, 0 insertions, 51 deletions
diff --git a/kludge-cgit-urls.py b/kludge-cgit-urls.py
deleted file mode 100755
index 4867fed..0000000
--- a/kludge-cgit-urls.py
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/env python3
-#
-# Kludges specific to converting the Cryptech wiki
-
-import os, re, json
-
-with open("repositories.json") as f:
- repo_or = "|".join(os.path.splitext(r)[0] for r in json.load(f))
-
-plain = "](https://git.cryptech.is"
-export = "](export:/"
-browser = "https://trac.cryptech.is/browser/"
-gitrepositories = "GitRepositories/"
-regexp = re.compile(r"(\(https://git\.cryptech\.is/(?:" + repo_or + "))([(/)])")
-
-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)
- with open(fn) as f:
- lines = f.readlines()
- if not any(any(pattern in line for pattern in (plain, export, browser, gitrepositories))
- for line in lines):
- continue
- changes = 0
- for i, line in enumerate(lines):
- if browser in line:
- changes = 1
- line = line.replace(browser, "https://git.cryptech.is/")
- elif gitrepositories in line:
- changes = 1
- line = line \
- .replace("[GitRepositories/", "[") \
- .replace("(GitRepositories/", "(https://git.cryptech.is/") \
- .replace("({filename}GitRepositories/", "(https://git.cryptech.is/")
- elif export in line:
- changes = 1
- line = line.replace(export, "](https://git.cryptech.is/")
- elif plain not in line:
- continue
- lines[i], n = regexp.subn(
- lambda m: m.group(1) + ("/tree" if m.group(2) == "/" else "/about") + m.group(2),
- line)
- changes += n
- if changes:
- tn = fn + ".tmp"
- with open(tn, "w") as f:
- for line in lines:
- f.write(line)
- os.rename(tn, fn)