~ubuntu-branches/ubuntu/karmic/eikazo/karmic

« back to all changes in this revision

Viewing changes to Eikazo/sanedebug.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien BLACHE
  • Date: 2007-01-01 16:05:19 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070101160519-0ns25jl68t57o918
Tags: 0.5.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
""" 
 
2
Copyright (c) Abel Deuring 2006 <adeuring@gmx.net>
 
3
 
 
4
This program is free software; you can redistribute it and/or modify
 
5
it under the terms of the GNU General Public License as published by
 
6
the Free Software Foundation; either version 2 of the License, or
 
7
(at your option) any later version.
 
8
 
 
9
This program is distributed in the hope that it will be useful,
 
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
GNU General Public License for more details.
 
13
 
 
14
You should have received a copy of the GNU General Public License
 
15
along with this program; if not, write to the Free Software
 
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 
17
 
 
18
adds some features to class sane.SaneDev from PIL's Sane module that make
 
19
debugging and development easier. A challenge for the development of a Sane 
 
20
frontend is that it is very difficult to predict all possible "weirdnesses" 
 
21
of a backend. For example, some backends do not provide options to set
 
22
the scan window. If the device supported by such a backend is not available,
 
23
it is hard to predict all possible error raised by attempts to access
 
24
a non-existing option.
 
25
"""
 
26
 
 
27
from sane import *
 
28
import _sane, os
 
29
 
 
30
    
 
31
test = os.getenv("SANE_DISABLE_OPTIONS")
 
32
if test:
 
33
    disabled_options = test.split(',')
 
34
else:
 
35
    disabled_options = []
 
36
 
 
37
 
 
38
_origSaneDev = SaneDev
 
39
class SaneDev(_origSaneDev):
 
40
    def __load_option_dict(self):
 
41
        global disabled_options
 
42
        d = self.__dict__
 
43
        d['opt'] =  {}
 
44
        optlist = d['dev'].get_options()
 
45
        for t in optlist:
 
46
            o = Option(t, self)
 
47
            if o.type != TYPE_GROUP and not o.py_name in disabled_options:
 
48
                d['opt'][o.py_name] = o
 
49
    
 
50
    def __setattr__(self, key, value):
 
51
        global disabled_options
 
52
        if not key in disabled_options:
 
53
            _origSaneDev.__setattr__(self, key, value)
 
54
        else:
 
55
            # this does not correspond to the normal behaviour of
 
56
            # SaneDev, but it does not make sense to 
 
57
            raise AttributeError, "Option disabled for debugging: " + key
 
58
    
 
59
    def __getattr__(self, key):
 
60
        global disabled_options
 
61
        if not key in disabled_options:
 
62
            return _origSaneDev.__getattr__(self, key)
 
63
        else:
 
64
            raise AttributeError, 'No such attribute: ' + key
 
65
    
 
66
    def get_options(self):
 
67
        res = _origSaneDev.get_options(self)
 
68
        return [x for x in res if not x[1].replace('-', '_') in disabled_options]
 
69
        
 
70
 
 
71
def open(devname):
 
72
    return SaneDev(devname)
 
73
    
 
 
b'\\ No newline at end of file'