command: Fix except declaration for get_comedi_cmd_pointer
[pycomedi.git] / pycomedi / library.pyx
1 # Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
2 #
3 # This file is part of pycomedi.
4 #
5 # pycomedi is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # pycomedi is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # pycomedi.  If not, see <http://www.gnu.org/licenses/>.
16
17 "Wrap library-wide Comedi functions in a `Device` class"
18
19 import os as _os
20
21 from pycomedi cimport _comedilib_h
22 from . import constant as _constant
23
24
25 def set_loglevel(level):
26     """Control the verbosity of Comedilib debugging and error messages
27
28     This function affects the output of debugging and error messages
29     from Comedilib. By increasing the loglevel, additional debugging
30     information will be printed. Error and debugging messages are
31     printed to the stream stderr.
32
33     The default loglevel can be set by using the environment variable
34     COMEDI_LOGLEVEL. The default loglevel is 1.
35
36     In order to conserve resources, some debugging information is
37     disabled by default when Comedilib is compiled.
38
39     See `constants.LOGLEVEL` for a list of possible levels and their
40     meanings.
41
42     Return value
43     ============
44
45     This function returns the previous loglevel.
46
47     >>> from constant import LOGLEVEL
48     >>> level = set_loglevel(LOGLEVEL.error)
49     >>> level
50     <_NamedInt bug>
51     >>> set_loglevel(level)
52     <_NamedInt error>
53     """
54     ret = _comedilib_h.comedi_loglevel(_constant.bitwise_value(level))
55     return _constant.LOGLEVEL.index_by_value(ret)