Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/bioblend/__init__.py @ 2:6af9afd405e9 draft
"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author | shellac |
---|---|
date | Thu, 14 May 2020 14:56:58 -0400 |
parents | 26e78fe6e8c4 |
children |
comparison
equal
deleted
inserted
replaced
1:75ca89e9b81c | 2:6af9afd405e9 |
---|---|
1 import logging | |
2 import os | |
3 | |
4 from bioblend.config import BioBlendConfigLocations, Config | |
5 | |
6 # Current version of the library | |
7 __version__ = '0.13.0' | |
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 Exception: | |
35 pass | |
36 | |
37 | |
38 class NullHandler(logging.Handler): | |
39 def emit(self, record): | |
40 pass | |
41 | |
42 | |
43 # By default, do not force any logging by the library. If you want to see the | |
44 # log messages in your scripts, add the following to the top of your script: | |
45 # import logging | |
46 # logging.basicConfig(filename="bioblend.log", level=logging.DEBUG) | |
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 | |
85 | |
86 | |
87 class ConnectionError(Exception): | |
88 """ | |
89 An exception class that is raised when unexpected HTTP responses come back. | |
90 | |
91 Should make it easier to debug when strange HTTP things happen such as a | |
92 proxy server getting in the way of the request etc. | |
93 @see: body attribute to see the content of the http response | |
94 """ | |
95 def __init__(self, message, body=None, status_code=None): | |
96 super(ConnectionError, self).__init__(message) | |
97 self.body = body | |
98 self.status_code = status_code | |
99 | |
100 def __str__(self): | |
101 return "{0}: {1}".format(self.args[0], self.body) |