Mercurial > hg > purlService
comparison restService/redirector.py @ 5:3ebe37d81071
addDri added
reorganisation of the packafes
author | dwinter |
---|---|
date | Fri, 02 Nov 2012 09:01:35 +0100 |
parents | redirector.py@caeede0c9464 |
children | 5f5447b3a082 |
comparison
equal
deleted
inserted
replaced
4:107f13ca333b | 5:3ebe37d81071 |
---|---|
1 ''' | |
2 redirects depending on a configuration file an index.meta purl to an viewer | |
3 Created on 01.11.2012 | |
4 | |
5 @author: dwinter | |
6 ''' | |
7 | |
8 import web | |
9 import manageIndexMetaPURLs | |
10 import logging | |
11 | |
12 class redirector: | |
13 | |
14 viewers={} # hash mit allen viewer name --> urls | |
15 purlHandler=None | |
16 def __init__(self): | |
17 #read config file for the viewers | |
18 confFile= file("viewer.config") | |
19 | |
20 self.purlHandler = manageIndexMetaPURLs.IndexMetaPURLManager() | |
21 | |
22 for line in confFile.readlines(): | |
23 splitted=line.split(",") | |
24 | |
25 list=[] | |
26 if splitted[1]=="": | |
27 list.append(None) # index.meta werden von dieser einstellung nicht interpretiert | |
28 else: | |
29 list.append(splitted[1]) | |
30 | |
31 if len(splitted)>1: # url fur image viewer | |
32 if splitted[2]=="": | |
33 list.append(None) # index.meta werden von dieser einstellung nicht interpretiert | |
34 else: | |
35 list.append(splitted[2]) | |
36 else: | |
37 list.append(None) # null wenn keiner konfiguriert wird. TODO: handle this | |
38 | |
39 | |
40 self.viewers[splitted[0]]=list | |
41 | |
42 def GET(self,path): | |
43 | |
44 splitted=path.split("/") | |
45 if len(splitted)!=2: #pfrad sollte zwei anteile habe "flavour/purl" | |
46 raise web.notfound("not found") | |
47 | |
48 purl = splitted[1] | |
49 flavour = splitted[0] | |
50 | |
51 if flavour not in self.viewers.keys(): | |
52 raise web.notfound("no viewer for %s"%flavour) | |
53 | |
54 formats = self.viewers[flavour] | |
55 | |
56 viewerWithIndexMetaFormatString = formats[0]; | |
57 viewerWithImagePathFormatString = formats[1]; | |
58 | |
59 | |
60 # checke ob es einen Image path gibt | |
61 path,validity = self.purlHandler.getImagePathValidity(purl) | |
62 if path is not None and path!="": | |
63 return self.handlePath(path,validity,viewerWithImagePathFormatString) | |
64 | |
65 | |
66 path,validity = self.purlHandler.getPathValidity(purl) | |
67 | |
68 if path is not None and path !="": | |
69 return self.handlePath(path,validity,viewerWithIndexMetaFormatString) | |
70 | |
71 | |
72 | |
73 #handle path | |
74 def handlePath(self,path,validity,viewerFormatString): | |
75 | |
76 if viewerFormatString is None or viewerFormatString=="": | |
77 raise web.internalerror("no viewer configure for indexMeta for this flavour") | |
78 | |
79 if path is None: | |
80 raise web.notfound("Cannnot find a URL to this path") | |
81 | |
82 if validity is manageIndexMetaPURLs.PERM_NON_VALID: | |
83 raise web.notfound("PURL NON VALID ANYMORE!") | |
84 | |
85 if validity is manageIndexMetaPURLs.TEMP_NON_VALID: | |
86 return web.notfound("PURL currently not VALID try later!") | |
87 | |
88 | |
89 viewerUrl = viewerFormatString%path | |
90 | |
91 print viewerUrl | |
92 raise web.redirect(viewerUrl,"302 found") | |
93 | |
94 if __name__ == '__main__': | |
95 pass |