aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2022-07-20 18:31:49 +0200
committerMatěj Cepl <mcepl@cepl.eu>2022-07-26 09:19:24 +0200
commit574a823d1c793823e31a4b0b9d43139e9b624682 (patch)
treebb9ef8f6c6472aed88975d66ebe9726118f02c23
parentbd639314967d964f1116ddb757986d0b00e79328 (diff)
downloadosc-fast-export-574a823d1c793823e31a4b0b9d43139e9b624682.tar.gz
Improve handling of authors file.
-rwxr-xr-xosc_fast_export.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/osc_fast_export.py b/osc_fast_export.py
index 0042100..545c8f1 100755
--- a/osc_fast_export.py
+++ b/osc_fast_export.py
@@ -9,14 +9,14 @@ import os.path
import pathlib
import subprocess
import sys
-from typing import List
+from typing import Dict, List
import xml.etree.ElementTree as ET
logging.basicConfig(format="%(levelname)s:%(funcName)s:%(message)s", level=logging.INFO)
log = logging.getLogger("osc_fast_export")
-authorsfile = pathlib.Path(".git", "authorsfile.txt")
+NULL = open(os.devnull, "wb")
# For reading section-less config files
# https://stackoverflow.com/a/2819788/164233
@@ -25,13 +25,6 @@ def FakeSecHead(fp):
yield from fp
-config = configparser.ConfigParser()
-authors = {}
-if authorsfile.exists():
- config.read_file(FakeSecHead(open(authorsfile)))
- authors = dict(config.items("asection"))
-
-
class LogEntry(
collections.namedtuple("LogEntry", ["rev", "md5", "author", "date", "msg"])
):
@@ -42,6 +35,18 @@ class LogEntry(
)
+def get_authors() -> Dict[str, str]:
+ config = configparser.ConfigParser()
+ authors = {}
+ authorsfile = pathlib.Path(".osc", "authorsfile.txt")
+
+ if authorsfile.exists():
+ config.read_file(FakeSecHead(open(authorsfile)))
+ authors = dict(config.items("asection"))
+
+ return authors
+
+
def osc_log() -> List[LogEntry]:
try:
log_str = subprocess.run(
@@ -66,7 +71,6 @@ def osc_log() -> List[LogEntry]:
def checkout_revision(rev: int):
- NULL = open(os.devnull, "wb")
try:
subprocess.check_call(
["osc", "up", "-r", f"{rev}"], stdout=NULL, stderr=subprocess.PIPE
@@ -76,7 +80,7 @@ def checkout_revision(rev: int):
raise RuntimeError(f"Cannot checkout revision {rev}!") from exc
-def print_export(entry: LogEntry) -> int:
+def print_export(entry: LogEntry, authors: Dict[str, str]) -> int:
mark = entry.rev
author = authors.get(entry.author, "<none>")
@@ -122,7 +126,8 @@ def print_export(entry: LogEntry) -> int:
if __name__ == "__main__":
last_mark = None
+ authors = get_authors()
for logentry in osc_log():
- last_mark = print_export(logentry)
+ last_mark = print_export(logentry, authors)
print("done")