Make plumbing respect the same env vars as the CLI. #180

This commit is contained in:
Eevee 2010-05-12 23:23:05 -07:00
parent 1c230f5990
commit 5e52bef91a
3 changed files with 14 additions and 1 deletions

View file

@ -46,6 +46,9 @@ def get_session(options):
session.
"""
# WARNING: This logic duplicates that in db.connect(), because there's no
# other reliable way to tell where the engine actually came from. Keep it
# up to date!
engine_uri = options.engine_uri
got_from = None
if engine_uri:
@ -70,6 +73,9 @@ def get_lookup(options, session=None, recreate=False):
PokedexLookup object.
"""
# WARNING: This logic duplicates that in PokedexLookup, because there's no
# other reliable way to tell where the engine actually came from. Keep it
# up to date!
if recreate and not session:
raise ValueError("get_lookup() needs an explicit session to regen the index")

View file

@ -1,3 +1,4 @@
import os
import pkg_resources
from sqlalchemy import MetaData, Table, create_engine, orm
@ -13,7 +14,10 @@ def connect(uri=None, session_args={}, engine_args={}):
Calling this function also binds the metadata object to the created engine.
"""
# Default to a URI within the package, which was hopefully created at some point
# Fall back to the environment, then a URI within the package
if not uri:
uri = os.environ.get('POKEDEX_DB_ENGINE', None)
if not uri:
sqlite_path = pkg_resources.resource_filename('pokedex',
'data/pokedex.sqlite')

View file

@ -103,6 +103,9 @@ class PokedexLookup(object):
# must be set
# Defaults
if not directory:
directory = os.environ.get('POKEDEX_INDEX_DIR', None)
if not directory:
directory = pkg_resources.resource_filename('pokedex',
'data/whoosh-index')