Code

More informative error message
[roundup.git] / roundup / backends / blobfiles.py
index 2080ab450dc8b793bbf2cccb2116cca11dd00eb7..3f110e5b01a7a6fe396b8c9662270ef940f9a131 100644 (file)
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-#$Id: blobfiles.py,v 1.1 2002-02-25 14:25:41 grubert Exp $
+#$Id: blobfiles.py,v 1.4 2002-06-19 03:07:19 richard Exp $
 '''
 This module exports file storage for roundup backends.
 Files are stored into a directory hierarchy.
@@ -23,11 +23,23 @@ Files are stored into a directory hierarchy.
 
 import os, os.path
 
+def files_in_dir(dir):       
+    if not os.path.exists(dir):
+        return 0
+    num_files = 0
+    for dir_entry in os.listdir(dir):
+        full_filename = os.path.join(dir,dir_entry)
+        if os.path.isfile(full_filename):
+            num_files = num_files + 1
+        elif os.path.isdir(full_filename):
+            num_files = num_files + files_in_dir(full_filename)
+    return num_files
+
 class FileStorage:
     """Store files in some directory structure"""
-    def __init__(self):
-        # maybe set "files"
-        pass
+# TODO: maybe set "files"
+#    def __init__(self):
+#        pass
 
     def filename(self, classname, nodeid, property=None):
         '''Determine what the filename for the given node and optionally 
@@ -87,20 +99,20 @@ class FileStorage:
         '''Get number of files in storage, even across subdirectories.
         '''
         files_dir = os.path.join(self.dir, 'files')
-
-        def files_in_dir(dir):       
-            if not os.path.exists(dir):
-                return 0
-            num_files = 0
-            for dir_entry in os.listdir(dir):
-                full_filename = os.path.join(dir,dir_entry)
-                if os.path.isfile(full_filename):
-                    num_files = num_files + 1
-                elif os.path.isdir(full_filename):
-                    num_files = num_files + files_in_dir(full_filename)
-            return num_files
-
         return files_in_dir(files_dir)
 
+    def _doStoreFile(self, name, **databases):
+        '''Store the file as part of a transaction commit.
+        '''
+        # the file is currently ".tmp" - move it to its real name to commit
+        os.rename(name+".tmp", name)
+        pattern = name.split('/')[-1]
+        self.indexer.add_files(dir=os.path.dirname(name), pattern=pattern)
+        self.indexer.save_index()
 
-
+# $Log: not supported by cvs2svn $
+# Revision 1.3  2002/02/27 07:33:34  grubert
+#  . add, vim line and cvs log key.
+#
+#
+# vim: set filetype=python ts=4 sw=4 et si