X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=roundup%2Fbackends%2Fblobfiles.py;h=0008ba60c468aacf0f7bfe91acb97fb23a72d9fa;hb=21b3acdf5b78d378f1f9044815f69f33bd2f168f;hp=3f110e5b01a7a6fe396b8c9662270ef940f9a131;hpb=782c6fb55542f0b10001ef5e19cfbcf64c6de290;p=roundup.git diff --git a/roundup/backends/blobfiles.py b/roundup/backends/blobfiles.py index 3f110e5..0008ba6 100644 --- a/roundup/backends/blobfiles.py +++ b/roundup/backends/blobfiles.py @@ -15,13 +15,13 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: blobfiles.py,v 1.4 2002-06-19 03:07:19 richard Exp $ +#$Id: blobfiles.py,v 1.9 2002-09-10 00:11:50 richard Exp $ ''' This module exports file storage for roundup backends. Files are stored into a directory hierarchy. ''' -import os, os.path +import os def files_in_dir(dir): if not os.path.exists(dir): @@ -37,10 +37,6 @@ def files_in_dir(dir): class FileStorage: """Store files in some directory structure""" -# 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 property is. @@ -74,12 +70,19 @@ class FileStorage: None, in which case the filename does not indicate which property is being saved. ''' + # determine the name of the file to write to name = self.filename(classname, nodeid, property) + + # make sure the file storage dir exists if not os.path.exists(os.path.dirname(name)): os.makedirs(os.path.dirname(name)) + + # open the temp file for writing open(name + '.tmp', 'wb').write(content) - self.transactions.append((self._doStoreFile, (name, ))) + # save off the commit action + self.transactions.append((self.doStoreFile, (classname, nodeid, + property))) def getfile(self, classname, nodeid, property): '''Get the content of the file in the database. @@ -88,6 +91,7 @@ class FileStorage: try: return open(filename, 'rb').read() except: + # now try the temp pre-commit filename try: return open(filename+'.tmp', 'rb').read() except: @@ -101,18 +105,24 @@ class FileStorage: files_dir = os.path.join(self.dir, 'files') return files_in_dir(files_dir) - def _doStoreFile(self, name, **databases): + def doStoreFile(self, classname, nodeid, property, **databases): '''Store the file as part of a transaction commit. ''' + # determine the name of the file to write to + name = self.filename(classname, nodeid, property) + # 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. -# -# + # return the classname, nodeid so we reindex this content + return (classname, nodeid) + + def rollbackStoreFile(self, classname, nodeid, property, **databases): + '''Remove the temp file as a part of a rollback + ''' + # determine the name of the file to delete + name = self.filename(classname, nodeid, property) + if os.path.exists(name+".tmp"): + os.remove(name+".tmp") + # vim: set filetype=python ts=4 sw=4 et si