mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-08 19:32:15 +03:00
docs/plugintest: Example of forwards-compatible config functions
This commit is contained in:
parent
1b7f5e2b06
commit
e5bbf73acb
@ -11,7 +11,20 @@ import zipfile
|
|||||||
import semantic_version
|
import semantic_version
|
||||||
from SubA import SubA
|
from SubA import SubA
|
||||||
|
|
||||||
from config import appname, appversion
|
from config import appname, appversion, config
|
||||||
|
|
||||||
|
# For compatibility with pre-5.0.0
|
||||||
|
if not hasattr(config, 'get_int'):
|
||||||
|
config.get_int = config.getint
|
||||||
|
|
||||||
|
if not hasattr(config, 'get_str'):
|
||||||
|
config.get_str = config.get
|
||||||
|
|
||||||
|
if not hasattr(config, 'get_bool'):
|
||||||
|
config.get_bool = config.get
|
||||||
|
|
||||||
|
if not hasattr(config, 'get_list'):
|
||||||
|
config.get_list = config.get
|
||||||
|
|
||||||
# This could also be returned from plugin_start3()
|
# This could also be returned from plugin_start3()
|
||||||
plugin_name = os.path.basename(os.path.dirname(__file__))
|
plugin_name = os.path.basename(os.path.dirname(__file__))
|
||||||
@ -101,6 +114,22 @@ def plugin_start3(plugin_dir: str) -> str:
|
|||||||
# From 5.0.0-beta1 it's a function, returning semantic_version.Version
|
# From 5.0.0-beta1 it's a function, returning semantic_version.Version
|
||||||
core_version = appversion()
|
core_version = appversion()
|
||||||
|
|
||||||
|
config.set('plugintest_bool', True)
|
||||||
|
somebool = config.get_bool('plugintest_bool')
|
||||||
|
logger.debug(f'Stored bool: {somebool=}')
|
||||||
|
|
||||||
|
config.set('plugintest_str', 'Test String')
|
||||||
|
somestr = config.get_str('plugintest_str')
|
||||||
|
logger.debug(f'Stored str: {somestr=}')
|
||||||
|
|
||||||
|
config.set('plugintest_int', 42)
|
||||||
|
someint = config.get_int('plugintest_int')
|
||||||
|
logger.debug(f'Stored int: {someint=}')
|
||||||
|
|
||||||
|
config.set('plugintest_list', ['test', 'one', 'two'])
|
||||||
|
somelist = config.get_list('plugintest_list')
|
||||||
|
logger.debug(f'Stored list: {somelist=}')
|
||||||
|
|
||||||
logger.info(f'Core EDMC version: {core_version}')
|
logger.info(f'Core EDMC version: {core_version}')
|
||||||
# And then compare like this
|
# And then compare like this
|
||||||
if core_version < semantic_version.Version('5.0.0-beta1'):
|
if core_version < semantic_version.Version('5.0.0-beta1'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user