1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-11-21 08:45:04 -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,21 +137,37 @@ def main():
accepted, _ = load_xepinfos(tree) accepted, _ = load_xepinfos(tree)
deferred = list(get_deferred(accepted)) deferred = list(get_deferred(accepted))
for deferred_info in deferred: with contextlib.ExitStack() as stack:
if args.modify: if args.commit:
defer_xep(deferred_info["number"], stack.enter_context(stash_guard())
deferred_info["last_revision"]["version"],
args.modify)
if args.verbose: for deferred_info in deferred:
print( if args.modify:
"XEP-{info[number]:04d}: {info[title]} " defer_xep(deferred_info["number"],
"(last update {info[last_revision][date]:%Y-%m-%d})".format( deferred_info["last_revision"]["version"],
info=deferred_info 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:
print(
"XEP-{info[number]:04d}: {info[title]} "
"(last update {info[last_revision][date]:%Y-%m-%d})".format(
info=deferred_info
)
) )
) else:
else: print(deferred_info["number"])
print(deferred_info["number"])
if __name__ == "__main__": if __name__ == "__main__":