lib/shorturl.py
changeset 28 70b6c13d084f
parent 26 81d6679d50d0
child 29 990300aa8010
--- a/lib/shorturl.py	Thu Jan 31 17:58:03 2008 +0000
+++ b/lib/shorturl.py	Thu Jan 31 19:13:00 2008 +0000
@@ -23,9 +23,8 @@
 import shelve
 import os.path
 
-from log import index
 
-import utils, db, helpers, folder, image
+import utils, db, helpers, folder, image, log
 
 def int2key (id) :
     """
@@ -146,7 +145,7 @@
     else :
         assert(False, "%r %r" % (obj, id))
 
-    index.info("img %50s %15s = %d %s", dir, fname, id, key)
+    log.info("img %50s %15s = %d %s", dir, fname, id, key)
 
 def updateDB (root) :
     """
@@ -162,8 +161,6 @@
     # dict of (dir, fname) -> obj
     paths = {}
 
-    index.info("Processing ShortURLs...")
-
     while dirqueue :
         dir = dirqueue.pop(0)
 
@@ -172,18 +169,18 @@
         if dir.alive :
             pathtuple = (utils.strip_path(dir.path), '')
             
-            index.debug("dir %50s", pathtuple[0])
+            log.debug("dir %50s", pathtuple[0])
 
             paths[pathtuple] = dir
 
         for img in dir.images.itervalues() :
             pathtuple = (utils.strip_path(img.dir.path), img.name)
             
-            index.debug("img %50s %15s", *pathtuple)
+            log.debug("img %50s %15s", *pathtuple)
 
             paths[pathtuple] = img
     
-    print "%d nodes:" % (len(paths))
+    log.info("we have %d nodes", len(paths))
 
     for (id, dir, fname) in db.select("SELECT id, dirpath, filename FROM nodes") :
         try :
@@ -192,17 +189,20 @@
 
             obj.shorturl_code = key
 
-            index.debug("%s %50s %15s -> %d %s", dir and "img" or "dir", dir, fname, id, key)
+            log.debug("%s %50s %15s -> %d %s", dir and "img" or "dir", dir, fname, id, key)
         
         except KeyError :
             pass
-#            index.warning("non-existant node (%d, %s, %s) in db", id, dir, fname)
+#            log.warning("non-existant node (%d, %s, %s) in db", id, dir, fname)
     
-    print "%d NEW nodes:" % (len(paths))
+    if paths :
+        log.info("allocating shorturls for %d new nodes:", len(paths))
 
-    db.insert_many(
-        _got_obj_key,
-        "INSERT INTO nodes (dirpath, filename) VALUES (?, ?)",
-        ((obj, (path, fname)) for ((path, fname), obj) in paths.iteritems())
-    )
+        db.insert_many(
+            _got_obj_key,
+            "INSERT INTO nodes (dirpath, filename) VALUES (?, ?)",
+            ((obj, (path, fname)) for ((path, fname), obj) in paths.iteritems())
+        )
+    else :
+        log.info("no new images")