-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommit.py
More file actions
104 lines (84 loc) · 2.9 KB
/
commit.py
File metadata and controls
104 lines (84 loc) · 2.9 KB
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
94
95
96
97
98
99
100
101
102
103
104
# 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.
"""
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 -
#------------------------
import time
from time import sleep
from datetime import datetime
import subprocess
#Prepare commands & Counter value
gitadd = ['git', 'add', '.']
gitcommit = ['git', 'commit','-a','-m']
gitpush = ['git', 'push', conf['remote'], conf['branch']]
gitstatus = ['git', 'status']
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 out
def getNew():
status = gitcmd(gitstatus).split("\n")
return [x[14:] for x in status if x.startswith("#\tnew file: ")]
def getModified():
status = gitcmd(gitstatus).split("\n")
return [x[14:] for x in status if x.startswith("#\tmodified: ")]
def getDeleted():
status = gitcmd(gitstatus).split("\n")
return [x[14:] for x in status if x.startswith("#\tdeleted: ")]
# 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)
new = getNew()
modified = getModified()
deleted = getDeleted()
# Commit
if not conf['silent']:
print "Committing"
gitcmd(gitcommit + ['AutoCommit: %s. %d deletions, %d adds, %d modifications' % (time.strftime("%Y-%m-%d %H:%M:%S"), len(deleted), len(new), len(modified))])
# 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)