2
The configuration module.
4
__author__ = "Zack Cerza <zcerza@redhat.com>, David Malcolm <dmalcolm@redhat.com>"
10
class _Config(object):
12
Contains configuration parameters for the dogtail run.
15
Directory where things like screenshots are stored.
18
Directory where related data files are located.
21
Directory where dogtail.tc.TC*-generated logs are stored.
23
scriptName(str) [Read-Only]:
24
The name of the script being run.
27
The encoding for text, used by dogtail.tc.TCString .
30
The delay after an action is executed.
33
The delay after a character is typed on the keyboard.
36
The interval at which dogtail.utils.run() and dogtail.procedural.run()
37
check to see if the application has started up.
40
The timeout after which dogtail.utils.run() and dogtail.procedural.run()
41
give up on looking for the newly-started application.
43
searchBackoffDuration (float):
44
Time in seconds for which to delay when a search fails.
46
searchWarningThreshold (int):
47
Number of retries before logging the individual attempts at a search.
49
searchCutoffCount (int):
50
Number of times to retry when a search fails.
53
Default time in seconds to sleep when delaying.
56
When there are a very large number of children of a node, only return
57
this many, starting with the first.
59
debugSearching (boolean):
60
Whether to write info on search backoff and retry to the debug log.
63
Whether to log whenever we sleep to the debug log.
65
debugSearchPaths (boolean):
66
Whether we should write out debug info when running the SearchPath
69
absoluteNodePaths (boolean):
70
Whether we should identify nodes in the logs with long 'abcolute paths', or
71
merely with a short 'relative path'. FIXME: give examples
73
ensureSensitivity (boolean):
74
Should we check that ui nodes are sensitive (not 'greyed out') before
75
performing actions on them? If this is True (the default) it will raise
76
an exception if this happens. Can set to False as a workaround for apps
77
and toolkits that don't report sensitivity properly.
79
debugTranslation (boolean):
80
Whether we should write out debug information from the translation/i18n
83
blinkOnActions (boolean):
84
Whether we should blink a rectangle around a Node when an action is
87
fatalErrors (boolean):
88
Whether errors encountered in dogtail.procedural should be considered
89
fatal. If True, exceptions will be raised. If False, warnings will be
90
passed to the debug logger.
92
checkForA11y (boolean):
93
Whether to check if accessibility is enabled. If not, just assume it is
96
logDebugToFile (boolean):
97
Whether to write debug output to a log file.
99
logDebugToStdOut (boolean):
100
Whether to print log output to console or not (default True).
102
def _getScriptName(self):
103
return os.path.basename(sys.argv[0]).replace('.py','')
104
scriptName = property(_getScriptName)
106
def _getEncoding(self):
107
return locale.getpreferredencoding().lower()
108
encoding = property(_getEncoding)
112
'scratchDir' : '/tmp/dogtail/',
113
'dataDir' : '/tmp/dogtail/data/',
114
'logDir' : '/tmp/dogtail/logs/',
115
'scriptName' : scriptName.fget(None),
116
'encoding' : encoding.fget(None),
122
'typingDelay' : 0.075,
125
'searchBackoffDuration' : 0.5,
126
'searchWarningThreshold' : 3,
127
'searchCutoffCount' : 20,
128
'defaultDelay' : 0.5,
129
'childrenLimit' : 100,
132
'debugSearching' : False,
133
'debugSleep' : False,
134
'debugSearchPaths' : False,
135
'logDebugToStdOut' : True,
136
'absoluteNodePaths' : False,
137
'ensureSensitivity' : False,
138
'debugTranslation' : False,
139
'blinkOnActions' : False,
140
'fatalErrors' : False,
141
'checkForA11y' : True,
144
'logDebugToFile' : True
149
invalidValue = "__INVALID__"
152
_Config.__createDir(_Config.defaults['scratchDir'])
153
_Config.__createDir(_Config.defaults['logDir'])
154
_Config.__createDir(_Config.defaults['dataDir'])
156
def __setattr__(self, name, value):
157
if name not in config.defaults:
158
raise AttributeError, name + " is not a valid option."
160
elif _Config.defaults[name] != value or \
161
_Config.options.get(name, _Config.invalidValue) != value:
163
_Config.__createDir(value)
164
if value[-1] != os.path.sep: value = value + os.path.sep
165
elif name == 'logDebugToFile':
167
logging.debugLogger = logging.Logger('debug', value)
168
_Config.options[name] = value
170
def __getattr__(self, name):
171
try: return _Config.options[name]
173
try: return _Config.defaults[name]
174
except KeyError: raise AttributeError, name + \
175
" is not a valid option."
177
def __createDir(cls, dirName, perms = 0777):
179
Creates a directory (if it doesn't currently exist), creating any
180
parent directories it needs.
182
If perms is None, create with python's default permissions.
184
dirName = os.path.abspath(dirName)
185
#print "Checking for %s ..." % dirName,
186
if not os.path.isdir(dirName):
189
os.makedirs(dirName, perms)
191
else: os.makedirs(dirName)
192
__createDir = classmethod(__createDir)
194
def load(self, dict):
196
Loads values from dict, preserving any options already set that are not overridden.
198
_Config.options.update(dict)
202
Resets all settings to their defaults.
209
if __name__ == '__main__':
211
def failOrPass(failure, description):
214
print "FAILED: " + description
215
else: print "PASSED: " + description
220
for option in config.defaults.keys():
221
failure = failure or not (getattr(config, option) == \
222
config.defaults[option])
223
print failure, option, getattr(config, option), config.defaults[option]
224
failOrPass(failure, "Reading all default values")
227
failure = config.ensureSensitivity != config.defaults['ensureSensitivity']
228
config.ensureSensitivity = False
229
failure = failure or config.ensureSensitivity == True
230
config.ensureSensitivity = True
231
failure = failure or config.ensureSensitivity != True
232
failOrPass(failure, "Setting ensureSensitivity")
235
failure = not os.path.isdir(config.defaults['scratchDir'])
236
failure = failure or not os.path.isdir(config.defaults['logDir'])
237
failure = failure or not os.path.isdir(config.defaults['dataDir'])
238
failOrPass(failure, "Looking for default directories")
241
config.scratchDir = '/tmp/dt'
242
failure = not os.path.isdir('/tmp/dt')
243
config.logDir = '/tmp/dt_log/'
244
failure = failure or not os.path.isdir('/tmp/dt_log/')
245
config.dataDir = '/tmp/dt_data'
246
failure = failure or not os.path.isdir('/tmp/dt_data')
247
failOrPass(failure, "Changing default directories")
251
if anyFailed: sys.exit(1)