Newer
Older
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
# Copyright (c) 2010- The University of Notre Dame.
# This software is distributed under the GNU General Public License.
# See the file COPYING for details.
""" Weaver options module """
from weaver.logger import D_OPTIONS
from weaver.stack import CurrentOptions, WeaverOptions, stack_context_manager
# Options class
@stack_context_manager(D_OPTIONS, WeaverOptions)
class Options(object):
""" Weaver Options class.
When a :class:`Options` object is created it will use the specified
parameters (i.e. ``cpu``, ``memory``, ``disk``) to record the options. If
any of these parameters are unset (i.e. ``None``) then the unset parameters
will take the value of the current :class:`Options` object. As such, a
:class:`Options` object will inherit options in an hierarchical fashion.
"""
def __init__(self, cpu=None, memory=None, disk=None, batch=None,
local=None, collect=None, environment=None):
# Set options such that specified parameters override current options.
try:
self.cpu = cpu or WeaverOptions.top().cpu
except AttributeError:
self.cpu = cpu
try:
self.memory = memory or WeaverOptions.top().memory
except AttributeError:
self.memory = memory
try:
self.disk = disk or WeaverOptions.top().disk
except AttributeError:
self.disk = disk
try:
self.batch = batch or WeaverOptions.top().batch
except AttributeError:
self.batch = batch
try:
self.local = local or WeaverOptions.top().local
except AttributeError:
self.local = local
try:
self.collect = collect or WeaverOptions.top().collect
except AttributeError:
self.collect = collect
try:
self.environment = environment or dict(WeaverOptions.top().environment)
except AttributeError:
self.environment = environment
if self.environment is None:
self.environment = {}
def __str__(self):
return 'Options(cpu={0}, memory={1}, disk={2}, batch={3}, local={4}, collect={5}, environment={6})'.format(
self.cpu, self.memory, self.disk, self.batch, self.local, self.collect, self.environment)