From 6646a0b942a10735ab49697e77990793fe4e3a9f Mon Sep 17 00:00:00 2001 From: Moritz <129004253+moritz-reinel@users.noreply.github.com> Date: Wed, 21 Jun 2023 08:38:21 +0200 Subject: [PATCH] Updated to python3 --- GitAutoDeploy.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py index 1e61cc6..dba0771 100755 --- a/GitAutoDeploy.py +++ b/GitAutoDeploy.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -import json, urlparse, sys, os -from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer +import json, sys, os +from http.server import BaseHTTPRequestHandler, HTTPServer from subprocess import call class GitAutoDeploy(BaseHTTPRequestHandler): @@ -35,15 +35,15 @@ def getConfig(myClass): return myClass.config def do_POST(self): - event = self.headers.getheader('X-Github-Event') + event = self.headers.get('X-Github-Event') if event == 'ping': if not self.quiet: - print 'Ping event received' + print ('Ping event received') self.respond(204) return if event != 'push': if not self.quiet: - print 'We only handle ping and push events' + print ('We only handle ping and push events') self.respond(304) return @@ -57,7 +57,7 @@ def do_POST(self): self.deploy(path) def parseRequest(self): - length = int(self.headers.getheader('content-length')) + length = int(self.headers.get('content-length')) body = self.rfile.read(length) payload = json.loads(body) self.branch = payload['ref'] @@ -78,9 +78,9 @@ def respond(self, code): def fetch(self, path): if(not self.quiet): - print "\nPost push request received" - print 'Updating ' + path - call(['cd "' + path + '" && git fetch'], shell=True) + print ("\nPost push request received") + print ('Updating ' + path) + call(['cd "' + path + '" && git pull'], shell=True) # previously: git fetch def deploy(self, path): config = self.getConfig() @@ -93,23 +93,23 @@ def deploy(self, path): if branch is None or branch == self.branch: if(not self.quiet): - print 'Executing deploy command' + print ('Executing deploy command') call(['cd "' + path + '" && ' + repository['deploy']], shell=True) - + elif not self.quiet: - print 'Push to different branch (%s != %s), not deploying' % (branch, self.branch) + print ('Push to different branch (%s != %s), not deploying' % (branch, self.branch)) break def main(): try: server = None - for arg in sys.argv: + for arg in sys.argv: if(arg == '-d' or arg == '--daemon-mode'): GitAutoDeploy.daemon = True GitAutoDeploy.quiet = True if(arg == '-q' or arg == '--quiet'): GitAutoDeploy.quiet = True - + if(GitAutoDeploy.daemon): pid = os.fork() if(pid != 0): @@ -117,21 +117,21 @@ def main(): os.setsid() if(not GitAutoDeploy.quiet): - print 'Github Autodeploy Service v0.2 started' + print ('Github Autodeploy Service v0.2 started') else: - print 'Github Autodeploy Service v 0.2 started in daemon mode' - + print ('Github Autodeploy Service v 0.2 started in daemon mode') + server = HTTPServer(('', GitAutoDeploy.getConfig()['port']), GitAutoDeploy) server.serve_forever() except (KeyboardInterrupt, SystemExit) as e: if(e): # wtf, why is this creating a new line? - print >> sys.stderr, e + print (e, file=sys.stderr) if(not server is None): server.socket.close() if(not GitAutoDeploy.quiet): - print 'Goodbye' + print ('Goodbye') if __name__ == '__main__': main()