-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
328 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,3 +105,4 @@ venv.bak/ | |
|
||
|
||
.idea/ | ||
data/database.db |
File renamed without changes.
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import configparser | ||
import logging | ||
import os | ||
from typing import * | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
CONFIG_PATH = os.path.join('data', 'config.ini') | ||
|
||
_config: Optional['AppConfig'] = None | ||
|
||
|
||
def init(): | ||
reload() | ||
|
||
|
||
def reload(): | ||
config = AppConfig() | ||
if config.load(CONFIG_PATH): | ||
global _config | ||
_config = config | ||
|
||
|
||
def get_config(): | ||
return _config | ||
|
||
|
||
class AppConfig: | ||
def __init__(self): | ||
self.database_url = 'sqlite:///data/database.db' | ||
|
||
def load(self, path): | ||
config = configparser.ConfigParser() | ||
config.read(path) | ||
try: | ||
app_section = config['app'] | ||
self.database_url = app_section['database_url'] | ||
except (KeyError, ValueError): | ||
logger.exception('Failed to load config:') | ||
return False | ||
return True |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[app] | ||
# See https://docs.sqlalchemy.org/en/13/core/engines.html#database-urls | ||
database_url = sqlite:///data/database.db | ||
|
||
|
||
# DON'T modify this section | ||
[DEFAULT] | ||
database_url = sqlite:///data/database.db |
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
Oops, something went wrong.