server/sources/storages.py
changeset 6401 d7f5d873e1b8
parent 6142 8bc6eac1fac1
parent 6383 19ebe0b994d6
child 6426 541659c39f6a
--- a/server/sources/storages.py	Wed Oct 06 11:57:21 2010 +0200
+++ b/server/sources/storages.py	Wed Oct 06 14:04:26 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
 
@@ -96,6 +97,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"""