From e19073995f0073e5b05250e88399e5b20a60f4dc Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Wed, 20 Jul 2022 15:07:47 +0200 Subject: A bit more cleanup (typing et al.) --- osc_fast_export.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/osc_fast_export.py b/osc_fast_export.py index 3b7c727..f07775a 100755 --- a/osc_fast_export.py +++ b/osc_fast_export.py @@ -4,11 +4,13 @@ import collections import configparser from datetime import datetime +import pathlib import subprocess +from typing import List import xml.etree.ElementTree as ET -authorsfile = "authorsfile.txt" +authorsfile = pathlib.PurePath(".git", "authorsfile.txt") # For reading section-less config files # https://stackoverflow.com/a/2819788/164233 @@ -18,8 +20,10 @@ def FakeSecHead(fp): config = configparser.ConfigParser() -config.read_file(FakeSecHead(open(authorsfile))) -authors = dict(config.items("asection")) +authors = {} +if authorsfile.exists(): + config.read_file(FakeSecHead(open(authorsfile))) + authors = dict(config.items("asection")) class LogEntry( @@ -32,7 +36,7 @@ class LogEntry( ) -def osc_log(): +def osc_log() -> List[LogEntry]: try: log_str = subprocess.run( ["osc", "log", "--xml"], check=True, text=True, stdout=subprocess.PIPE @@ -54,11 +58,11 @@ def osc_log(): return log_list -def export_data(dt): +def export_data(dt: str) -> str: return f"data {len(dt)}\n{dt}" -def print_export(entry): +def print_export(entry: LogEntry) -> int: mark = entry.rev author = authors.get(entry.author, "") date = int(datetime.timestamp(entry.date)) @@ -69,6 +73,7 @@ def print_export(entry): print(export_data(entry.msg)) if last_mark: print(f"from :{last_mark}") + # The following is dummy, needs to be replaced by actual content of each commit. print("deleteall") print("M 644 inline tralala") print(export_data("tralalala")) -- cgit