@@ -33,12 +33,12 @@ class ExecEnv:
33
33
"""Object representing execution environment"""
34
34
35
35
UNATTENDED_ARG = "unattended"
36
- ACCEPTDIALOGS_ARG = "accept_dialogs"
36
+ ACCEPT_DIALOGS_ARG = "accept_dialogs"
37
37
VERBOSE_ARG = "verbose"
38
38
SCREENSHOT_ARG = "screenshot"
39
39
DELAY_ARG = "delay"
40
40
UNATTENDED_ENV = "GUIDATA_UNATTENDED"
41
- ACCEPTDIALOGS_ENV = "GUIDATA_ACCEPT_DIALOGS"
41
+ ACCEPT_DIALOGS_ENV = "GUIDATA_ACCEPT_DIALOGS"
42
42
VERBOSE_ENV = "GUIDATA_VERBOSE"
43
43
SCREENSHOT_ENV = "GUIDATA_SCREENSHOT"
44
44
DELAY_ENV = "GUIDATA_DELAY"
@@ -50,15 +50,23 @@ def __init__(self):
50
50
# Check that calling `to_dict` do not raise any exception
51
51
self .to_dict ()
52
52
53
+ def iterate_over_attrs_envvars (self ) -> Generator [tuple [str , str ], None , None ]:
54
+ """Iterate over CDL environment variables
55
+
56
+ Yields:
57
+ A tuple (attribute name, environment variable name)
58
+ """
59
+ for name in dir (self ):
60
+ if name .endswith ("_ENV" ):
61
+ envvar : str = getattr (self , name )
62
+ attrname = "_" .join (name .split ("_" )[:- 1 ]).lower ()
63
+ yield attrname , envvar
64
+
53
65
def to_dict (self ):
54
66
"""Return a dictionary representation of the object"""
55
- # The list of properties match the list of environment variable names, modulo
56
- # the "GUIDATA_" prefix for environment variables:
57
- props = [
58
- "_" .join (getattr (self , attrname ).split ("_" )[1 :]).lower ()
59
- for attrname in dir (self )
60
- if attrname .endswith ("_ENV" )
61
- ]
67
+ # The list of properties match the list of environment variable attribute names,
68
+ # modulo the "_ENV" suffix:
69
+ props = [attrname for attrname , _envvar in self .iterate_over_attrs_envvars ()]
62
70
63
71
# Check that all properties are defined in the class and that they are
64
72
# really properties:
@@ -106,12 +114,12 @@ def unattended(self, value):
106
114
@property
107
115
def accept_dialogs (self ):
108
116
"""Whether to accept dialogs in unattended mode"""
109
- return self .__get_mode (self .ACCEPTDIALOGS_ENV )
117
+ return self .__get_mode (self .ACCEPT_DIALOGS_ENV )
110
118
111
119
@accept_dialogs .setter
112
120
def accept_dialogs (self , value ):
113
121
"""Set whether to accept dialogs in unattended mode"""
114
- self .__set_mode (self .ACCEPTDIALOGS_ENV , value )
122
+ self .__set_mode (self .ACCEPT_DIALOGS_ENV , value )
115
123
116
124
@property
117
125
def screenshot (self ):
@@ -159,7 +167,7 @@ def parse_args(self):
159
167
default = None ,
160
168
)
161
169
parser .add_argument (
162
- "--" + self .ACCEPTDIALOGS_ARG ,
170
+ "--" + self .ACCEPT_DIALOGS_ARG ,
163
171
action = "store_true" ,
164
172
help = "accept dialogs in unattended mode" ,
165
173
default = None ,
@@ -190,7 +198,7 @@ def set_env_from_args(self, args):
190
198
"""Set appropriate environment variables"""
191
199
for argname in (
192
200
self .UNATTENDED_ARG ,
193
- self .ACCEPTDIALOGS_ARG ,
201
+ self .ACCEPT_DIALOGS_ARG ,
194
202
self .SCREENSHOT_ARG ,
195
203
self .VERBOSE_ARG ,
196
204
self .DELAY_ARG ,
0 commit comments