This repository was archived by the owner on Dec 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdecorators.py
More file actions
62 lines (54 loc) · 2.01 KB
/
decorators.py
File metadata and controls
62 lines (54 loc) · 2.01 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
__all__ = (
'suppress_action_result',
'dont_isolate_yet',
'isolate_one_only',
'alias',
)
def suppress_action_result(action):
"""
When using a deployment shell, don't print the returned result to stdout.
For example, when the result is superfluous to be printed, because the
action itself contains already print statements, while the result
can be useful for the caller.
"""
action.suppress_result = True
return action
def dont_isolate_yet(func):
"""
If the node has not yet been separated in several parallel, isolated
nodes per host. Don't do it yet for this function.
When another action of the same host without this decorator is called,
the node will be split.
It's for instance useful for reading input, which is similar for all
isolated executions, (like asking which Git Checkout has to be taken),
before forking all the threads.
Note that this will not guarantee that a node will not be split into
its isolations, it does only say, that it does not have to. It is was
already been split before, and this is called from a certain isolation,
we'll keep it like that.
"""
func.dont_isolate_yet = True
return func
def isolate_one_only(func):
"""
When using role isolation, and several hosts are available, run on only
one role. Useful for instance, for a database client. it does not make
sense to run the interactive client on every host which has database
access.
"""
func.isolate_one_only = True
return func
def alias(name):
"""
Give this node action an alias. It will also be accessable using that
name in the deployment shell. This is useful, when you want to have special
characters which are not allowed in Python function names, like dots, in
the name of an action.
"""
def decorator(func):
if hasattr(func, 'action_alias'):
func.action_alias.append(name)
else:
func.action_alias = [ name ]
return func
return decorator