Trisurf Monte Carlo simulator
Samo Penic
2016-07-11 e984829db39b2778e4f66c34524329ad09749c45
commit | author | age
c54425 1 import subprocess
61d2e7 2 import sys, os
SP 3 if sys.version_info>=(3,0):
4     from urllib.parse import urlparse
5 else:
6     from urlparse import urlparse
c54425 7 import http.server
SP 8 import socketserver
9
10 #Web server
11 class TsWEB(http.server.BaseHTTPRequestHandler):
12     def do_GET(self):
13         parsed_path=urlparse(self.path)
14         """    message_parts = [
15                 'CLIENT VALUES:',
16                 'client_address=%s (%s)' % (self.client_address, self.address_string()),
17                 'command=%s' % self.command,
18                 'path=%s' % self.path,
19                 'real path=%s' % parsed_path.path,
20                 'query=%s' % parsed_path.query,
21                 'request_version=%s' % self.request_version,
22                 '',
23                 'SERVER VALUES:',
24                 'server_version=%s' % self.server_version,
25                 'sys_version=%s' % self.sys_version,
26                 'protocol_version=%s' % self.protocol_version,
27                 '',
28                 'HEADERS RECEIVED:',
29                 ]
30         for name, value in sorted(self.headers.items()):
31             message_parts.append('%s=%s' % (name, value.rstrip()))
32         message_parts.append('')
33         message = '<br>'.join(message_parts) """
34         self.send_response(200)
35         self.end_headers()
36         self.wfile.write(b"<h1>Trisurf-ng manager web interface</h1><hr>")
37         oldstdout=sys.stdout
38         process=subprocess.Popen (['/usr/bin/python3', sys.argv[0], '-s', '--html'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
39         stdout, stderr= process.communicate()
40         output=stdout.decode('ascii')
41         output=output.replace('\n','<BR>')
42         output=bytearray(output,'ascii')
43         self.wfile.write(output)
44
45
46
47
48 class WebServer():
49     def __init__(self, port=8000):
50         http_server = socketserver.TCPServer(('', port), TsWEB)
51         try:
52             http_server.serve_forever()
53         except KeyboardInterrupt:
54             print('^C received, shutting down the web server')
55             http_server.socket.close()
56
57
58
59