This commit is contained in:
bvn13 2024-10-08 00:18:36 +03:00
commit 1601d8a300
5 changed files with 61 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.idea
.idea/**
poetry.lock

0
app/__init__.py Normal file
View File

5
app/logger.py Normal file
View File

@ -0,0 +1,5 @@
import logging
logging.basicConfig(format="%(asctime)s | %(name)s | %(levelname)s | %(message)s")
logger = logging.getLogger(__package__)
logger.setLevel(logging.INFO)

38
main.py Normal file
View File

@ -0,0 +1,38 @@
import argparse
from app.logger import logger as l
import datetime as dt
import subprocess as proc
from scheduler import Scheduler
import time
delta = dt.timedelta(hours=3)
tz_msk = dt.timezone(offset=delta, name="MSK")
logger = l.getChild(__name__)
logger.warning("Starting")
parser = argparse.ArgumentParser(__name__)
parser.add_argument("d", help="Directory to watch")
args = parser.parse_args()
directory = args.d
logger.info(f"Directory to watch: {directory}")
def c(command: str) -> list[str]:
return command.split(" ")
def _watcher() -> None:
g_status = proc.check_output(c("git status -s"))
if g_status is not None:
proc.run(c("git add ."))
now = time.ctime()
proc.run(c(f"git commit -m '{now}'"))
proc.run(c("git fetch"))
proc.run(c("git rebase"))
schedule = Scheduler(tzinfo=tz_msk)
schedule.minutely()
schedule.daily(dt.time(hour=7, minute=5, tzinfo=tz_msk), _watcher)

15
pyproject.toml Normal file
View File

@ -0,0 +1,15 @@
[tool.poetry]
name = "git-pusher"
version = "0.1.0"
description = ""
authors = ["bvn13 <from.github@bvn13.me>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.12"
scheduler = "^0.8.7"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"