command: Fix except declaration for get_comedi_cmd_pointer
[pycomedi.git] / pycomedi / __init__.py
1 # Copyright (C) 2008-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 "A Pythonic wrapper around Comedilib"
18
19 import logging as _logging
20
21
22 __version__ = '0.9'
23
24
25 LOG = _logging.getLogger('pycomedi')
26 "Pycomedi logger"
27
28 LOG.setLevel(_logging.WARN)
29 h = _logging.StreamHandler()
30 f = _logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
31 h.setFormatter(f)
32 LOG.addHandler(h)
33 del h, f
34
35
36 class PyComediError (Exception):
37     "Error in pycomedi"
38     def __init__(self, function_name=None, ret=None, comedi_msg=None,
39                  error_msg=None):
40         self.function_name = function_name
41         self.ret = ret
42         self.comedi_msg = comedi_msg
43         self.error_msg = error_msg
44         if error_msg:
45             msg = '{0} ({1}): {2} ({3})'.format(
46                 function_name, error_msg, comedi_msg, ret)
47         else:
48             msg = '{0}: {1} ({2})'.format(function_name, comedi_msg, ret)
49         super(PyComediError, self).__init__(msg)