Merge "Removes the need to pass around the app object"
This commit is contained in:
commit
4d395320ff
gertty
@ -210,8 +210,8 @@ class App(object):
|
||||
|
||||
self.fetch_missing_refs = fetch_missing_refs
|
||||
self.config.keymap.updateCommandMap()
|
||||
self.search = search.SearchCompiler(self)
|
||||
self.db = db.Database(self)
|
||||
self.search = search.SearchCompiler(self.config.username)
|
||||
self.db = db.Database(self, self.config.dburi, self.search)
|
||||
self.sync = sync.Sync(self)
|
||||
|
||||
self.screens = []
|
||||
|
11
gertty/db.py
11
gertty/db.py
@ -595,10 +595,11 @@ def add_sqlite_match(dbapi_connection, connection_record):
|
||||
dbapi_connection.create_function("matches", 2, match)
|
||||
|
||||
class Database(object):
|
||||
def __init__(self, app):
|
||||
def __init__(self, app, dburi, search):
|
||||
self.log = logging.getLogger('gertty.db')
|
||||
self.app = app
|
||||
self.engine = create_engine(self.app.config.dburi)
|
||||
self.dburi = dburi
|
||||
self.search = search
|
||||
self.engine = create_engine(self.dburi)
|
||||
#metadata.create_all(self.engine)
|
||||
self.migrate(app)
|
||||
# If we want the objects returned from query() to be usable
|
||||
@ -625,7 +626,7 @@ class Database(object):
|
||||
|
||||
config = alembic.config.Config()
|
||||
config.set_main_option("script_location", "gertty:alembic")
|
||||
config.set_main_option("sqlalchemy.url", self.app.config.dburi)
|
||||
config.set_main_option("sqlalchemy.url", self.dburi)
|
||||
config.gertty_app = app
|
||||
|
||||
if current_rev is None and has_table:
|
||||
@ -637,7 +638,7 @@ class DatabaseSession(object):
|
||||
def __init__(self, database):
|
||||
self.database = database
|
||||
self.session = database.session
|
||||
self.search = database.app.search
|
||||
self.search = database.search
|
||||
|
||||
def __enter__(self):
|
||||
self.database.lock.acquire()
|
||||
|
@ -24,8 +24,8 @@ class SearchSyntaxError(Exception):
|
||||
|
||||
|
||||
class SearchCompiler(object):
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
def __init__(self, username):
|
||||
self.username = username
|
||||
self.lexer = tokenizer.SearchTokenizer()
|
||||
self.parser = parser.SearchParser()
|
||||
|
||||
@ -44,7 +44,7 @@ class SearchCompiler(object):
|
||||
return tables
|
||||
|
||||
def parse(self, data):
|
||||
self.parser.username = self.app.config.username
|
||||
self.parser.username = self.username
|
||||
result = self.parser.parse(data, lexer=self.lexer)
|
||||
tables = self.findTables(result)
|
||||
if gertty.db.project_table in tables:
|
||||
@ -79,6 +79,6 @@ if __name__ == '__main__':
|
||||
app = Dummy()
|
||||
app.config = Dummy()
|
||||
app.config.username = 'bob'
|
||||
search = SearchCompiler(app)
|
||||
search = SearchCompiler(app.config.username)
|
||||
x = search.parse(query)
|
||||
print x
|
||||
|
Loading…
x
Reference in New Issue
Block a user