lib/shorturl.py
changeset 19 8d3ffd87cb0b
parent 14 4b5478da5850
child 20 6c774496bb00
--- a/lib/shorturl.py	Sat Dec 22 21:31:01 2007 +0000
+++ b/lib/shorturl.py	Wed Jan 16 14:58:03 2008 +0000
@@ -96,3 +96,32 @@
 
     db['_id'] = id
     db.close()
+
+class DB (object) :
+    def __init__ (self, read_only=True) :
+        self.db = shelve.open('shorturls2', read_only and 'r' or 'c')
+
+    def html_path (self, key, index) :
+        type, dirpath, fname = self.db[key]
+
+        if type == 'img' :
+            fname += '.html'
+        elif type == 'dir' :
+            fname = ''
+
+        if index :
+            dirpath = '../%s' % dirpath
+            
+            if type == 'dir' and index > 1 : 
+                fname = 'index_%s.html' % (index - 1)
+
+        return os.path.join(dirpath, fname)
+   
+    def image_info (self, key) :
+        type, dirpath, fname = self.db[key]
+
+        if type != 'img' :
+            raise ValueError("%s is not an img" % key)
+
+        return dirpath, fname
+