2
Copyright (c) Abel Deuring 2006 <adeuring@gmx.net>
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.
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.
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.
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.
31
test = os.getenv("SANE_DISABLE_OPTIONS")
33
disabled_options = test.split(',')
38
_origSaneDev = SaneDev
39
class SaneDev(_origSaneDev):
40
def __load_option_dict(self):
41
global disabled_options
44
optlist = d['dev'].get_options()
47
if o.type != TYPE_GROUP and not o.py_name in disabled_options:
48
d['opt'][o.py_name] = o
50
def __setattr__(self, key, value):
51
global disabled_options
52
if not key in disabled_options:
53
_origSaneDev.__setattr__(self, key, value)
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
59
def __getattr__(self, key):
60
global disabled_options
61
if not key in disabled_options:
62
return _origSaneDev.__getattr__(self, key)
64
raise AttributeError, 'No such attribute: ' + key
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]
72
return SaneDev(devname)
b'\\ No newline at end of file'