mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Rely only on app_id argument for multi-instances apps
The original app_id hard-coded replacement in scripts and hooks is replaced by the use in app scripts directly of the given app_id argument (wip #126). It's now the app maintainer responsability to make use of it in a way to prevent colisions with other instances.
This commit is contained in:
parent
f0d0499257
commit
5fd2cf6667
1 changed files with 3 additions and 51 deletions
|
@ -320,13 +320,8 @@ def app_upgrade(auth, app=[], url=None, file=None):
|
||||||
if app_id in upgraded_apps:
|
if app_id in upgraded_apps:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if '__' in app_id:
|
|
||||||
original_app_id = app_id[:app_id.index('__')]
|
|
||||||
else:
|
|
||||||
original_app_id = app_id
|
|
||||||
|
|
||||||
current_app_dict = app_info(app_id, raw=True)
|
current_app_dict = app_info(app_id, raw=True)
|
||||||
new_app_dict = app_info(original_app_id, raw=True)
|
new_app_dict = app_info(app_id, raw=True)
|
||||||
|
|
||||||
if file:
|
if file:
|
||||||
manifest = _extract_app_from_file(file)
|
manifest = _extract_app_from_file(file)
|
||||||
|
@ -356,27 +351,6 @@ def app_upgrade(auth, app=[], url=None, file=None):
|
||||||
status = _get_app_status(app_id)
|
status = _get_app_status(app_id)
|
||||||
status['remote'] = manifest.get('remote', None)
|
status['remote'] = manifest.get('remote', None)
|
||||||
|
|
||||||
if original_app_id != app_id:
|
|
||||||
# Replace original_app_id with the forked one in scripts
|
|
||||||
for script in os.listdir(app_tmp_folder +'/scripts'):
|
|
||||||
#TODO: do it with sed ?
|
|
||||||
if script[:1] != '.':
|
|
||||||
with open(app_tmp_folder +'/scripts/'+ script, "r") as sources:
|
|
||||||
lines = sources.readlines()
|
|
||||||
with open(app_tmp_folder +'/scripts/'+ script, "w") as sources:
|
|
||||||
for line in lines:
|
|
||||||
sources.write(re.sub(r''+ original_app_id +'', app_id, line))
|
|
||||||
|
|
||||||
if 'hooks' in os.listdir(app_tmp_folder):
|
|
||||||
for hook in os.listdir(app_tmp_folder +'/hooks'):
|
|
||||||
#TODO: do it with sed ?
|
|
||||||
if hook[:1] != '.':
|
|
||||||
with open(app_tmp_folder +'/hooks/'+ hook, "r") as sources:
|
|
||||||
lines = sources.readlines()
|
|
||||||
with open(app_tmp_folder +'/hooks/'+ hook, "w") as sources:
|
|
||||||
for line in lines:
|
|
||||||
sources.write(re.sub(r''+ original_app_id +'', app_id, line))
|
|
||||||
|
|
||||||
# Clean hooks and add new ones
|
# Clean hooks and add new ones
|
||||||
hook_remove(app_id)
|
hook_remove(app_id)
|
||||||
if 'hooks' in os.listdir(app_tmp_folder):
|
if 'hooks' in os.listdir(app_tmp_folder):
|
||||||
|
@ -467,30 +441,8 @@ def app_install(auth, app, label=None, args=None):
|
||||||
raise MoulinetteError(errno.EEXIST,
|
raise MoulinetteError(errno.EEXIST,
|
||||||
m18n.n('app_already_installed', app_id))
|
m18n.n('app_already_installed', app_id))
|
||||||
|
|
||||||
app_id_forked = app_id + '__' + str(instance_number)
|
# Change app_id to the forked app id
|
||||||
|
app_id = app_id + '__' + str(instance_number)
|
||||||
# Replace app_id with the new one in scripts
|
|
||||||
for script in os.listdir(app_tmp_folder +'/scripts'):
|
|
||||||
#TODO: do it with sed ?
|
|
||||||
if script[:1] != '.':
|
|
||||||
with open(app_tmp_folder +'/scripts/'+ script, "r") as sources:
|
|
||||||
lines = sources.readlines()
|
|
||||||
with open(app_tmp_folder +'/scripts/'+ script, "w") as sources:
|
|
||||||
for line in lines:
|
|
||||||
sources.write(re.sub(r''+ app_id +'', app_id_forked, line))
|
|
||||||
|
|
||||||
if 'hooks' in os.listdir(app_tmp_folder):
|
|
||||||
for hook in os.listdir(app_tmp_folder +'/hooks'):
|
|
||||||
#TODO: do it with sed ?
|
|
||||||
if hook[:1] != '.':
|
|
||||||
with open(app_tmp_folder +'/hooks/'+ hook, "r") as sources:
|
|
||||||
lines = sources.readlines()
|
|
||||||
with open(app_tmp_folder +'/hooks/'+ hook, "w") as sources:
|
|
||||||
for line in lines:
|
|
||||||
sources.write(re.sub(r''+ app_id +'', app_id_forked, line))
|
|
||||||
|
|
||||||
# Change app_id for the rest of the process
|
|
||||||
app_id = app_id_forked
|
|
||||||
|
|
||||||
# Prepare App settings
|
# Prepare App settings
|
||||||
app_setting_path = apps_setting_path +'/'+ app_id
|
app_setting_path = apps_setting_path +'/'+ app_id
|
||||||
|
|
Loading…
Add table
Reference in a new issue