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

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

osray: fixed camera parameters

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