comparison planemo/lib/python3.7/site-packages/bioblend/config.py @ 0:d30785e31577 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:18:57 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d30785e31577
1 import configparser
2 import os
3
4 BioBlendConfigPath = '/etc/bioblend.cfg'
5 BioBlendConfigLocations = [BioBlendConfigPath]
6 UserConfigPath = os.path.join(os.path.expanduser('~'), '.bioblend')
7 BioBlendConfigLocations.append(UserConfigPath)
8
9
10 class Config(configparser.ConfigParser):
11 """
12 BioBlend allows library-wide configuration to be set in external files.
13 These configuration files can be used to specify access keys, for example.
14 By default we use two locations for the BioBlend configurations:
15
16 * System wide: ``/etc/bioblend.cfg``
17 * Individual user: ``~/.bioblend`` (which works on both Windows and Unix)
18 """
19 def __init__(self, path=None, fp=None, do_load=True):
20 super().__init__({'working_dir': '/mnt/pyami', 'debug': '0'})
21 if do_load:
22 if path:
23 self.load_from_path(path)
24 elif fp:
25 self.readfp(fp)
26 else:
27 self.read(BioBlendConfigLocations)
28
29 def get_value(self, section, name, default=None):
30 return self.get(section, name, default)
31
32 def get(self, section, name, default=None):
33 """
34 """
35 try:
36 val = super().get(section, name)
37 except Exception:
38 val = default
39 return val
40
41 def getint(self, section, name, default=0):
42 try:
43 val = super().getint(section, name)
44 except Exception:
45 val = int(default)
46 return val
47
48 def getfloat(self, section, name, default=0.0):
49 try:
50 val = super().getfloat(section, name)
51 except Exception:
52 val = float(default)
53 return val
54
55 def getbool(self, section, name, default=False):
56 if self.has_option(section, name):
57 val = self.get(section, name)
58 if val.lower() == 'true':
59 val = True
60 else:
61 val = False
62 else:
63 val = default
64 return val