Skip to content
Snippets Groups Projects
Commit 4d3b7f37 authored by inso's avatar inso
Browse files

Select database as an option

parent 9ec4cb93
No related branches found
No related tags found
No related merge requests found
......@@ -90,7 +90,7 @@ class Application(QObject):
:return:
"""
self.parameters = UserParametersFile.in_config_path(self.options.config_path, profile_name).load_or_init()
self.db = SakiaDatabase.load_or_init(self.options.config_path, profile_name)
self.db = SakiaDatabase.load_or_init(self.options, profile_name)
self.instanciate_services()
......
......@@ -28,14 +28,13 @@ class SakiaDatabase:
sources_repo = attr.ib(default=None)
dividends_repo = attr.ib(default=None)
_logger = attr.ib(default=attr.Factory(lambda: logging.getLogger('sakia')))
db_file = 'sakia.db'
@classmethod
def load_or_init(cls, config_path, profile_name):
def load_or_init(cls, options, profile_name):
sqlite3.register_adapter(BlockUID, str)
sqlite3.register_adapter(bool, int)
sqlite3.register_converter("BOOLEAN", lambda v: bool(int(v)))
con = sqlite3.connect(os.path.join(config_path, profile_name, SakiaDatabase.db_file),
con = sqlite3.connect(os.path.join(options.config_path, profile_name, options.database + ".db"),
detect_types=sqlite3.PARSE_DECLTYPES)
meta = SakiaDatabase(con, ConnectionsRepo(con), IdentitiesRepo(con),
BlockchainsRepo(con), CertificationsRepo(con), TransactionsRepo(con),
......
......@@ -27,6 +27,7 @@ def config_path_factory():
@attr.s()
class SakiaOptions:
config_path = attr.ib(default=attr.Factory(config_path_factory))
database = attr.ib(default="sakia")
_logger = attr.ib(default=attr.Factory(lambda: logging.getLogger('sakia')))
@classmethod
......@@ -50,8 +51,14 @@ class SakiaOptions:
action="store_true", dest="debug", default=False,
help="Print DEBUG messages to stdout")
parser.add_option("--database", dest="database", default="sakia",
help="Select another database filename")
(options, args) = parser.parse_args(argv)
if options.database:
self.database = options.database
if options.debug:
self._logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(levelname)s:%(module)s:%(funcName)s:%(message)s')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment