1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-11-24 10:12:19 -05:00

Add commit capability to deferrals.py

This commit is contained in:
Jonas Wielicki 2018-01-25 13:44:58 +01:00
parent 1cac2f9918
commit 1409f2722d

View File

@ -1,5 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import contextlib
import re import re
import subprocess
import xml.etree.ElementTree as etree import xml.etree.ElementTree as etree
@ -31,6 +33,29 @@ REVISION_TEMPLATE = """
</revision>""" </revision>"""
@contextlib.contextmanager
def stash_guard():
try:
subprocess.check_call([
"git", "diff-index", "--quiet", "HEAD", "--"
])
except subprocess.CalledProcessError:
# there are changes
pass
else:
yield
return
subprocess.check_call([
"git", "stash",
])
try:
yield
finally:
subprocess.check_call(["git", "stash", "pop"])
def defer_xep(number, last_version, initials): def defer_xep(number, last_version, initials):
filename = "xep-{:04d}.xml".format(number) filename = "xep-{:04d}.xml".format(number)
with open(filename, "r") as f: with open(filename, "r") as f:
@ -94,6 +119,13 @@ def main():
"INITIALS in the remarks." "INITIALS in the remarks."
) )
parser.add_argument(
"-c", "--commit",
default=False,
action="store_true",
help="Create a git commit for each deferral (only reasonable with -m)"
)
args = parser.parse_args() args = parser.parse_args()
if args.xeplist is None: if args.xeplist is None:
@ -105,11 +137,27 @@ def main():
accepted, _ = load_xepinfos(tree) accepted, _ = load_xepinfos(tree)
deferred = list(get_deferred(accepted)) deferred = list(get_deferred(accepted))
with contextlib.ExitStack() as stack:
if args.commit:
stack.enter_context(stash_guard())
for deferred_info in deferred: for deferred_info in deferred:
if args.modify: if args.modify:
defer_xep(deferred_info["number"], defer_xep(deferred_info["number"],
deferred_info["last_revision"]["version"], deferred_info["last_revision"]["version"],
args.modify) args.modify)
if args.commit:
subprocess.check_call([
"git", "add", "xep-{:04d}.xml".format(
deferred_info["number"],
),
])
subprocess.check_call([
"git", "commit", "-vem",
"XEP-{:04d}: deferred due to lack of activity".format(
deferred_info["number"],
),
])
if args.verbose: if args.verbose:
print( print(