2017-08-23 08:08:17 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import pathlib
|
|
|
|
import shutil
|
2017-11-29 06:45:29 -05:00
|
|
|
import subprocess
|
2017-08-23 08:08:17 -04:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import xml.etree.ElementTree as etree
|
|
|
|
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
from xeplib import load_xepinfos, Status
|
|
|
|
|
|
|
|
|
2020-06-13 11:08:08 -04:00
|
|
|
def do_archive(xeps_dir, attic, xep, old_version, new_version, build):
|
2018-02-23 02:23:57 -05:00
|
|
|
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)
|
|
|
|
|
2020-06-13 11:08:08 -04:00
|
|
|
if build:
|
|
|
|
subprocess.check_call(["make", "build/xep-{:04d}.html".format(xep)])
|
2018-02-23 02:23:57 -05:00
|
|
|
|
|
|
|
shutil.copy(str(curr_file), str(attic_file))
|
|
|
|
|
|
|
|
|
2017-08-23 08:08:17 -04:00
|
|
|
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/)"
|
|
|
|
)
|
|
|
|
|
2020-06-13 11:08:08 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"--no-build",
|
|
|
|
action="store_false",
|
|
|
|
dest="build",
|
|
|
|
default=True,
|
|
|
|
)
|
|
|
|
|
2018-02-23 02:23:57 -05:00
|
|
|
parser.add_argument(
|
|
|
|
"xeps",
|
|
|
|
nargs="*",
|
|
|
|
type=int,
|
|
|
|
help="Additional XEPs (by their number) to archive. Useful for "
|
|
|
|
"purely editorial changes."
|
|
|
|
)
|
|
|
|
|
2017-08-23 08:08:17 -04:00
|
|
|
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
|
|
|
|
|
2018-02-23 02:23:57 -05:00
|
|
|
force_archive = set(args.xeps)
|
|
|
|
|
2017-08-23 08:08:17 -04:00
|
|
|
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
|
|
|
|
|
2018-02-23 02:23:57 -05:00
|
|
|
force_archive.discard(xep)
|
2020-06-13 11:08:08 -04:00
|
|
|
do_archive(args.xeps_dir, args.attic, xep, old_version, new_version, args.build)
|
2018-02-23 02:23:57 -05:00
|
|
|
changed = True
|
2017-08-23 08:08:17 -04:00
|
|
|
|
2018-02-23 02:23:57 -05:00
|
|
|
for xep in force_archive:
|
|
|
|
old_version = old_accepted.get(xep, {}).get("last_revision", {}).get(
|
|
|
|
"version"
|
|
|
|
)
|
|
|
|
new_version = new_accepted[xep]["last_revision"]["version"]
|
2017-11-29 06:45:29 -05:00
|
|
|
|
2020-06-13 11:08:08 -04:00
|
|
|
do_archive(args.xeps_dir, args.attic, xep, old_version, new_version, args.build)
|
2017-08-23 08:08:17 -04:00
|
|
|
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()
|