server/sources/storages.py
branchstable
changeset 6383 19ebe0b994d6
parent 5863 4495b9bc49df
child 6401 d7f5d873e1b8
--- a/server/sources/storages.py	Fri Oct 01 17:03:50 2010 +0200
+++ b/server/sources/storages.py	Fri Oct 01 17:04:09 2010 +0200
@@ -18,6 +18,7 @@
 """custom storages for the system source"""
 
 from os import unlink, path as osp
+from contextlib import contextmanager
 
 from yams.schema import role_name
 
@@ -93,6 +94,17 @@
             return path
     return None
 
+@contextmanager
+def fsimport(session):
+    present = 'fs_importing' in session.transaction_data
+    old_value = session.transaction_data.get('fs_importing')
+    session.transaction_data['fs_importing'] = True
+    yield
+    if present:
+        session.transaction_data['fs_importing'] = old_value
+    else:
+        del session.transaction_data['fs_importing']
+
 
 class BytesFileSystemStorage(Storage):
     """store Bytes attribute value on the file system"""