mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Factor out logic for finding the default db/index. #180
Note: `if not x:` has changed to `if x is not None:`, changing the semantics slightly. Shouldn't be a big issue.
This commit is contained in:
parent
5e52bef91a
commit
ffc30bff8f
5 changed files with 74 additions and 58 deletions
pokedex
45
pokedex/defaults.py
Normal file
45
pokedex/defaults.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
""" pokedex.defaults - logic for finding default paths """
|
||||
|
||||
import os
|
||||
import pkg_resources
|
||||
|
||||
def get_default_db_uri_with_origin():
|
||||
uri = os.environ.get('POKEDEX_DB_ENGINE', None)
|
||||
origin = 'environment'
|
||||
|
||||
if uri is None:
|
||||
sqlite_path = pkg_resources.resource_filename('pokedex',
|
||||
'data/pokedex.sqlite')
|
||||
uri = 'sqlite:///' + sqlite_path
|
||||
origin = 'default'
|
||||
|
||||
return uri, origin
|
||||
|
||||
def get_default_index_dir_with_origin():
|
||||
index_dir = os.environ.get('POKEDEX_INDEX_DIR', None)
|
||||
origin = 'environment'
|
||||
|
||||
if index_dir is None:
|
||||
index_dir = pkg_resources.resource_filename('pokedex',
|
||||
'data/whoosh-index')
|
||||
origin = 'default'
|
||||
|
||||
return index_dir, origin
|
||||
|
||||
def get_default_csv_dir_with_origin():
|
||||
csv_dir = pkg_resources.resource_filename('pokedex', 'data/csv')
|
||||
origin = 'default'
|
||||
|
||||
return csv_dir, origin
|
||||
|
||||
|
||||
def get_default_db_uri():
|
||||
return get_default_db_uri_with_origin()[0]
|
||||
|
||||
def get_default_index_dir():
|
||||
return get_default_index_dir_with_origin()[0]
|
||||
|
||||
def get_default_csv_dir():
|
||||
return get_default_csv_dir_with_origin()[0]
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue