changeset 2:fb2a3b4542a4

restservice
author dwinter
date Wed, 31 Oct 2012 21:54:55 +0100
parents fef9ad4020ee
children caeede0c9464
files createPurlDB.sql manageIndexMetaPURLs.py restService.py
diffstat 3 files changed, 77 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/createPurlDB.sql	Wed Oct 31 16:35:12 2012 +0100
+++ b/createPurlDB.sql	Wed Oct 31 21:54:55 2012 +0100
@@ -1,3 +1,19 @@
+-- Database: "purlDB"
+
+-- DROP DATABASE "purlDB";
+
+CREATE DATABASE "purlDB"
+  WITH OWNER = postgres
+       ENCODING = 'UTF8'
+       TABLESPACE = pg_default
+       LC_COLLATE = 'C'
+       LC_CTYPE = 'C'
+       CONNECTION LIMIT = -1;
+GRANT CONNECT, TEMPORARY ON DATABASE "purlDB" TO public;
+GRANT ALL ON DATABASE "purlDB" TO postgres;
+GRANT ALL ON DATABASE "purlDB" TO "purlUSER";
+
+
 -- Table: purls
 
 -- DROP TABLE purls;
--- a/manageIndexMetaPURLs.py	Wed Oct 31 16:35:12 2012 +0100
+++ b/manageIndexMetaPURLs.py	Wed Oct 31 21:54:55 2012 +0100
@@ -11,6 +11,10 @@
 NEW_PURL=1
 ERROR=-1
 PURL_PREFIX="MPIWG:"
+
+VALID=1
+TEMP_NON_VALID=0
+PERM_NON_VALID=-1
     
 class IndexMetaPURLManager:
     
@@ -30,7 +34,7 @@
     # server_url base_url of server
   
     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")
       
     
     
@@ -40,7 +44,23 @@
             return None
         else:
             return urls[0]['path']
+        
+    def isIndexMeta(self,purl):  
+        urls = self.purlDB.select('"purls"' ,where="purl='%s'"%purl)
+        if urls is None or len(urls)==0:
+            return False
+        else:
+            return urls[0]['is_index_meta']
           
+    
+    def getPathValidity(self,purl):  
+        urls = self.purlDB.select('"purls"' ,where="purl='%s'"%purl)
+        if urls is None or len(urls)==0:
+            return None,-1
+        else:
+            res = urls[0]
+            return res['path'],res['validity']
+      
     #get purl attached tp a path or URL, return None if none.
     
     #checke if purl exist
@@ -157,4 +177,4 @@
     
     im = IndexMetaPURLManager()
     print im.register("/tmp3/index.meta", True, "", "dwinter")
-    pass
+    pass
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/restService.py	Wed Oct 31 21:54:55 2012 +0100
@@ -0,0 +1,39 @@
+'''
+Created on 31.10.2012
+
+@author: dwinter
+'''
+import web
+import manageIndexMetaPURLs
+
+urls = (
+    '/purl/(.+)','purl'
+)
+
+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