-
Notifications
You must be signed in to change notification settings - Fork 1
/
autoCommitter.py
86 lines (71 loc) · 2.32 KB
/
autoCommitter.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
# coding=utf8
"""
A simple script that commits ALL changes to a repository
Copyright © 2014 Dimitri Molenaars <tyrope@tyrope.nl>
This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2,
as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
"""
from __future__ import print_function
conf = {}
#----------------------
#- User Configuration -
#----------------------
# Verbosity settings
conf['print_stdout'] = True # Print git output to console.
conf['print_stderr'] = True # Print git errors to console.
conf['silent'] = False # Silence non-git output.
# Push settings
conf['push'] = True # Whether or not to git push.
# If False, this program will only commit.
conf['remote'] = 'origin' # Remote repository you want to push to.
conf['branch'] = 'master' # Remote branch you want to push to.
#------------------------
#- End of Configuration -
#------------------------
from time import sleep
from datetime import datetime
import subprocess
#Prepare commands & Counter value
gitadd = ['git', 'add', '.']
gitcommit = ['git', 'commit', '-a', '--allow-empty', '-m']
gitpush = ['git', 'push', conf['remote'], conf['branch']]
counter = 1
#Helper method.
def gitcmd(cmd):
# Open up a proccess
p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
# Talk to me.
out, err = p.communicate()
# Thank you.
if err != '' and conf['print_stderr']:
print(err)
if conf['print_stdout']:
print(out)
return
# Main Cycle start
if not conf['silent']:
print("Starting the auto committer in 3, 2, 1, GO!")
while True:
counter -= 1
if counter > 0:
# Wait...
if not conf['silent']:
print("Pushing to remote in %s minutes." % (counter+1,))
else:
# Add
gitcmd(gitadd)
# Commit
if not conf['silent']:
print("Committing")
gitcmd(gitcommit + ['AutoCommit: '+str(datetime.now())])
# Push
if conf['push']:
if not conf['silent']:
print("Pushing.")
gitcmd(gitpush)
if not conf['silent']:
print("Push complete. Starting new 15 minutes timer.")
counter = 14
sleep(60)