source: subversion/applications/rendering/parking/osray/osray_server.py @ 21992

Last change on this file since 21992 was 21992, checked in by kdrangmeister, 10 years ago

added comment with web page describing tile coordinates

  • Property svn:mime-type set to text/plain
File size: 3.2 KB
Line 
1# -*- coding: utf-8 -*-
2
3import string, cgi, time
4from os import curdir, sep
5from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
6import urlparse
7import osray
8
9options = {'height': 100, 'dsn': 'dbname=gis', 'width': 100, 'prefix': 'planet_osm', 'bbox': '9.94861 49.79293,9.96912 49.80629', 'quick': False}
10
11# for tile names and coordinates:
12# http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
13
14class osrayHandler(BaseHTTPRequestHandler):
15
16    def do_GET(self):
17        try:
18            theurl = self.path
19            if theurl == "/favicon.ico":
20                self.send_response(200)
21                self.end_headers()
22                self.wfile.write("")
23                return
24            urlcomponents = urlparse.urlparse(theurl)
25            print urlcomponents
26            baseurl = urlcomponents[2]
27            print "parse=",urlparse.urlparse(theurl)
28            print "base=",baseurl
29            urlqs = urlparse.urlparse(theurl)[4]
30            print "URL qs:", urlqs
31            queryparams = urlparse.parse_qs(urlqs)
32            print queryparams
33            if baseurl.endswith(".png"):
34                if queryparams.has_key('width'):
35                    options['width']=queryparams['width'][0]
36                if queryparams.has_key('height'):
37                    options['height']=queryparams['height'][0]
38                print "--- calling osray"
39                osray.main(options)
40                print "--- calling osray ends"
41                f = open(curdir + sep + 'scene-osray.png')
42                self.send_response(200)
43                self.send_header('Content-type','image/png')
44                self.end_headers()
45                self.wfile.write(f.read())
46                f.close()
47                return
48            print "URL was ", theurl
49            urlqs = urlparse.urlparse(theurl)[4]
50            print "URL qs:", urlqs
51            queryparams = urlparse.parse_qs(urlqs)
52            print queryparams
53            self.send_response(200)
54            self.send_header('Content-type', 'text/html')
55            self.end_headers()
56            self.wfile.write("hey, today is the" + str(time.localtime()[7]))
57            self.wfile.write(" day in the year " + str(time.localtime()[0]))
58            return
59        except IOError:
60            self.send_error(404, 'File Not Found: %s' % self.path)
61
62
63"""
64    def do_POST(self):
65        global rootnode
66        try:
67            ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
68            if ctype == 'multipart/form-data':
69                query = cgi.parse_multipart(self.rfile, pdict)
70            self.send_response(301)
71           
72            self.end_headers()
73            upfilecontent = query.get('upfile')
74            print "filecontent", upfilecontent[0]
75            self.wfile.write("<HTML>POST OK.<BR><BR>");
76            self.wfile.write(upfilecontent[0]);
77           
78        except :
79            pass
80"""
81
82def main():
83    try:
84        server = HTTPServer(('', 8087), osrayHandler)
85        print 'started osray server...'
86        server.serve_forever()
87    except KeyboardInterrupt:
88        print 'shutting down server'
89        server.socket.close()
90
91if __name__ == '__main__':
92    main()
Note: See TracBrowser for help on using the repository browser.