initial commit

This commit is contained in:
2024-05-29 12:26:15 +02:00
commit 4bbe20497d
8 changed files with 299 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
__version__ = "0.0.0"
__name__ = "git_time_tracking"

View File

View File

@@ -0,0 +1,51 @@
import argparse
import datetime
import subprocess
from .utils import SETTINGS, console
GIT_COMMAND = """
git log "
"""
def main():
# get the user input
parser = argparse.ArgumentParser()
parser.add_argument("date", help="The date to get the logs for")
args = parser.parse_args()
parsed_date = raw_date = args.date.replace("date=", "")
try:
date = datetime.datetime.strptime(raw_date, SETTINGS["date_format"]).date()
parsed_date = date.strftime("%Y-%m-%d")
except ValueError as e:
pass
if SETTINGS["git_author"] is None:
SETTINGS["git_author"] = console.input("Whats your name? ").strip()
parsed_author = SETTINGS["git_author"].replace("'", "")
pretty_author = parsed_author if not SETTINGS["censor_author"] else "*" * len(parsed_author)
console.print("date:\t", parsed_date, style="bold")
console.print("author:\t", pretty_author, style="bold")
# build the command
command = "git log --format=short --author='{}' --since='{} 00:00' --until='{} 23:59'".format(parsed_author, parsed_date, parsed_date)
console.print()
console.print(command)
# run the command in every git directory
for path in SETTINGS["git_directories"]:
path = path.strip()
console.print()
console.print(path, style="bold")
console.print()
subprocess.run(command, shell=True, cwd=path)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,37 @@
import atexit
import signal
from pathlib import Path
import toml
from rich.console import Console
from .__about__ import __name__
console: Console = Console()
CONFIG_PATH = Path.home() / ".config" / __name__ / "config.toml"
SETTINGS = {
"git_directories": [],
"git_author": None,
"censor_author": False,
"date_format": r"%Y-%m-%d",
}
def load_config():
if CONFIG_PATH.exists():
with CONFIG_PATH.open("r", encoding="utf-8") as f:
config = toml.load(f)
SETTINGS.update(config)
load_config()
def save_config():
CONFIG_PATH.parent.mkdir(exist_ok=True, parents=True)
with CONFIG_PATH.open("w", encoding="utf-8") as f:
toml.dump(SETTINGS, f)
atexit.register(save_config)
signal.signal(signal.SIGTERM, save_config)
signal.signal(signal.SIGINT, save_config)