64 @objectify_predicate |
64 @objectify_predicate |
65 def repairing(cls, req, **kwargs): |
65 def repairing(cls, req, **kwargs): |
66 """return 1 when repository is running in repair mode""" |
66 """return 1 when repository is running in repair mode""" |
67 return req.vreg.config.repairing |
67 return req.vreg.config.repairing |
68 |
68 |
69 |
|
70 class transaction(object): |
|
71 """Ensure that the transaction is either commited or rolled back at exit |
|
72 |
|
73 Context manager to enter a transaction for a session: when exiting the |
|
74 `with` block on exception, call `session.rollback()`, else call |
|
75 `session.commit()` on normal exit |
|
76 """ |
|
77 def __init__(self, session, free_cnxset=True): |
|
78 self.session = session |
|
79 self.free_cnxset = free_cnxset |
|
80 |
|
81 def __enter__(self): |
|
82 # ensure session has a cnxset |
|
83 self.session.set_cnxset() |
|
84 |
|
85 def __exit__(self, exctype, exc, traceback): |
|
86 if exctype: |
|
87 self.session.rollback(free_cnxset=self.free_cnxset) |
|
88 else: |
|
89 self.session.commit(free_cnxset=self.free_cnxset) |
|
90 |
69 |
91 @deprecated('[3.17] use <object>.allow/deny_all_hooks_but instead') |
70 @deprecated('[3.17] use <object>.allow/deny_all_hooks_but instead') |
92 def hooks_control(obj, mode, *categories): |
71 def hooks_control(obj, mode, *categories): |
93 assert mode in (HOOKS_ALLOW_ALL, HOOKS_DENY_ALL) |
72 assert mode in (HOOKS_ALLOW_ALL, HOOKS_DENY_ALL) |
94 if mode == HOOKS_ALLOW_ALL: |
73 if mode == HOOKS_ALLOW_ALL: |