initial commit
This commit is contained in:
2
git_time_tracking/__about__.py
Normal file
2
git_time_tracking/__about__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
__version__ = "0.0.0"
|
||||
__name__ = "git_time_tracking"
|
||||
0
git_time_tracking/__init__.py
Normal file
0
git_time_tracking/__init__.py
Normal file
51
git_time_tracking/__main__.py
Normal file
51
git_time_tracking/__main__.py
Normal 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()
|
||||
37
git_time_tracking/utils.py
Normal file
37
git_time_tracking/utils.py
Normal 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)
|
||||
Reference in New Issue
Block a user