-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.py
More file actions
44 lines (35 loc) · 1.3 KB
/
config.py
File metadata and controls
44 lines (35 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import ConfigParser
import os
import sys
import tempfile
load_dir = os.path.join(tempfile.gettempdir(), 'treestore')
base_uri = 'http://www.phylocommons.org/trees/'
def get_treestore_kwargs():
global load_dir
global base_uri
config_dir = os.path.expanduser('~/.treestore')
if not os.path.exists(config_dir): os.makedirs(config_dir)
config_file_path = os.path.join(config_dir, 'treestore.config')
defaults = [
('dsn', 'Virtuoso'),
('user', 'dba'),
('password', 'dba'),
('load_dir', load_dir),
('base_uri', base_uri),
]
config = ConfigParser.SafeConfigParser()
if os.path.exists(config_file_path):
config.read(config_file_path)
else:
if not config.has_section('treestore'): config.add_section('treestore')
for key, value in defaults:
config.set('treestore', key, value)
with open(config_file_path, 'w') as output_file:
config.write(output_file)
# store config options in a dictionary
kwargs = {}
for k, v in config.items('treestore'):
kwargs[k] = v
if 'load_dir' in kwargs: load_dir = kwargs['load_dir']
if not os.path.exists(load_dir): os.makedirs(load_dir)
return kwargs