[Cryptech-Commits] [user/sra/pelican] 30/68: Restructure

git at cryptech.is git at cryptech.is
Mon Jul 19 22:25:09 UTC 2021


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch pelican
in repository user/sra/pelican.

commit 7bf10bb74babd8f16b7a3942607f3d1007aa2324
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Sun Feb 14 16:18:57 2021 +0000

    Restructure
---
 tools/extract.py | 65 +++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 24 deletions(-)

diff --git a/tools/extract.py b/tools/extract.py
index 8035b20..7f76fe9 100755
--- a/tools/extract.py
+++ b/tools/extract.py
@@ -6,6 +6,7 @@ import json
 import os
 import shutil
 import sqlite3
+import sys
 import time
 import urllib.parse
 
@@ -51,38 +52,54 @@ def attachment_link(row):
         os.path.join("attachments", "wiki", h1[:3], h1, h2 + fn2), \
         os.path.join(urllib.parse.quote(row.id, ""), urllib.parse.quote(row.filename, ""))
 
-with open("filter.json") as f:
-    filter = json.load(f)
+class Filter:
 
-def keep(name):
-    for k, v in filter:
-        assert k in "+-"
-        if fnmatch.fnmatch(name, v):
-            return k == "+"
-    return True
+    def __init__(self, filename = "filter.json"):
+        with open(filename) as f:
+            filter = json.load(f)
+        if not all(action in "-+" for action, pattern in filter):
+            sys.exit("Bad action \"{}\" in filter".format(action))
+        self.filter = tuple((action == "+", pattern) for action, pattern in filter)
+
+    def __call__(self, name):
+        for action, pattern in self.filter:
+            if fnmatch.fnmatch(name, pattern):
+                return action
+        return True
 
 class Row(sqlite3.Row):
     def __getattr__(self, name):
         return self[name]
 
-for dn in ("wiki", "pelican/content"):
-    if not os.path.exists(dn):
+def main():
+
+    for dn in ("wiki", "pelican"):
+        shutil.rmtree(dn)
+
+    for dn in ("wiki", "pelican/content/images", "pelican/content/pages"):
         os.makedirs(dn)
 
-db = sqlite3.connect("trac.db")
-db.row_factory = Row
+    #os.link("pelican.conf", "pelican/pelican.conf")
+
+    keep = Filter()
+
+    db = sqlite3.connect("trac.db")
+    db.row_factory = Row
+
+    for row in db.execute(wiki_query):
+        if keep(row.name):
+            slug = urllib.parse.quote(row.name, "")
+            print(slug, row.version)
+            with open("wiki/{}.trac".format(slug), "w") as f:
+                f.write(row.text)
+            md = trac2md.WikiToMD(row.text)
+            with open("pelican/content/{}.md".format(slug), "w") as f:
+                f.write(md)
 
-for row in db.execute(wiki_query):
-    if keep(row.name):
-        slug = urllib.parse.quote(row.name, "")
-        print(slug, row.version)
-        with open("wiki/{}.trac".format(slug), "w") as f:
-            f.write(row.text)
-        md = trac2md.WikiToMD(row.text)
-        with open("pelican/content/{}.md".format(slug), "w") as f:
-            f.write(md)
+    for row in db.execute(attachment_query):
+        print("{} => {}".format(*attachment_link(row)))
 
-for row in db.execute(attachment_query):
-    print("{} => {}".format(*attachment_link(row)))
+    db.close()
 
-db.close()
+if __name__ == "__main__":
+    main()



More information about the Commits mailing list