Unbreak db.connect(), whoops.
[zzz-pokedex.git] / pokedex / defaults.py
1 """ pokedex.defaults - logic for finding default paths """
2
3 import os
4 import pkg_resources
5
6 def get_default_db_uri_with_origin():
7 uri = os.environ.get('POKEDEX_DB_ENGINE', None)
8 origin = 'environment'
9
10 if uri is None:
11 sqlite_path = pkg_resources.resource_filename('pokedex',
12 'data/pokedex.sqlite')
13 uri = 'sqlite:///' + sqlite_path
14 origin = 'default'
15
16 return uri, origin
17
18 def get_default_index_dir_with_origin():
19 index_dir = os.environ.get('POKEDEX_INDEX_DIR', None)
20 origin = 'environment'
21
22 if index_dir is None:
23 index_dir = pkg_resources.resource_filename('pokedex',
24 'data/whoosh-index')
25 origin = 'default'
26
27 return index_dir, origin
28
29 def get_default_csv_dir_with_origin():
30 csv_dir = pkg_resources.resource_filename('pokedex', 'data/csv')
31 origin = 'default'
32
33 return csv_dir, origin
34
35
36 def get_default_db_uri():
37 return get_default_db_uri_with_origin()[0]
38
39 def get_default_index_dir():
40 return get_default_index_dir_with_origin()[0]
41
42 def get_default_csv_dir():
43 return get_default_csv_dir_with_origin()[0]
44
45