diff options
Diffstat (limited to 'osc_fast_export.py')
-rwxr-xr-x | osc_fast_export.py | 29 |
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") |