1
1
#!/usr/bin/env python
2
2
3
- import json , urlparse , sys , os
4
- from BaseHTTPServer import BaseHTTPRequestHandler , HTTPServer
3
+ import json , sys , os
4
+ from http . server import BaseHTTPRequestHandler , HTTPServer
5
5
from subprocess import call
6
6
7
7
class GitAutoDeploy (BaseHTTPRequestHandler ):
@@ -35,15 +35,15 @@ def getConfig(myClass):
35
35
return myClass .config
36
36
37
37
def do_POST (self ):
38
- event = self .headers .getheader ('X-Github-Event' )
38
+ event = self .headers .get ('X-Github-Event' )
39
39
if event == 'ping' :
40
40
if not self .quiet :
41
- print 'Ping event received'
41
+ print ( 'Ping event received' )
42
42
self .respond (204 )
43
43
return
44
44
if event != 'push' :
45
45
if not self .quiet :
46
- print 'We only handle ping and push events'
46
+ print ( 'We only handle ping and push events' )
47
47
self .respond (304 )
48
48
return
49
49
@@ -57,7 +57,7 @@ def do_POST(self):
57
57
self .deploy (path )
58
58
59
59
def parseRequest (self ):
60
- length = int (self .headers .getheader ('content-length' ))
60
+ length = int (self .headers .get ('content-length' ))
61
61
body = self .rfile .read (length )
62
62
payload = json .loads (body )
63
63
self .branch = payload ['ref' ]
@@ -78,9 +78,9 @@ def respond(self, code):
78
78
79
79
def fetch (self , path ):
80
80
if (not self .quiet ):
81
- print "\n Post push request received"
82
- print 'Updating ' + path
83
- call (['cd "' + path + '" && git fetch ' ], shell = True )
81
+ print ( "\n Post push request received" )
82
+ print ( 'Updating ' + path )
83
+ call (['cd "' + path + '" && git pull ' ], shell = True ) # previously: git fetch
84
84
85
85
def deploy (self , path ):
86
86
config = self .getConfig ()
@@ -93,45 +93,45 @@ def deploy(self, path):
93
93
94
94
if branch is None or branch == self .branch :
95
95
if (not self .quiet ):
96
- print 'Executing deploy command'
96
+ print ( 'Executing deploy command' )
97
97
call (['cd "' + path + '" && ' + repository ['deploy' ]], shell = True )
98
-
98
+
99
99
elif not self .quiet :
100
- print 'Push to different branch (%s != %s), not deploying' % (branch , self .branch )
100
+ print ( 'Push to different branch (%s != %s), not deploying' % (branch , self .branch ) )
101
101
break
102
102
103
103
def main ():
104
104
try :
105
105
server = None
106
- for arg in sys .argv :
106
+ for arg in sys .argv :
107
107
if (arg == '-d' or arg == '--daemon-mode' ):
108
108
GitAutoDeploy .daemon = True
109
109
GitAutoDeploy .quiet = True
110
110
if (arg == '-q' or arg == '--quiet' ):
111
111
GitAutoDeploy .quiet = True
112
-
112
+
113
113
if (GitAutoDeploy .daemon ):
114
114
pid = os .fork ()
115
115
if (pid != 0 ):
116
116
sys .exit ()
117
117
os .setsid ()
118
118
119
119
if (not GitAutoDeploy .quiet ):
120
- print 'Github Autodeploy Service v0.2 started'
120
+ print ( 'Github Autodeploy Service v0.2 started' )
121
121
else :
122
- print 'Github Autodeploy Service v 0.2 started in daemon mode'
123
-
122
+ print ( 'Github Autodeploy Service v 0.2 started in daemon mode' )
123
+
124
124
server = HTTPServer (('' , GitAutoDeploy .getConfig ()['port' ]), GitAutoDeploy )
125
125
server .serve_forever ()
126
126
except (KeyboardInterrupt , SystemExit ) as e :
127
127
if (e ): # wtf, why is this creating a new line?
128
- print >> sys .stderr , e
128
+ print ( e , file = sys .stderr )
129
129
130
130
if (not server is None ):
131
131
server .socket .close ()
132
132
133
133
if (not GitAutoDeploy .quiet ):
134
- print 'Goodbye'
134
+ print ( 'Goodbye' )
135
135
136
136
if __name__ == '__main__' :
137
137
main ()
0 commit comments