__init__.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright (C) 2009-2011 Wander Lairson Costa
  2. #
  3. # The following terms apply to all files associated
  4. # with the software unless explicitly disclaimed in individual files.
  5. #
  6. # The authors hereby grant permission to use, copy, modify, distribute,
  7. # and license this software and its documentation for any purpose, provided
  8. # that existing copyright notices are retained in all copies and that this
  9. # notice is included verbatim in any distributions. No written agreement,
  10. # license, or royalty fee is required for any of the authorized uses.
  11. # Modifications to this software may be copyrighted by their authors
  12. # and need not follow the licensing terms described here, provided that
  13. # the new terms are clearly indicated on the first page of each file where
  14. # they apply.
  15. #
  16. # IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
  17. # FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  18. # ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
  19. # DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
  20. # POSSIBILITY OF SUCH DAMAGE.
  21. #
  22. # THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
  23. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  24. # FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
  25. # IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
  26. # NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
  27. # MODIFICATIONS.
  28. r"""PyUSB - Easy USB access in Python
  29. This package exports the following modules and subpackages:
  30. core - the main USB implementation
  31. legacy - the compatibility layer with 0.x version
  32. backend - the support for backend implementations.
  33. Since version 1.0, main PyUSB implementation lives in the 'usb.core'
  34. module. New applications are encouraged to use it.
  35. """
  36. import logging
  37. import os
  38. __author__ = 'Wander Lairson Costa'
  39. __all__ = ['legacy', 'core', 'backend', 'util']
  40. def _setup_log():
  41. logger = logging.getLogger('usb')
  42. debug_level = os.getenv('PYUSB_DEBUG_LEVEL')
  43. if debug_level is not None:
  44. filename = os.getenv('PYUSB_LOG_FILENAME')
  45. LEVELS = {'debug': logging.DEBUG,
  46. 'info': logging.INFO,
  47. 'warning': logging.WARNING,
  48. 'error': logging.ERROR,
  49. 'critical': logging.CRITICAL}
  50. level = LEVELS.get(debug_level, logging.CRITICAL + 10)
  51. logger.setLevel(level = level)
  52. try:
  53. handler = logging.FileHandler(filename)
  54. except:
  55. handler = logging.StreamHandler()
  56. fmt = logging.Formatter('%(asctime)s %(levelname)s:%(name)s:%(message)s')
  57. handler.setFormatter(fmt)
  58. logger.addHandler(handler)
  59. else:
  60. class NullHandler(logging.Handler):
  61. def emit(self, record):
  62. pass
  63. logger.addHandler(NullHandler())
  64. _setup_log()
  65. # We import all 'legacy' module symbols to provide compatility
  66. # with applications that use 0.x versions.
  67. from usb.legacy import *