The structure of the company currently in office has not stabilized. Operations related tools are not perfect, and some development does not log into the test environment server permissions, so you write a self-updating test environment tools. Because the Python version of the server is Python 2.6.6
<! DOCTYPE html>Import simplehttpserverimport socketserverimport loggingimport cgiimport subprocessclass AutoReleaseRequestHandler ( Simplehttpserver.simplehttprequesthandler): def do_get (self): logging.warning ("======= GET STARTED =======") Logging.warning (self.headers) Self.path = '/index.html ' SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET (self) def do_post (self): logging.warning ("======= POST STARTED =======") logging.warning (Self.headers) form = CGI. Fieldstorage (Fp=self.rfile, headers=self.headers, environ={' request_method ': ' POST ', ' Content_Type ': self.headers[' Content-type '],}) logging.warning ("======= POST VALUES = ====== ") Self.wfile.write (' {" Status ":" OK ") for the item in Form.list:logging.warning (item) Self.wfile.write (', '%s ': '%s ' \ n '% (Item.name, item.value)) command = ' cd/home/www/%s/; Git stash;git pull--rebase origin%s '% (form[' environ '].value, form[' branch '].value) self.wfile.write (', ' command ': '%s ' '% command) Self.wfile.write ('} ') subprocess. Popen (command, stdout=subprocess. PIPE, Stderr=subprocess. STDOUT, Shell=true) logging.warning ("\ n") if __name__ = = ' __main__ ': print ' starting server, use <Ctrl-C> to stop ' Server = Socketserver.tcpserver ((' 0.0.0.0 ', 1024x768), Autoreleaserequesthandler) Server.serve_forever ()
command to run:
Nohup python release.py >/dev/null &
Python Simplehttpserver Simple Development