changeset 5:3ebe37d81071

addDri added reorganisation of the packafes
author dwinter
date Fri, 02 Nov 2012 09:01:35 +0100
parents 107f13ca333b
children f0417a01690a
files addDriToIndexMeta.py manageIndexMetaPURLs.py redirector.py restService.py restService/__init__.py restService/redirector.py restService/restService.py restService/viewer.config viewer.config
diffstat 8 files changed, 206 insertions(+), 141 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/addDriToIndexMeta.py	Fri Nov 02 09:01:35 2012 +0100
@@ -0,0 +1,65 @@
+'''
+Created on 01.11.2012
+
+@author: dwinter
+'''
+import os
+import manageIndexMetaPURLs
+import re
+from lxml import etree
+
+from os.path import join, getsize
+
+
+def addPURL(fl,purl,test=False):
+    tree = etree.parse(fl)
+    
+    dris = tree.xpath("/resource/meta/dri[@type='mpiwg']")
+    
+    if len(dris)==0: # erzeuge neu
+        newDri = etree.Element("dri",type="mpiwg")
+        newDri.text=purl
+        metas=tree.xpath("/resource/meta")
+        if len(metas)==0:
+            print "no resource/meta in %s"%fl
+            return False
+        else:
+            metas[0].append(newDri)
+    else:
+        dris[0].text=purl
+        
+    print etree.tostring(tree, pretty_print=True)
+    
+    if not test:
+        os.rename(fl, fl+"_mpiwg_dri")
+        out = etree.tostring(tree, encoding="UTF-8",xml_declaration=False)
+        fo = file(fl,"w")
+        fo.write(out)
+        fo.close
+    return True
+    
+def addDriToIndexMeta(path,delpath="",replacepath="", update=False,test=False):
+    
+   
+    
+    for root, dirs, files in os.walk(path):
+    
+    
+        for name in files:
+            if name.endswith(".meta"):
+                fl=join(root, name)
+                shortPath=re.sub("^"+delpath,replacepath,fl)
+                purl=manageIndexMetaPURLs.IndexMetaPURLManager().getPurl(shortPath)
+              
+                addPURL(fl,purl,test)
+                    
+        if 'pageimg' in dirs:
+            dirs.remove('pageimg')  # don't visit pageimf
+        for dir in dirs:
+            if  dir== "pageimg":
+                dirs.remove('pageimg')
+            if  dir.startswith("."):
+                dirs.remove(dir)
+
+if __name__ == '__main__':
+     addDriToIndexMeta("/mpiwg/online/permanent/annalen",delpath="/mpiwg/online")
\ No newline at end of file
--- a/manageIndexMetaPURLs.py	Thu Nov 01 17:08:10 2012 +0100
+++ b/manageIndexMetaPURLs.py	Fri Nov 02 09:01:35 2012 +0100
@@ -38,7 +38,7 @@
     
   
     def __init__(self):
-        self.purlDB = web.database(dbn="postgres", db="purlDB",user="purlUSER",password="p*lWa55eR", host="localhost")
+        self.purlDB = web.database(dbn="postgres", db="purlDB",user="purlUSER",password="3333", host="localhost")
       
     
     
--- a/redirector.py	Thu Nov 01 17:08:10 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-'''
-redirects depending on a configuration file an index.meta purl to an viewer
-Created on 01.11.2012
-
-@author: dwinter
-'''
-
-import web
-import manageIndexMetaPURLs
-import logging
-
-class redirector:
-    
-    viewers={} # hash mit allen viewer name --> urls
-    purlHandler=None
-    def __init__(self):
-        #read config file for the viewers
-        confFile= file("viewer.config")
-        
-        self.purlHandler = manageIndexMetaPURLs.IndexMetaPURLManager()
-        
-        for line in confFile.readlines():
-            splitted=line.split(",")
-            
-            list=[]
-            if splitted[1]=="":
-                list.append(None) # index.meta werden von dieser einstellung nicht interpretiert
-            else:
-                list.append(splitted[1])
-                
-            if len(splitted)>1: # url fur image viewer
-                if splitted[2]=="":
-                    list.append(None) # index.meta werden von dieser einstellung nicht interpretiert
-                else:
-                    list.append(splitted[2])
-            else:
-                list.append(None) # null wenn keiner konfiguriert wird. TODO: handle this
-            
-            
-            self.viewers[splitted[0]]=list
-                
-    def GET(self,path):
-        
-        splitted=path.split("/")
-        if len(splitted)!=2: #pfrad sollte zwei anteile habe "flavour/purl"
-            raise web.notfound("not found")
-        
-        purl = splitted[1] 
-        flavour = splitted[0]
-        
-        if flavour not in self.viewers.keys():
-            raise web.notfound("no viewer for %s"%flavour)
-        
-        formats = self.viewers[flavour]
-        
-        viewerWithIndexMetaFormatString =  formats[0];
-        viewerWithImagePathFormatString = formats[1];
-        
-      
-        # checke ob es einen Image path gibt
-        path,validity = self.purlHandler.getImagePathValidity(purl)
-        if path is not None and path!="":
-            return self.handlePath(path,validity,viewerWithImagePathFormatString)
-        
-        
-        path,validity = self.purlHandler.getPathValidity(purl)
-        
-        if path is not None and path !="":
-            return self.handlePath(path,validity,viewerWithIndexMetaFormatString)
-        
-    
-    
-    #handle path 
-    def handlePath(self,path,validity,viewerFormatString):
-        
-        if viewerFormatString is None or viewerFormatString=="": 
-            raise web.internalerror("no viewer configure for indexMeta for this flavour")
-        
-        if path is None:
-            raise web.notfound("Cannnot find a URL to this 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!")
-        
-    
-        viewerUrl = viewerFormatString%path
-        
-        print viewerUrl
-        raise web.redirect(viewerUrl,"302 found")
-        
-if __name__ == '__main__':
-    pass
\ No newline at end of file
--- a/restService.py	Thu Nov 01 17:08:10 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-'''
-Created on 31.10.2012
-
-@author: dwinter
-'''
-import web
-import manageIndexMetaPURLs
-from redirector import redirector
-import logging
-
-urls = (
-    '/purl/(.+)','purl',
-    '/docuviewer/(.+)','redirector',
-)
-
-app = web.application(urls, globals())
-
-
-class purl:
-    
-    def __init__(self):
-        self.md=manageIndexMetaPURLs.IndexMetaPURLManager()
-        
-    def GET(self,purl):
-        
-        path,validity=self.md.getPathValidity(purl)
-        
-        if path is None:
-            raise web.notfound("Cannnot find a URL to this 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!")
-       
-        
-        return path
-        
-
-if __name__ == "__main__":
-    app.run()
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/restService/redirector.py	Fri Nov 02 09:01:35 2012 +0100
@@ -0,0 +1,95 @@
+'''
+redirects depending on a configuration file an index.meta purl to an viewer
+Created on 01.11.2012
+
+@author: dwinter
+'''
+
+import web
+import manageIndexMetaPURLs
+import logging
+
+class redirector:
+    
+    viewers={} # hash mit allen viewer name --> urls
+    purlHandler=None
+    def __init__(self):
+        #read config file for the viewers
+        confFile= file("viewer.config")
+        
+        self.purlHandler = manageIndexMetaPURLs.IndexMetaPURLManager()
+        
+        for line in confFile.readlines():
+            splitted=line.split(",")
+            
+            list=[]
+            if splitted[1]=="":
+                list.append(None) # index.meta werden von dieser einstellung nicht interpretiert
+            else:
+                list.append(splitted[1])
+                
+            if len(splitted)>1: # url fur image viewer
+                if splitted[2]=="":
+                    list.append(None) # index.meta werden von dieser einstellung nicht interpretiert
+                else:
+                    list.append(splitted[2])
+            else:
+                list.append(None) # null wenn keiner konfiguriert wird. TODO: handle this
+            
+            
+            self.viewers[splitted[0]]=list
+                
+    def GET(self,path):
+        
+        splitted=path.split("/")
+        if len(splitted)!=2: #pfrad sollte zwei anteile habe "flavour/purl"
+            raise web.notfound("not found")
+        
+        purl = splitted[1] 
+        flavour = splitted[0]
+        
+        if flavour not in self.viewers.keys():
+            raise web.notfound("no viewer for %s"%flavour)
+        
+        formats = self.viewers[flavour]
+        
+        viewerWithIndexMetaFormatString =  formats[0];
+        viewerWithImagePathFormatString = formats[1];
+        
+      
+        # checke ob es einen Image path gibt
+        path,validity = self.purlHandler.getImagePathValidity(purl)
+        if path is not None and path!="":
+            return self.handlePath(path,validity,viewerWithImagePathFormatString)
+        
+        
+        path,validity = self.purlHandler.getPathValidity(purl)
+        
+        if path is not None and path !="":
+            return self.handlePath(path,validity,viewerWithIndexMetaFormatString)
+        
+    
+    
+    #handle path 
+    def handlePath(self,path,validity,viewerFormatString):
+        
+        if viewerFormatString is None or viewerFormatString=="": 
+            raise web.internalerror("no viewer configure for indexMeta for this flavour")
+        
+        if path is None:
+            raise web.notfound("Cannnot find a URL to this 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!")
+        
+    
+        viewerUrl = viewerFormatString%path
+        
+        print viewerUrl
+        raise web.redirect(viewerUrl,"302 found")
+        
+if __name__ == '__main__':
+    pass
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/restService/restService.py	Fri Nov 02 09:01:35 2012 +0100
@@ -0,0 +1,42 @@
+'''
+Created on 31.10.2012
+
+@author: dwinter
+'''
+import web
+import manageIndexMetaPURLs
+from redirector import redirector
+import logging
+
+urls = (
+    '/purl/(.+)','purl',
+    '/docuviewer/(.+)','redirector',
+)
+
+app = web.application(urls, globals())
+
+
+class purl:
+    
+    def __init__(self):
+        self.md=manageIndexMetaPURLs.IndexMetaPURLManager()
+        
+    def GET(self,purl):
+        
+        path,validity=self.md.getPathValidity(purl)
+        
+        if path is None:
+            raise web.notfound("Cannnot find a URL to this 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!")
+       
+        
+        return path
+        
+
+if __name__ == "__main__":
+    app.run()
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/restService/viewer.config	Fri Nov 02 09:01:35 2012 +0100
@@ -0,0 +1,3 @@
+echo,http://echo.mpiwg-berlin.mpg.de/ECHOdocuViewfull?url=%s,http://echo.mpiwg-berlin.mpg.de/ECHOdocuViewfull?mode=imagepath&url=%s&viewMode=images
+libcoll,,http://libcoll.mpiwg-berlin.mpg.de/libview?url=%s&mode=imagepath
+digilib,,http://digilib.mpiwg-berlin.mpg.de/digitallibrary/jquery/digilib.html?fn=%s
--- a/viewer.config	Thu Nov 01 17:08:10 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-echo,http://echo.mpiwg-berlin.mpg.de/ECHOdocuViewfull?url=%s,http://echo.mpiwg-berlin.mpg.de/ECHOdocuViewfull?mode=imagepath&url=%s&viewMode=images
-libcoll,,http://libcoll.mpiwg-berlin.mpg.de/libview?url=%s&mode=imagepath
-digilib,,http://digilib.mpiwg-berlin.mpg.de/digitallibrary/jquery/digilib.html?fn=%s