~ubuntu-branches/debian/experimental/dogtail/experimental

« back to all changes in this revision

Viewing changes to .pc/0001-homedirornamedtemp.patch/dogtail/config.py

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2013-02-09 16:01:44 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20130209160144-k2yk35tll4eew9wg
Tags: 0.8.1-1
* New maintainer. (Closes: #696136) (Closes: #553898)
* Set packaging format to 3.0 (quilt).
* New upstream release (Closes: #486452):
  - String exceptions are not used anymore. (Closes: #585287)
  - Fix missing check in findChildren(), tree.py (Closes: #485758)
* ACK NMUs:
  - Convert APT's API patch into the quilt format. (Closes: #572087)
  - Convert Ludovico Gardenghi's patch into the quilt
    format. (Closes: #485752)
* Fix desktop file as Freedesktop.org's per-spec.
* Migrate from CDBS + python-support to DH short-form + dh_python2.
* Move to section python.
* Refresh {,Build-}Depends lists.
* Remove xbase-clients from Depends. (Closes: #601486)
* Add Homepage field. (Closes: #572570)
* Add watch file.
* Add gbp config file.
* Refresh debian/copyright to meet copyright format 1.0.
* Install NEWS as upstream changelog.
* Bump Standards.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
class _Config(object):
 
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
    """
 
102
    def _getScriptName(self):
 
103
        return os.path.basename(sys.argv[0]).replace('.py','')
 
104
    scriptName = property(_getScriptName)
 
105
 
 
106
    def _getEncoding(self):
 
107
        return locale.getpreferredencoding().lower()
 
108
    encoding = property(_getEncoding)
 
109
 
 
110
    defaults = {
 
111
            # Storage
 
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
            # Timing and Limits
 
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
            # Debug
 
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
            # Logging
 
144
            'logDebugToFile' : True
 
145
    }
 
146
 
 
147
    options = {}
 
148
 
 
149
    invalidValue = "__INVALID__"
 
150
 
 
151
    def __init__(self):
 
152
        _Config.__createDir(_Config.defaults['scratchDir'])
 
153
        _Config.__createDir(_Config.defaults['logDir'])
 
154
        _Config.__createDir(_Config.defaults['dataDir'])
 
155
 
 
156
    def __setattr__(self, name, value):
 
157
        if name not in config.defaults:
 
158
            raise AttributeError, name + " is not a valid option."
 
159
 
 
160
        elif _Config.defaults[name] != value or \
 
161
                _Config.options.get(name, _Config.invalidValue) != value:
 
162
            if 'Dir' in name:
 
163
                _Config.__createDir(value)
 
164
                if value[-1] != os.path.sep: value = value + os.path.sep
 
165
            elif name == 'logDebugToFile':
 
166
                import logging
 
167
                logging.debugLogger = logging.Logger('debug', value)
 
168
            _Config.options[name] = value
 
169
 
 
170
    def __getattr__(self, name):
 
171
        try: return _Config.options[name]
 
172
        except KeyError:
 
173
            try: return _Config.defaults[name]
 
174
            except KeyError: raise AttributeError, name + \
 
175
                    " is not a valid option."
 
176
 
 
177
    def __createDir(cls, dirName, perms = 0777):
 
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
        #print "Checking for %s ..." % dirName,
 
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
 
 
200
    def     reset(self):
 
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
 
211
    def failOrPass(failure, description):
 
212
        if failure:
 
213
            anyFailed = True
 
214
            print "FAILED: " + description
 
215
        else: print "PASSED: " + description
 
216
 
 
217
    # BEGIN tests
 
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
    # END tests
 
250
 
 
251
    if anyFailed: sys.exit(1)