-
Notifications
You must be signed in to change notification settings - Fork 0
/
elgit.py
executable file
·87 lines (66 loc) · 2.72 KB
/
elgit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/python3
import argparse
import datetime
import os
import random
import time
unixtime = int
now = datetime.datetime.now()
argparser = argparse.ArgumentParser(description='The simplest tool for deferred commits')
argparser.add_argument('-m', '--msg', type=str, help='commit message')
argparser.add_argument('--minutes', type=int, help='after how many minutes to commit, relative')
argparser.add_argument('--absminutes', type=int, help='after how many minutes to commit, absolute')
argparser.add_argument('--hours', type=int, help='after how many hours to commit, relative')
argparser.add_argument('--abshours', type=int, help='after how many hours to commit, absolute')
argparser.add_argument('--days', type=int, help='after how many days to commit, relative')
argparser.add_argument('--absdays', type=int, help='after how many days to commit, absolute')
argparser.add_argument('--months', type=int, help='after how many months to commit, relative')
argparser.add_argument('--absmonths', type=int, help='after how many months to commit, absolute')
argparser.add_argument('--randtime', action='store_true', help='random commit time')
args = argparser.parse_args()
def generate_commit_time(arguments) -> unixtime:
minutes: int = 0
hours: int = 0
days: int = 0
months: int = 0
if arguments.randtime:
minutes = random.randint(0, 59)
hours = random.randint(0, 23)
else:
if arguments.minutes != None:
minutes = (now + datetime.timedelta(minutes=arguments.minutes)).minute
elif arguments.absminutes != None:
minutes = arguments.absminutes
else:
minutes = now.minute
if arguments.hours != None:
hours = (now + datetime.timedelta(hours=arguments.hours)).hour
elif arguments.abshours != None:
hours = arguments.abshours
else:
hours = now.hour
if arguments.days != None:
days = (now + datetime.timedelta(days=arguments.days)).day
elif arguments.absdays != None:
days = arguments.absdays
else:
days = now.day
if arguments.months != None:
months = (now + datetime.timedelta(days=arguments.months * 30)).month
elif arguments.absmonths != None:
months = arguments.absmonths
else:
months = now.month
return int(time.mktime(datetime.datetime(
year=now.year,
month=months,
day=days,
hour=hours,
minute=minutes,
second=now.second
).timetuple()))
def create_commit(arguments, commit_time: unixtime):
os.system(f'git commit -m "{arguments.msg}" --date="{commit_time}"')
if __name__ == '__main__':
commit_time: unixtime = generate_commit_time(args)
create_commit(args, commit_time)