-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathlifetime.py
More file actions
46 lines (35 loc) · 1.19 KB
/
lifetime.py
File metadata and controls
46 lines (35 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Activate/deactive some feature of sofa python
Use that to control how some part of the binding should behave.
Usage:
from Sofa.Lifetime import __feature__
with __feature__("feature_name", True):
do_something()
with __feature__("feature_name", False):
do_something()
"""
import Sofa.Lifetime
from contextlib import ContextDecorator
### Initialize the feature set.
# Add your own feature by un-commenting the following line
#Sofa.Lifetime.init("my_feature", False)
Sofa.Lifetime.init("object_auto_init", False)
def has_feature(name):
return Sofa.Lifetime.get(name)
def list_features():
return Sofa.Lifetime.list_features()
class __feature__(ContextDecorator):
@staticmethod
def list_features():
return self.Config.list_feature()
def __init__(self, name, value):
self.name=name
self.new_value=value
self.old_value=None
def __enter__(self):
self.old_value=Sofa.Config.get(self.name)
Sofa.Lifetime.set(self.name, self.new_value)
return self
def __exit__(self, *exc):
Sofa.Lifetime.set(self.name, self.old_value)
return False