changeset 28:246049db5466

getImagePath askes now the md server for the image path new module image.py to handle this
author dwinter
date Wed, 13 Mar 2013 15:15:27 +0100
parents cbae1998a2a9
children 7027fbf1d141
files managePurls/manageIndexMetaPURLs.py restService/images.py restService/restService.py
diffstat 3 files changed, 107 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/managePurls/manageIndexMetaPURLs.py	Wed Mar 13 11:02:20 2013 +0100
+++ b/managePurls/manageIndexMetaPURLs.py	Wed Mar 13 15:15:27 2013 +0100
@@ -17,6 +17,8 @@
 VALID=1
 TEMP_NON_VALID=0
 PERM_NON_VALID=-1
+NO_METADATA_FOUND=-2
+NO_IMAGE_PATH_FOUND=-3
     
 class IndexMetaPURLManager:
     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/restService/images.py	Wed Mar 13 15:15:27 2013 +0100
@@ -0,0 +1,103 @@
+'''
+handels the image path
+Created on 13.03.2013
+
+@author: dwinter
+'''
+
+import web
+import managePurls.manageIndexMetaPURLs as manageIndexMetaPURLs
+import logging
+import urllib
+import urllib2
+import sunburnt
+import os.path
+
+#SOLR_URL="http://127.0.0.1:8983/solr/mpiwgSources"
+SOLR_URL="http://md.mpiwg-berlin.mpg.de:8983/solr/mpiwgSources"
+SCALERPATH="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?fn=%s"
+
+
+
+class imageBasic:
+    def __init__(self):
+        self.md=manageIndexMetaPURLs.IndexMetaPURLManager()
+        self.solr = sunburnt.SolrInterface(SOLR_URL)
+        
+    def getImagePathFromMetaData(self,purl):
+        query=self.solr.query(**{'mpiwg-dri':purl})
+        
+        res = query.execute()
+        
+        if res.result.numFound == 0:
+            return "",manageIndexMetaPURLs.NO_METADATA_FOUND
+        
+        doc=res.result.docs[0]
+        
+        path=doc.get('TT_image',None)
+        
+        if not isinstance(path, basestring): #TT_image was  defined as multiple , shouldn't be the case ?
+            path=path[0]
+        
+      
+        archivePath=doc.get('archive-path',None)
+       
+        if (path == None) or (archivePath==None):
+            return "",manageIndexMetaPURLs.NO_IMAGE_PATH_FOUND
+        
+        path = os.path.join(archivePath,path)
+        path = path.replace("/mpiwg/online",'')
+        return path,manageIndexMetaPURLs.VALID
+        
+    def getPath(self,purl):
+        
+        #first try check if path stored
+        path,validity=self.md.getImagePathValidity(purl)
+        
+        if path=="":
+           
+            #second try gessing
+            
+            path,validity=self.getImagePathFromMetaData(purl)
+           
+            if path=="":
+            
+                path,validity=self.md.getPathValidity(purl)
+                
+                path=path.replace("index.meta","pageimg") #hope that images are stored at the required place
+                 
+                if path.startswith("http"): # there is a url stored, than this cannot be a path for the image server
+                    raise web.notfound("NO IMAGE PATH STORED FOUND AN URL(%s)!"%path)
+    
+
+
+        if validity is manageIndexMetaPURLs.PERM_NON_VALID:
+            raise web.notfound("PURL NON VALID ANYMORE!")
+         
+        if validity is manageIndexMetaPURLs.TEMP_NON_VALID:
+            raise web.notfound("PURL currently not VALID try later!")
+        
+        
+        data = web.input()
+        
+        if not 'dw' in data.keys():
+            data['dw']="100"
+       
+        if not 'dh' in data.keys():
+            data['dh']="100"
+          
+       
+        return SCALERPATH%path+"&"+"&".join(["%s=%s"%(key,value) for key,value in data.items()])
+
+
+class imageURL(imageBasic):
+    def GET(self,purl):
+        return self.getPath(purl)
+        
+class image(imageBasic):     
+    def GET(self,purl):
+        path = self.getPath(purl)
+        print path
+        raise web.redirect(path,"302 found")
+    
+        
\ No newline at end of file
--- a/restService/restService.py	Wed Mar 13 11:02:20 2013 +0100
+++ b/restService/restService.py	Wed Mar 13 15:15:27 2013 +0100
@@ -13,6 +13,8 @@
 from searchService.searchLines import searchLines
 from getPurls import getPurls
 from searchService.searchSolr import searchSolr
+from images import image
+from images import imageURL
 
 import config
 
@@ -116,84 +118,7 @@
         return path
         
     
-class imageURL:
-    def __init__(self):
-        self.md=manageIndexMetaPURLs.IndexMetaPURLManager()
-        
-    def GET(self,purl):
-        
-        #first try check if path stored
-        path,validity=self.md.getImagePathValidity(purl)
-        
-        if path=="":
-            print "no path"
-            #second try gessing
-            path,validity=self.md.getPathValidity(purl)
-            
-            path=path.replace("index.meta","pageimg") #hope that images are stored at the required place
-             
-            if path.startswith("http"): # there is a url stored, than this cannot be a path for the image server
-                raise web.notfound("NO IMAGE PATH STORED FOUND AN URL(%s)!"%path)
 
-
-
-        if validity is manageIndexMetaPURLs.PERM_NON_VALID:
-            raise web.notfound("PURL NON VALID ANYMORE!")
-         
-        if validity is manageIndexMetaPURLs.TEMP_NON_VALID:
-            return web.notfound("PURL currently not VALID try later!")
-        
-        
-        data = web.input()
-        
-        if not 'dw' in data.keys():
-            data['dw']="100"
-       
-        if not 'dh' in data.keys():
-            data['dh']="100"
-          
-        
-        return SCALERPATH%path+"&"+"&".join(["%s=%s"%(key,value) for key,value in data.items()])
-
-class image:
-    def __init__(self):
-        self.md=manageIndexMetaPURLs.IndexMetaPURLManager()
-        
-    def GET(self,purl):
-        
-        #first try check if path stored
-        path,validity=self.md.getImagePathValidity(purl)
-        
-        if path=="":
-            print "no path"
-            #second try gessing
-            path,validity=self.md.getPathValidity(purl)
-            
-            path=path.replace("index.meta","pageimg") #hope that images are stored at the required place
-             
-            if path.startswith("http"): # there is a url stored, than this cannot be a path for the image server
-                raise web.notfound("NO IMAGE PATH STORED FOUND AN URL(%s)!"%path)
-
-
-
-        if validity is manageIndexMetaPURLs.PERM_NON_VALID:
-            raise web.notfound("PURL NON VALID ANYMORE!")
-         
-        if validity is manageIndexMetaPURLs.TEMP_NON_VALID:
-            return web.notfound("PURL currently not VALID try later!")
-        
-        
-        data = web.input()
-        
-        if not 'dw' in data.keys():
-            data['dw']="100"
-       
-        if not 'dh' in data.keys():
-            data['dh']="100"
-          
-        
-        raise web.redirect(SCALERPATH%path+"&"+"&".join(["%s=%s"%(key,value) for key,value in data.items()]))
-        
  #http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?fn=/permanent/echo/hellinomnimon/Gazis-Gram_A/img&dw=1298&dh=915&pn=3       
        
 if __name__ == "__main__":