comparison venv/lib/python2.7/site-packages/bioblend/__init__.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 import logging
2 import os
3
4 from bioblend.config import Config, BioBlendConfigLocations
5
6 # Current version of the library
7 __version__ = '0.6.1'
8
9 # default chunk size (in bytes) for reading remote data
10 try:
11 import resource
12 CHUNK_SIZE = resource.getpagesize()
13 except Exception:
14 CHUNK_SIZE = 4096
15
16
17 config = Config()
18
19
20 def get_version():
21 """
22 Returns a string with the current version of the library (e.g., "0.2.0")
23 """
24 return __version__
25
26
27 def init_logging():
28 """
29 Initialize BioBlend's logging from a configuration file.
30 """
31 for config_file in BioBlendConfigLocations:
32 try:
33 logging.config.fileConfig(os.path.expanduser(config_file))
34 except:
35 pass
36
37
38 class NullHandler(logging.Handler):
39 def emit(self, record):
40 pass
41
42 # By default, do not force any logging by the library. If you want to see the
43 # log messages in your scripts, add the following to the top of your script:
44 # import logging
45 # logging.basicConfig(filename="bioblend.log", level=logging.DEBUG)
46
47 default_format_string = "%(asctime)s %(name)s [%(levelname)s]: %(message)s"
48 log = logging.getLogger('bioblend')
49 log.addHandler(NullHandler())
50 init_logging()
51
52 # Convenience functions to set logging to a particular file or stream
53 # To enable either of these, simply add the following at the top of a
54 # bioblend module:
55 # import bioblend
56 # bioblend.set_stream_logger(__name__)
57
58
59 def set_file_logger(name, filepath, level=logging.INFO, format_string=None):
60 global log
61 if not format_string:
62 format_string = default_format_string
63 logger = logging.getLogger(name)
64 logger.setLevel(level)
65 fh = logging.FileHandler(filepath)
66 fh.setLevel(level)
67 formatter = logging.Formatter(format_string)
68 fh.setFormatter(formatter)
69 logger.addHandler(fh)
70 log = logger
71
72
73 def set_stream_logger(name, level=logging.DEBUG, format_string=None):
74 global log
75 if not format_string:
76 format_string = default_format_string
77 logger = logging.getLogger(name)
78 logger.setLevel(level)
79 fh = logging.StreamHandler()
80 fh.setLevel(level)
81 formatter = logging.Formatter(format_string)
82 fh.setFormatter(formatter)
83 logger.addHandler(fh)
84 log = logger