Skip to content

Commit 6646a0b

Browse files
Updated to python3
1 parent f34a58c commit 6646a0b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

GitAutoDeploy.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

3-
import json, urlparse, sys, os
4-
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
3+
import json, sys, os
4+
from http.server import BaseHTTPRequestHandler, HTTPServer
55
from subprocess import call
66

77
class GitAutoDeploy(BaseHTTPRequestHandler):
@@ -35,15 +35,15 @@ def getConfig(myClass):
3535
return myClass.config
3636

3737
def do_POST(self):
38-
event = self.headers.getheader('X-Github-Event')
38+
event = self.headers.get('X-Github-Event')
3939
if event == 'ping':
4040
if not self.quiet:
41-
print 'Ping event received'
41+
print ('Ping event received')
4242
self.respond(204)
4343
return
4444
if event != 'push':
4545
if not self.quiet:
46-
print 'We only handle ping and push events'
46+
print ('We only handle ping and push events')
4747
self.respond(304)
4848
return
4949

@@ -57,7 +57,7 @@ def do_POST(self):
5757
self.deploy(path)
5858

5959
def parseRequest(self):
60-
length = int(self.headers.getheader('content-length'))
60+
length = int(self.headers.get('content-length'))
6161
body = self.rfile.read(length)
6262
payload = json.loads(body)
6363
self.branch = payload['ref']
@@ -78,9 +78,9 @@ def respond(self, code):
7878

7979
def fetch(self, path):
8080
if(not self.quiet):
81-
print "\nPost push request received"
82-
print 'Updating ' + path
83-
call(['cd "' + path + '" && git fetch'], shell=True)
81+
print ("\nPost push request received")
82+
print ('Updating ' + path)
83+
call(['cd "' + path + '" && git pull'], shell=True) # previously: git fetch
8484

8585
def deploy(self, path):
8686
config = self.getConfig()
@@ -93,45 +93,45 @@ def deploy(self, path):
9393

9494
if branch is None or branch == self.branch:
9595
if(not self.quiet):
96-
print 'Executing deploy command'
96+
print ('Executing deploy command')
9797
call(['cd "' + path + '" && ' + repository['deploy']], shell=True)
98-
98+
9999
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))
101101
break
102102

103103
def main():
104104
try:
105105
server = None
106-
for arg in sys.argv:
106+
for arg in sys.argv:
107107
if(arg == '-d' or arg == '--daemon-mode'):
108108
GitAutoDeploy.daemon = True
109109
GitAutoDeploy.quiet = True
110110
if(arg == '-q' or arg == '--quiet'):
111111
GitAutoDeploy.quiet = True
112-
112+
113113
if(GitAutoDeploy.daemon):
114114
pid = os.fork()
115115
if(pid != 0):
116116
sys.exit()
117117
os.setsid()
118118

119119
if(not GitAutoDeploy.quiet):
120-
print 'Github Autodeploy Service v0.2 started'
120+
print ('Github Autodeploy Service v0.2 started')
121121
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+
124124
server = HTTPServer(('', GitAutoDeploy.getConfig()['port']), GitAutoDeploy)
125125
server.serve_forever()
126126
except (KeyboardInterrupt, SystemExit) as e:
127127
if(e): # wtf, why is this creating a new line?
128-
print >> sys.stderr, e
128+
print (e, file=sys.stderr)
129129

130130
if(not server is None):
131131
server.socket.close()
132132

133133
if(not GitAutoDeploy.quiet):
134-
print 'Goodbye'
134+
print ('Goodbye')
135135

136136
if __name__ == '__main__':
137137
main()

0 commit comments

Comments
 (0)