Package dogtail :: Module config
[hide private]
[frames] | no frames]

Source Code for Module dogtail.config

  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 10 11 -def _userTmpDir(baseName):
12 # i.e. /tmp/dogtail-foo 13 return '-'.join(('/'.join(('/tmp', baseName)), os.environ['USER']))
14
15 16 -class _Config(object):
17 18 """ 19 Contains configuration parameters for the dogtail run. 20 21 scratchDir(str): 22 Directory where things like screenshots are stored. 23 24 dataDir(str): 25 Directory where related data files are located. 26 27 logDir(str): 28 Directory where dogtail.tc.TC*-generated logs are stored. 29 30 scriptName(str) [Read-Only]: 31 The name of the script being run. 32 33 encoding(str) 34 The encoding for text, used by dogtail.tc.TCString . 35 36 actionDelay(float): 37 The delay after an action is executed. 38 39 typingDelay(float): 40 The delay after a character is typed on the keyboard. 41 42 runInterval(float): 43 The interval at which dogtail.utils.run() and dogtail.procedural.run() 44 check to see if the application has started up. 45 46 runTimeout(int): 47 The timeout after which dogtail.utils.run() and dogtail.procedural.run() 48 give up on looking for the newly-started application. 49 50 searchBackoffDuration (float): 51 Time in seconds for which to delay when a search fails. 52 53 searchWarningThreshold (int): 54 Number of retries before logging the individual attempts at a search. 55 56 searchCutoffCount (int): 57 Number of times to retry when a search fails. 58 59 defaultDelay (float): 60 Default time in seconds to sleep when delaying. 61 62 childrenLimit (int): 63 When there are a very large number of children of a node, only return 64 this many, starting with the first. 65 66 debugSearching (boolean): 67 Whether to write info on search backoff and retry to the debug log. 68 69 debugSleep (boolean): 70 Whether to log whenever we sleep to the debug log. 71 72 debugSearchPaths (boolean): 73 Whether we should write out debug info when running the SearchPath 74 routines. 75 76 absoluteNodePaths (boolean): 77 Whether we should identify nodes in the logs with long 'abcolute paths', or 78 merely with a short 'relative path'. FIXME: give examples 79 80 ensureSensitivity (boolean): 81 Should we check that ui nodes are sensitive (not 'greyed out') before 82 performing actions on them? If this is True (the default) it will raise 83 an exception if this happens. Can set to False as a workaround for apps 84 and toolkits that don't report sensitivity properly. 85 86 debugTranslation (boolean): 87 Whether we should write out debug information from the translation/i18n 88 subsystem. 89 90 blinkOnActions (boolean): 91 Whether we should blink a rectangle around a Node when an action is 92 performed on it. 93 94 fatalErrors (boolean): 95 Whether errors encountered in dogtail.procedural should be considered 96 fatal. If True, exceptions will be raised. If False, warnings will be 97 passed to the debug logger. 98 99 checkForA11y (boolean): 100 Whether to check if accessibility is enabled. If not, just assume it is 101 (default True). 102 103 logDebugToFile (boolean): 104 Whether to write debug output to a log file. 105 106 logDebugToStdOut (boolean): 107 Whether to print log output to console or not (default True). 108 """ 109 @property
110 - def scriptName(self):
111 return os.path.basename(sys.argv[0]).replace('.py', '')
112 113 @property
114 - def encoding(self):
115 return locale.getpreferredencoding().lower()
116 117 defaults = { 118 # Storage 119 'scratchDir': '/'.join((_userTmpDir('dogtail'), '')), 120 'dataDir': '/'.join((_userTmpDir('dogtail'), 'data', '')), 121 'logDir': '/'.join((_userTmpDir('dogtail'), 'logs', '')), 122 'scriptName': scriptName.fget(None), 123 'encoding': encoding.fget(None), 124 'configFile': None, 125 'baseFile': None, 126 127 # Timing and Limits 128 'actionDelay': 1.0, 129 'typingDelay': 0.1, 130 'runInterval': 0.5, 131 'runTimeout': 30, 132 'searchBackoffDuration': 0.5, 133 'searchWarningThreshold': 3, 134 'searchCutoffCount': 20, 135 'defaultDelay': 0.5, 136 'childrenLimit': 100, 137 138 # Debug 139 'debugSearching': False, 140 'debugSleep': False, 141 'debugSearchPaths': False, 142 'logDebugToStdOut': True, 143 'absoluteNodePaths': False, 144 'ensureSensitivity': False, 145 'debugTranslation': False, 146 'blinkOnActions': False, 147 'fatalErrors': False, 148 'checkForA11y': True, 149 150 # Logging 151 'logDebugToFile': True 152 } 153 154 options = {} 155 156 invalidValue = "__INVALID__" 157
158 - def __init__(self):
162
163 - def __setattr__(self, name, value):
164 if name not in config.defaults: 165 raise AttributeError(name + " is not a valid option.") 166 167 elif _Config.defaults[name] != value or \ 168 _Config.options.get(name, _Config.invalidValue) != value: 169 if 'Dir' in name: 170 _Config.__createDir(value) 171 if value[-1] != os.path.sep: 172 value = value + os.path.sep 173 elif name == 'logDebugToFile': 174 import logging 175 logging.debugLogger = logging.Logger('debug', value) 176 _Config.options[name] = value
177
178 - def __getattr__(self, name):
179 try: 180 return _Config.options[name] 181 except KeyError: 182 try: 183 return _Config.defaults[name] 184 except KeyError: 185 raise AttributeError("%s is not a valid option." % name)
186
187 - def __createDir(cls, dirName, perms=0o777):
188 """ 189 Creates a directory (if it doesn't currently exist), creating any 190 parent directories it needs. 191 192 If perms is None, create with python's default permissions. 193 """ 194 dirName = os.path.abspath(dirName) 195 # print "Checking for %s ..." % dirName, 196 if not os.path.isdir(dirName): 197 if perms: 198 umask = os.umask(0) 199 os.makedirs(dirName, perms) 200 os.umask(umask) 201 else: 202 # This is probably a dead code - no other functions call this without the permissions set 203 os.makedirs(dirName) # pragma: no cover
204 __createDir = classmethod(__createDir) 205
206 - def load(self, dict):
207 """ 208 Loads values from dict, preserving any options already set that are not overridden. 209 """ 210 _Config.options.update(dict)
211
212 - def reset(self):
213 """ 214 Resets all settings to their defaults. 215 """ 216 _Config.options = {}
217 218 219 config = _Config() 220