Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 18 additions & 32 deletions baph/core/preconfig/loader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import imp
import inspect
import os
from pkg_resources import get_distribution
import sys

from .config import Preconfiguration
Expand All @@ -11,33 +8,22 @@
PRECONFIG_MODULE_NAME = 'preconfig'
CONFIG_FOLDERS = ('', 'config', 'conf')

class PreconfigLoader(object):
cache = {}

def __init__(self):
raise Exception('PreconfigLoader is not initializable')

@classmethod
def load(cls, root=None):
if root is None and 'BAPH_APP' in os.environ:
app = os.environ['BAPH_APP']
dist = get_distribution(app)
root = os.path.join(dist.location, app)
'''
try:
_, root, _ = imp.find_module(app, sys.path)
except:
pass
'''

if root is None:
path = os.path.realpath(sys.argv[0])
root = os.path.dirname(path)

if root not in cls.cache:
profile = load_preconfig_profile(root)
if not profile:
return None
cls.cache[root] = Preconfiguration(root, profile)
return cls.cache[root]

class PreconfigLoader(object):
cache = {}

def __init__(self):
raise Exception('PreconfigLoader is not initializable')

@classmethod
def load(cls, root=None):
if root is None:
path = os.path.realpath(sys.argv[0])
root = os.path.dirname(path)

if root not in cls.cache:
profile = load_preconfig_profile(root)
if not profile:
return None
cls.cache[root] = Preconfiguration(root, profile)
return cls.cache[root]