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
9 changed files
with
86 additions
and
0 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 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
Empty file.
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,20 @@ | ||
|
||
from qtoggleserver.conf import settings | ||
from qtoggleserver.core import api as core_api | ||
from qtoggleserver.core.typing import GenericJSONDict | ||
from qtoggleserver.system import conf as system_conf | ||
from qtoggleserver.utils import conf as conf_utils | ||
|
||
|
||
@core_api.api_call(core_api.ACCESS_LEVEL_ADMIN) | ||
async def get_system(request: core_api.APIRequest) -> GenericJSONDict: | ||
return conf_utils.config_from_file(settings.source) | ||
|
||
|
||
@core_api.api_call(core_api.ACCESS_LEVEL_ADMIN) | ||
async def put_system(request: core_api.APIRequest, params: GenericJSONDict) -> None: | ||
# Update in-memory settings (no effect guaranteed without a restart, though) | ||
conf_utils.update_obj_from_dict(settings, params) | ||
|
||
# Update config file | ||
system_conf.conf_file_from_dict(params) |
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,38 @@ | ||
|
||
from typing import Any, Dict | ||
|
||
import logging | ||
import os | ||
|
||
from qtoggleserver.conf import settings | ||
from qtoggleserver.utils import conf as conf_utils | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def can_write_conf_file() -> bool: | ||
if not settings.source: | ||
return False | ||
|
||
return os.access(settings.source, os.W_OK) | ||
|
||
|
||
def conf_file_to_dict() -> Dict[str, Any]: | ||
if not can_write_conf_file(): | ||
raise Exception('Configuration file not available') | ||
|
||
return conf_utils.config_from_file(settings.source) | ||
|
||
|
||
def conf_file_from_dict(d: Dict[str, Any]) -> None: | ||
if not can_write_conf_file(): | ||
raise Exception('Configuration file not available') | ||
|
||
logger.debug('updating configuration file %s', settings.source) | ||
|
||
config = conf_utils.config_from_dict(d) | ||
config_str = conf_utils.config_to_str(config) | ||
|
||
with open(settings.source, 'wt') as f: | ||
f.write(config_str) |
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