1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-12-22 07:38:52 -05:00
xeps/tools/archive.py
Jonas Schäfer 7eb2c2e095 archive.py: add support for skipping building during archiving
If it is known that the documents have already been built or if it
is imperative to use the versions built even if local changes have
been applied since the last build, this switch comes in handy.
2020-06-14 11:09:19 +02:00

126 lines
3.0 KiB
Python
Executable File

#!/usr/bin/env python3
import pathlib
import shutil
import subprocess
import sys
import xml.etree.ElementTree as etree
from datetime import datetime, timedelta
from xeplib import load_xepinfos, Status
def do_archive(xeps_dir, attic, xep, old_version, new_version, build):
curr_file = xeps_dir / "xep-{:04d}.html".format(xep)
attic_file = attic / "xep-{:04d}-{}.html".format(xep, new_version)
print("XEP-{:04d}:".format(xep), old_version, "->", new_version)
if build:
subprocess.check_call(["make", "build/xep-{:04d}.html".format(xep)])
shutil.copy(str(curr_file), str(attic_file))
def main():
import argparse
parser = argparse.ArgumentParser(
description="Show the XEPs which need to be changed to deferred."
)
parser.add_argument(
"old",
type=argparse.FileType("rb"),
help="Old XEP list"
)
parser.add_argument(
"new",
type=argparse.FileType("rb"),
help="New XEP list"
)
parser.add_argument(
"-d", "--xeps-dir",
type=pathlib.Path,
default=pathlib.Path.cwd() / "build",
help="Path to the built XEPs (defaults to ./build)"
)
parser.add_argument(
"-a", "--attic",
type=pathlib.Path,
default=pathlib.Path.cwd() / '../xep-attic/content/',
help="Path to the attic (defaults to ../xep-attic/content/)"
)
parser.add_argument(
"--no-build",
action="store_false",
dest="build",
default=True,
)
parser.add_argument(
"xeps",
nargs="*",
type=int,
help="Additional XEPs (by their number) to archive. Useful for "
"purely editorial changes."
)
args = parser.parse_args()
with args.old as f:
old_tree = etree.parse(f)
old_accepted, _ = load_xepinfos(old_tree)
with args.new as f:
new_tree = etree.parse(f)
new_accepted, _ = load_xepinfos(new_tree)
changed = False
force_archive = set(args.xeps)
for xep, new_info in new_accepted.items():
old_version = old_accepted.get(xep, {}).get("last_revision", {}).get(
"version"
)
new_version = new_info["last_revision"]["version"]
if old_version == new_version:
continue
force_archive.discard(xep)
do_archive(args.xeps_dir, args.attic, xep, old_version, new_version, args.build)
changed = True
for xep in force_archive:
old_version = old_accepted.get(xep, {}).get("last_revision", {}).get(
"version"
)
new_version = new_accepted[xep]["last_revision"]["version"]
do_archive(args.xeps_dir, args.attic, xep, old_version, new_version, args.build)
changed = True
if changed:
print(
"{}: do not forget to commit & push the attic!".format(
sys.argv[0]
),
file=sys.stderr
)
else:
print("{}: nothing to do".format(sys.argv[0]),
file=sys.stderr)
if __name__ == "__main__":
main()