Removes the need to pass around the app object

The Database and SearchParser classes didn't really need the app object.
They just needed to use some of its properties. Instead those properties
are just being passed in.

Change-Id: Iabdd0072a8f74e6b9346fe03c15cfa00810e1c4a
This commit is contained in:
David Stanek 2015-04-08 14:46:39 -04:00
parent 0b16cbb8c4
commit 5ecfdd506d
3 changed files with 12 additions and 11 deletions

View File

@ -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 = []

View File

@ -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()

View File

@ -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