94 lines
2.5 KiB
Python
Executable File
94 lines
2.5 KiB
Python
Executable File
#! /usr/bin/env python3
|
|
|
|
import sys
|
|
import os
|
|
import subprocess
|
|
from glob import glob
|
|
|
|
|
|
class Entry:
|
|
name = None
|
|
description = None
|
|
stamps = None
|
|
|
|
def __init__(self, name, description, stamps):
|
|
self.name = name
|
|
self.description = description
|
|
self.stamps = stamps
|
|
|
|
@staticmethod
|
|
def parse(raw_entry):
|
|
description = ""
|
|
stamps = []
|
|
lines = raw_entry.strip().split("\n")
|
|
if len(lines) < 2:
|
|
return None
|
|
name = lines[0].strip()
|
|
previous_was_blank = False
|
|
for line in lines[1:]:
|
|
line = line.strip()
|
|
if previous_was_blank is True and line == "":
|
|
continue
|
|
previous_was_blank = False
|
|
if line.startswith("sdns://"):
|
|
stamps.append(line)
|
|
else:
|
|
description = description + line + "\n"
|
|
|
|
description = description.strip()
|
|
if len(name) < 2 or len(description) < 10 or len(stamps) < 1:
|
|
return None
|
|
|
|
return Entry(name, description, stamps)
|
|
|
|
def format(self):
|
|
out = "## " + self.name + "\n\n"
|
|
out = out + self.description + "\n\n"
|
|
for stamp in self.stamps:
|
|
out = out + stamp + "\n"
|
|
|
|
return out
|
|
|
|
|
|
def process(md_path, signatures_to_update):
|
|
print("\n[" + md_path + "]")
|
|
entries = {}
|
|
out = ""
|
|
previous_content = ""
|
|
|
|
with open(md_path) as f:
|
|
previous_content = f.read()
|
|
c = previous_content.split("\n## ")
|
|
out = out + c[0].strip() + "\n\n"
|
|
raw_entries = c[1:]
|
|
for i in range(0, len(raw_entries)):
|
|
entry = Entry.parse(raw_entries[i])
|
|
if not entry:
|
|
print(
|
|
"Invalid entry: [" + raw_entries[i] + "]", file=sys.stderr)
|
|
continue
|
|
if entry.name in entries:
|
|
print("Duplicate entry: [" + entry.name + "]", file=sys.stderr)
|
|
entries[entry.name] = entry
|
|
|
|
for name in sorted(entries.keys()):
|
|
entry = entries[name]
|
|
out = out + "\n" + entry.format() + "\n"
|
|
|
|
if out == previous_content:
|
|
print("No changes")
|
|
else:
|
|
with open(md_path + ".tmp", "wt") as f:
|
|
f.write(out)
|
|
os.rename(md_path + ".tmp", md_path)
|
|
signatures_to_update.append(md_path)
|
|
|
|
|
|
signatures_to_update = []
|
|
|
|
for md_path in glob("v2/*.md"):
|
|
process(md_path, signatures_to_update)
|
|
|
|
if signatures_to_update:
|
|
subprocess.run(["minisign", "-Sm", *signatures_to_update])
|