mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Use a common function to retrieve app settings
This commit is contained in:
parent
ed49a8f577
commit
da2b3691c7
2 changed files with 31 additions and 23 deletions
|
@ -17,6 +17,7 @@
|
||||||
"app_unknown" : "Unknown app",
|
"app_unknown" : "Unknown app",
|
||||||
"app_no_upgrade" : "No app to upgrade",
|
"app_no_upgrade" : "No app to upgrade",
|
||||||
"app_not_installed" : "{:s} is not installed",
|
"app_not_installed" : "{:s} is not installed",
|
||||||
|
"app_not_correctly_installed" : "{app:s} seems to be not correctly installed",
|
||||||
"custom_app_url_required" : "You must provide an URL to upgrade your custom app {:s}",
|
"custom_app_url_required" : "You must provide an URL to upgrade your custom app {:s}",
|
||||||
"app_recent_version_required" : "{:s} requires a more recent version of the moulinette",
|
"app_recent_version_required" : "{:s} requires a more recent version of the moulinette",
|
||||||
"app_upgraded" : "{:s} successfully upgraded",
|
"app_upgraded" : "{:s} successfully upgraded",
|
||||||
|
|
|
@ -218,8 +218,7 @@ def app_info(app, show_status=False, raw=False):
|
||||||
m18n.n('app_not_installed', app))
|
m18n.n('app_not_installed', app))
|
||||||
if raw:
|
if raw:
|
||||||
ret = app_list(filter=app, raw=True)[app]
|
ret = app_list(filter=app, raw=True)[app]
|
||||||
with open(apps_setting_path + app +'/settings.yml') as f:
|
ret['settings'] = _get_app_settings(app)
|
||||||
ret['settings'] = yaml.load(f)
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
app_setting_path = apps_setting_path + app
|
app_setting_path = apps_setting_path + app
|
||||||
|
@ -265,9 +264,8 @@ def app_map(app=None, raw=False, user=None):
|
||||||
apps = os.listdir(apps_setting_path)
|
apps = os.listdir(apps_setting_path)
|
||||||
|
|
||||||
for app_id in apps:
|
for app_id in apps:
|
||||||
with open(apps_setting_path + app_id +'/settings.yml') as f:
|
app_settings = _get_app_settings(app_id)
|
||||||
app_settings = yaml.load(f)
|
if not app_settings:
|
||||||
if not isinstance(app_settings, dict):
|
|
||||||
continue
|
continue
|
||||||
if 'domain' not in app_settings:
|
if 'domain' not in app_settings:
|
||||||
continue
|
continue
|
||||||
|
@ -734,12 +732,7 @@ def app_makedefault(auth, app, domain=None):
|
||||||
"""
|
"""
|
||||||
from yunohost.domain import domain_list
|
from yunohost.domain import domain_list
|
||||||
|
|
||||||
if not _is_installed(app):
|
app_settings = _get_app_settings(app)
|
||||||
raise MoulinetteError(errno.EINVAL, m18n.n('app_not_installed', app))
|
|
||||||
|
|
||||||
with open(apps_setting_path + app +'/settings.yml') as f:
|
|
||||||
app_settings = yaml.load(f)
|
|
||||||
|
|
||||||
app_domain = app_settings['domain']
|
app_domain = app_settings['domain']
|
||||||
app_path = app_settings['path']
|
app_path = app_settings['path']
|
||||||
|
|
||||||
|
@ -782,17 +775,7 @@ def app_setting(app, key, value=None, delete=False):
|
||||||
delete -- Delete the key
|
delete -- Delete the key
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not _is_installed(app):
|
app_settings = _get_app_settings(app)
|
||||||
raise MoulinetteError(errno.EINVAL,
|
|
||||||
m18n.n('app_not_installed', app))
|
|
||||||
|
|
||||||
settings_file = apps_setting_path + app +'/settings.yml'
|
|
||||||
try:
|
|
||||||
with open(settings_file) as f:
|
|
||||||
app_settings = yaml.load(f)
|
|
||||||
except IOError:
|
|
||||||
# Do not fail if setting file is not there
|
|
||||||
app_settings = {}
|
|
||||||
|
|
||||||
if value is None and not delete:
|
if value is None and not delete:
|
||||||
try:
|
try:
|
||||||
|
@ -812,7 +795,8 @@ def app_setting(app, key, value=None, delete=False):
|
||||||
value=yaml.load(value)
|
value=yaml.load(value)
|
||||||
app_settings[key] = value
|
app_settings[key] = value
|
||||||
|
|
||||||
with open(settings_file, 'w') as f:
|
with open(os.path.join(
|
||||||
|
apps_setting_path, app, 'settings.yml'), 'w') as f:
|
||||||
yaml.safe_dump(app_settings, f, default_flow_style=False)
|
yaml.safe_dump(app_settings, f, default_flow_style=False)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1012,6 +996,29 @@ def app_ssowatconf(auth):
|
||||||
msignals.display(m18n.n('ssowat_conf_generated'), 'success')
|
msignals.display(m18n.n('ssowat_conf_generated'), 'success')
|
||||||
|
|
||||||
|
|
||||||
|
def _get_app_settings(app_id):
|
||||||
|
"""
|
||||||
|
Get settings of an installed app
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
app_id -- The app id
|
||||||
|
|
||||||
|
"""
|
||||||
|
if not _is_installed(app_id):
|
||||||
|
raise MoulinetteError(errno.EINVAL,
|
||||||
|
m18n.n('app_not_installed', app_id))
|
||||||
|
try:
|
||||||
|
with open(os.path.join(
|
||||||
|
apps_setting_path, app_id, 'settings.yml')) as f:
|
||||||
|
settings = yaml.load(f)
|
||||||
|
if app_id == settings['id']:
|
||||||
|
return settings
|
||||||
|
except (IOError, KeyError):
|
||||||
|
logger.exception(m18n.n('app_not_correctly_installed',
|
||||||
|
app=app_id))
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def _get_app_status(app_id, format_date=False):
|
def _get_app_status(app_id, format_date=False):
|
||||||
"""
|
"""
|
||||||
Get app status or create it if needed
|
Get app status or create it if needed
|
||||||
|
|
Loading…
Add table
Reference in a new issue