server/sources/storages.py
branchstable
changeset 6383 19ebe0b994d6
parent 5863 4495b9bc49df
child 6401 d7f5d873e1b8
equal deleted inserted replaced
6382:4efd0f07fd53 6383:19ebe0b994d6
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """custom storages for the system source"""
    18 """custom storages for the system source"""
    19 
    19 
    20 from os import unlink, path as osp
    20 from os import unlink, path as osp
       
    21 from contextlib import contextmanager
    21 
    22 
    22 from yams.schema import role_name
    23 from yams.schema import role_name
    23 
    24 
    24 from cubicweb import Binary, ValidationError
    25 from cubicweb import Binary, ValidationError
    25 from cubicweb.server import hook
    26 from cubicweb.server import hook
    90     for i in xrange(1, 256):
    91     for i in xrange(1, 256):
    91         path = '%s%s%s' % (base, i, ext)
    92         path = '%s%s%s' % (base, i, ext)
    92         if not osp.isfile(path):
    93         if not osp.isfile(path):
    93             return path
    94             return path
    94     return None
    95     return None
       
    96 
       
    97 @contextmanager
       
    98 def fsimport(session):
       
    99     present = 'fs_importing' in session.transaction_data
       
   100     old_value = session.transaction_data.get('fs_importing')
       
   101     session.transaction_data['fs_importing'] = True
       
   102     yield
       
   103     if present:
       
   104         session.transaction_data['fs_importing'] = old_value
       
   105     else:
       
   106         del session.transaction_data['fs_importing']
    95 
   107 
    96 
   108 
    97 class BytesFileSystemStorage(Storage):
   109 class BytesFileSystemStorage(Storage):
    98     """store Bytes attribute value on the file system"""
   110     """store Bytes attribute value on the file system"""
    99     def __init__(self, defaultdir, fsencoding='utf-8'):
   111     def __init__(self, defaultdir, fsencoding='utf-8'):