1 """
2 The configuration module.
3 """
4 __author__ = "Zack Cerza <zcerza@redhat.com>, David Malcolm <dmalcolm@redhat.com>"
5
6 import os
7 import sys
8 import locale
9
11 """
12 Contains configuration parameters for the dogtail run.
13
14 scratchDir(str):
15 Directory where things like screenshots are stored.
16
17 dataDir(str):
18 Directory where related data files are located.
19
20 logDir(str):
21 Directory where dogtail.tc.TC*-generated logs are stored.
22
23 scriptName(str) [Read-Only]:
24 The name of the script being run.
25
26 encoding(str)
27 The encoding for text, used by dogtail.tc.TCString .
28
29 actionDelay(float):
30 The delay after an action is executed.
31
32 typingDelay(float):
33 The delay after a character is typed on the keyboard.
34
35 runInterval(float):
36 The interval at which dogtail.utils.run() and dogtail.procedural.run()
37 check to see if the application has started up.
38
39 runTimeout(int):
40 The timeout after which dogtail.utils.run() and dogtail.procedural.run()
41 give up on looking for the newly-started application.
42
43 searchBackoffDuration (float):
44 Time in seconds for which to delay when a search fails.
45
46 searchWarningThreshold (int):
47 Number of retries before logging the individual attempts at a search.
48
49 searchCutoffCount (int):
50 Number of times to retry when a search fails.
51
52 defaultDelay (float):
53 Default time in seconds to sleep when delaying.
54
55 childrenLimit (int):
56 When there are a very large number of children of a node, only return
57 this many, starting with the first.
58
59 debugSearching (boolean):
60 Whether to write info on search backoff and retry to the debug log.
61
62 debugSleep (boolean):
63 Whether to log whenever we sleep to the debug log.
64
65 debugSearchPaths (boolean):
66 Whether we should write out debug info when running the SearchPath
67 routines.
68
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
72
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.
78
79 debugTranslation (boolean):
80 Whether we should write out debug information from the translation/i18n
81 subsystem.
82
83 blinkOnActions (boolean):
84 Whether we should blink a rectangle around a Node when an action is
85 performed on it.
86
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.
91
92 checkForA11y (boolean):
93 Whether to check if accessibility is enabled. If not, just assume it is
94 (default True).
95
96 logDebugToFile (boolean):
97 Whether to write debug output to a log file.
98
99 logDebugToStdOut (boolean):
100 Whether to print log output to console or not (default True).
101 """
103 return os.path.basename(sys.argv[0]).replace('.py','')
104 scriptName = property(_getScriptName)
105
107 return locale.getpreferredencoding().lower()
108 encoding = property(_getEncoding)
109
110 defaults = {
111
112 'scratchDir' : '/tmp/dogtail/',
113 'dataDir' : '/tmp/dogtail/data/',
114 'logDir' : '/tmp/dogtail/logs/',
115 'scriptName' : scriptName.fget(None),
116 'encoding' : encoding.fget(None),
117 'configFile' : None,
118 'baseFile' : None,
119
120
121 'actionDelay' : 1.0,
122 'typingDelay' : 0.075,
123 'runInterval' : 0.5,
124 'runTimeout' : 30,
125 'searchBackoffDuration' : 0.5,
126 'searchWarningThreshold' : 3,
127 'searchCutoffCount' : 20,
128 'defaultDelay' : 0.5,
129 'childrenLimit' : 100,
130
131
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,
142
143
144 'logDebugToFile' : True
145 }
146
147 options = {}
148
149 invalidValue = "__INVALID__"
150
155
169
176
178 """
179 Creates a directory (if it doesn't currently exist), creating any
180 parent directories it needs.
181
182 If perms is None, create with python's default permissions.
183 """
184 dirName = os.path.abspath(dirName)
185
186 if not os.path.isdir(dirName):
187 if perms:
188 umask = os.umask(0)
189 os.makedirs(dirName, perms)
190 os.umask(umask)
191 else: os.makedirs(dirName)
192 __createDir = classmethod(__createDir)
193
194 - def load(self, dict):
195 """
196 Loads values from dict, preserving any options already set that are not overridden.
197 """
198 _Config.options.update(dict)
199
201 """
202 Resets all settings to their defaults.
203 """
204 _Config.options = {}
205
206
207 config = _Config()
208
209 if __name__ == '__main__':
210 anyFailed = False
212 if failure:
213 anyFailed = True
214 print "FAILED: " + description
215 else: print "PASSED: " + description
216
217
218
219 failure = False
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")
225
226 failure = True
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")
233
234 failure = True
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")
239
240 failure = True
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")
248
249
250
251 if anyFailed: sys.exit(1)
252