-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprogram.py
93 lines (69 loc) · 2.38 KB
/
program.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
88
89
90
91
92
93
import sys
import random
from git import Git
from datetime import datetime, timedelta
from tqdm import tqdm
from args import parser
import signal
import sys
def signal_handler(sig, frame):
print('You pressed Ctrl+C!')
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
def init_config(git, config):
email = config['email']
name = config['name']
if email != None:
git.config('user.email', email)
print("Email: %s" % email)
if name != None:
git.config('user.name', name)
print("Name: %s" % name)
def get_days():
args = parser.parse_args()
config = vars(args)
start_date_str = config['start_date']
end_date_str = config['end_date']
if start_date_str != None:
start_date = datetime.strptime(start_date_str, '%y-%m-%d')
else:
start_date = datetime.today()
if end_date_str != None:
end_date = datetime.strptime(end_date_str, '%y-%m-%d')
else:
end_date = datetime.today()
print("Start date: %s\tEnd Date: %s" % (str(start_date).split(" ")[0], str(end_date).split(" ")[0]))
number_of_days = (end_date - start_date).days
return [(start_date + timedelta(days = day)).isoformat() for day in range(number_of_days)]
def commit_day(git, day, days_list, commits_per_day, delta, is_random):
i = days_list.index(day)
text = ''
if is_random:
commits_per_day = random.randint(
commits_per_day - delta, commits_per_day + delta
)
file_name = 'file.txt'
for commit_id in range(commits_per_day):
text += str(commit_id)
git.append_file(file_name, text)
git.add('.')
git.commit('commit %d for file %d' % (commit_id, i), day)
def main():
args = parser.parse_args()
config = vars(args)
commits_per_day = config['commits_per_day']
is_random = config['random']
delta = config['delta']
repo_name = config['repo_name'][0]
print("Repository name: %s" % repo_name)
print("Is Random: %s \t Delta: %d" % (is_random, delta))
print("commits per day: %d" % commits_per_day)
git = Git(repo_name)
init_config(git, config)
days_list = get_days()
pbar = tqdm(days_list)
for day in pbar:
pbar.set_description("Processing on %s" % day.split('T')[0])
commit_day(git, day, days_list, commits_per_day, delta, is_random)
if __name__ == "__main__":
main()