diff roundup/hyperdb.py @ 3019:293a17149765

First cut at exporting/importing file content from and to the hyperdb. Unfortunately, I currently set the content using "Class.set", which also updates the "activity". So testImportExport is broken for tsearch2 right now. Also did bits of refactoring in hyperdb.FileClass, a tiny step towards making in-database files backend & indexer-independent.
author Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
date Sat, 18 Dec 2004 11:12:04 +0000
parents 4607f58a007b
children c1c67c62b699
line wrap: on
line diff
--- a/roundup/hyperdb.py	Fri Dec 17 23:42:34 2004 +0000
+++ b/roundup/hyperdb.py	Sat Dec 18 11:12:04 2004 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 #
-# $Id: hyperdb.py,v 1.107 2004-11-25 22:51:06 richard Exp $
+# $Id: hyperdb.py,v 1.108 2004-12-18 11:12:03 jlgijsbers Exp $
 
 """Hyperdatabase implementation, especially field types.
 """
@@ -26,6 +26,7 @@
 
 # roundup modules
 import date, password
+from support import ensureParentsExist
 
 #
 # Types
@@ -746,27 +747,26 @@
         propnames.sort()
         return propnames
 
+    def exportFilename(self, dirname, nodeid):
+        subdir_filename = self.db.subdirFilename(self.classname, nodeid)
+        return os.path.join(dirname, self.classname+'-files', subdir_filename)
+
     def export_files(self, dirname, nodeid):
         ''' Export the "content" property as a file, not csv column
         '''
         source = self.db.filename(self.classname, nodeid)
-        x, filename = os.path.split(source)
-        x, subdir = os.path.split(x)
-        dest = os.path.join(dirname, self.classname+'-files', subdir, filename)
-        if not os.path.exists(os.path.dirname(dest)):
-            os.makedirs(os.path.dirname(dest))
-        shutil.copyfile(source, dest)
+
+        dest = self.exportFilename(dirname, nodeid)
+        ensureParentsExist(dest)
+        shutil.copyfile(source, dest)    
 
     def import_files(self, dirname, nodeid):
         ''' Import the "content" property as a file
         '''
+        source = self.exportFilename(dirname, nodeid)
+
         dest = self.db.filename(self.classname, nodeid, create=1)
-        x, filename = os.path.split(dest)
-        x, subdir = os.path.split(x)
-        source = os.path.join(dirname, self.classname+'-files', subdir,
-            filename)
-        if not os.path.exists(os.path.dirname(dest)):
-            os.makedirs(os.path.dirname(dest))
+        ensureParentsExist(dest)
         shutil.copyfile(source, dest)
 
 class Node:

Roundup Issue Tracker: http://roundup-tracker.org/