This repository has been archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to baseplate configuration parsing
- Loading branch information
Showing
6 changed files
with
47 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,23 @@ | ||
from baseplate import config | ||
from sqlalchemy.engine import url | ||
from twisted.enterprise.adbapi import ConnectionPool | ||
|
||
from harold.conf import PluginConfig, Option | ||
from harold.plugin import Plugin | ||
|
||
|
||
class DatabaseConfig(PluginConfig): | ||
connection_string = Option(str) | ||
|
||
def get_module_and_params(self): | ||
"""Parse the SQLAlchemy connection string and return DBAPI info.""" | ||
sa_url = url.make_url(self.connection_string) | ||
dialect_cls = sa_url.get_dialect() | ||
return dialect_cls.dbapi(), sa_url.translate_connect_args() | ||
|
||
|
||
class DatabasePlugin(ConnectionPool, Plugin): | ||
"""A plugin that provides a simple twisted ADBAPI interface to a DB.""" | ||
|
||
def __init__(self, db_config): | ||
Plugin.__init__(self) | ||
self.module, kwargs = db_config.get_module_and_params() | ||
|
||
self.module = db_config.connection_string.get_dialect().dbapi() | ||
kwargs = db_config.connection_string.translate_connect_args() | ||
ConnectionPool.__init__(self, self.module.__name__, **kwargs) | ||
|
||
|
||
def make_plugin(config): | ||
db_config = DatabaseConfig(config) | ||
def make_plugin(app_config): | ||
db_config = config.parse_config(app_config, { | ||
"connection_string": url.make_url, | ||
}) | ||
return DatabasePlugin(db_config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters