mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
autopep8 --in-place -a -a -a --ignore E402,E501,E722 -r src/yunohost/*.py
This commit is contained in:
parent
485044335d
commit
05b1a8f96e
4 changed files with 42 additions and 44 deletions
|
@ -670,15 +670,15 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu
|
||||||
|
|
||||||
if confirm in ["danger", "thirdparty"]:
|
if confirm in ["danger", "thirdparty"]:
|
||||||
answer = msignals.prompt(m18n.n('confirm_app_install_' + confirm,
|
answer = msignals.prompt(m18n.n('confirm_app_install_' + confirm,
|
||||||
answers='Yes, I understand'),
|
answers='Yes, I understand'),
|
||||||
color="red")
|
color="red")
|
||||||
if answer != "Yes, I understand":
|
if answer != "Yes, I understand":
|
||||||
raise YunohostError("aborting")
|
raise YunohostError("aborting")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
answer = msignals.prompt(m18n.n('confirm_app_install_' + confirm,
|
answer = msignals.prompt(m18n.n('confirm_app_install_' + confirm,
|
||||||
answers='Y/N'),
|
answers='Y/N'),
|
||||||
color="yellow")
|
color="yellow")
|
||||||
if answer.upper() != "Y":
|
if answer.upper() != "Y":
|
||||||
raise YunohostError("aborting")
|
raise YunohostError("aborting")
|
||||||
|
|
||||||
|
@ -816,7 +816,7 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu
|
||||||
|
|
||||||
# Initialize the main permission for the app
|
# Initialize the main permission for the app
|
||||||
# After the install, if apps don't have a domain and path defined, the default url '/' is removed from the permission
|
# After the install, if apps don't have a domain and path defined, the default url '/' is removed from the permission
|
||||||
permission_create(app_instance_name+".main", allowed=["all_users"], label=label, show_tile=False, protected=False)
|
permission_create(app_instance_name + ".main", allowed=["all_users"], label=label, show_tile=False, protected=False)
|
||||||
|
|
||||||
# Execute the app install script
|
# Execute the app install script
|
||||||
install_failed = True
|
install_failed = True
|
||||||
|
@ -901,7 +901,7 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu
|
||||||
|
|
||||||
# Remove all permission in LDAP
|
# Remove all permission in LDAP
|
||||||
for permission_name in user_permission_list()["permissions"].keys():
|
for permission_name in user_permission_list()["permissions"].keys():
|
||||||
if permission_name.startswith(app_instance_name+"."):
|
if permission_name.startswith(app_instance_name + "."):
|
||||||
permission_delete(permission_name, force=True, sync_perm=False)
|
permission_delete(permission_name, force=True, sync_perm=False)
|
||||||
|
|
||||||
if remove_retcode != 0:
|
if remove_retcode != 0:
|
||||||
|
@ -1074,7 +1074,7 @@ def app_remove(operation_logger, app):
|
||||||
|
|
||||||
# Remove all permission in LDAP
|
# Remove all permission in LDAP
|
||||||
for permission_name in user_permission_list()["permissions"].keys():
|
for permission_name in user_permission_list()["permissions"].keys():
|
||||||
if permission_name.startswith(app+"."):
|
if permission_name.startswith(app + "."):
|
||||||
permission_delete(permission_name, force=True, sync_perm=False)
|
permission_delete(permission_name, force=True, sync_perm=False)
|
||||||
|
|
||||||
permission_sync_to_user()
|
permission_sync_to_user()
|
||||||
|
@ -1096,7 +1096,7 @@ def app_addaccess(apps, users=[]):
|
||||||
|
|
||||||
output = {}
|
output = {}
|
||||||
for app in apps:
|
for app in apps:
|
||||||
permission = user_permission_update(app+".main", add=users, remove="all_users")
|
permission = user_permission_update(app + ".main", add=users, remove="all_users")
|
||||||
output[app] = permission["corresponding_users"]
|
output[app] = permission["corresponding_users"]
|
||||||
|
|
||||||
return {'allowed_users': output}
|
return {'allowed_users': output}
|
||||||
|
@ -1117,7 +1117,7 @@ def app_removeaccess(apps, users=[]):
|
||||||
|
|
||||||
output = {}
|
output = {}
|
||||||
for app in apps:
|
for app in apps:
|
||||||
permission = user_permission_update(app+".main", remove=users)
|
permission = user_permission_update(app + ".main", remove=users)
|
||||||
output[app] = permission["corresponding_users"]
|
output[app] = permission["corresponding_users"]
|
||||||
|
|
||||||
return {'allowed_users': output}
|
return {'allowed_users': output}
|
||||||
|
@ -1137,7 +1137,7 @@ def app_clearaccess(apps):
|
||||||
|
|
||||||
output = {}
|
output = {}
|
||||||
for app in apps:
|
for app in apps:
|
||||||
permission = user_permission_reset(app+".main")
|
permission = user_permission_reset(app + ".main")
|
||||||
output[app] = permission["corresponding_users"]
|
output[app] = permission["corresponding_users"]
|
||||||
|
|
||||||
return {'allowed_users': output}
|
return {'allowed_users': output}
|
||||||
|
@ -1209,7 +1209,7 @@ def app_setting(app, key, value=None, delete=False):
|
||||||
# (unprotected, protected, skipped_uri/regex)
|
# (unprotected, protected, skipped_uri/regex)
|
||||||
#
|
#
|
||||||
|
|
||||||
is_legacy_permission_setting = any(key.startswith(word+"_") for word in ["unprotected", "protected", "skipped"])
|
is_legacy_permission_setting = any(key.startswith(word + "_") for word in ["unprotected", "protected", "skipped"])
|
||||||
|
|
||||||
if is_legacy_permission_setting:
|
if is_legacy_permission_setting:
|
||||||
|
|
||||||
|
@ -1286,7 +1286,6 @@ def app_setting(app, key, value=None, delete=False):
|
||||||
show_tile=False,
|
show_tile=False,
|
||||||
protected=True)
|
protected=True)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Regular setting management
|
# Regular setting management
|
||||||
#
|
#
|
||||||
|
@ -1356,16 +1355,16 @@ def app_ssowatconf():
|
||||||
"show_tile": False,
|
"show_tile": False,
|
||||||
"auth_header": False,
|
"auth_header": False,
|
||||||
"public": True,
|
"public": True,
|
||||||
"uris": \
|
"uris":
|
||||||
[domain + '/yunohost/admin' for domain in domains] + \
|
[domain + '/yunohost/admin' for domain in domains] +
|
||||||
[domain + '/yunohost/api' for domain in domains] + [
|
[domain + '/yunohost/api' for domain in domains] + [
|
||||||
"re:^[^/]*/%.well%-known/ynh%-diagnosis/.*$",
|
"re:^[^/]*/%.well%-known/ynh%-diagnosis/.*$",
|
||||||
"re:^[^/]*/%.well%-known/acme%-challenge/.*$",
|
"re:^[^/]*/%.well%-known/acme%-challenge/.*$",
|
||||||
"re:^[^/]*/%.well%-known/autoconfig/mail/config%-v1%.1%.xml.*$"
|
"re:^[^/]*/%.well%-known/autoconfig/mail/config%-v1%.1%.xml.*$"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
redirected_regex = {main_domain + '/yunohost[\/]?$': 'https://' + main_domain + '/yunohost/sso/'}
|
redirected_regex = {main_domain + r'/yunohost[\/]?$': 'https://' + main_domain + '/yunohost/sso/'}
|
||||||
redirected_urls = {}
|
redirected_urls = {}
|
||||||
|
|
||||||
for app in _installed_apps():
|
for app in _installed_apps():
|
||||||
|
@ -1825,7 +1824,7 @@ def _get_app_config_panel(app_id):
|
||||||
"panel": [],
|
"panel": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
panels = filter(lambda (key, value): key not in ("name", "version") and isinstance(value, OrderedDict),
|
panels = filter(lambda key_value: key_value[0] not in ("name", "version") and isinstance(key_value[1], OrderedDict),
|
||||||
toml_config_panel.items())
|
toml_config_panel.items())
|
||||||
|
|
||||||
for key, value in panels:
|
for key, value in panels:
|
||||||
|
@ -1835,7 +1834,7 @@ def _get_app_config_panel(app_id):
|
||||||
"sections": [],
|
"sections": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
sections = filter(lambda (k, v): k not in ("name",) and isinstance(v, OrderedDict),
|
sections = filter(lambda k_v1: k_v1[0] not in ("name",) and isinstance(k_v1[1], OrderedDict),
|
||||||
value.items())
|
value.items())
|
||||||
|
|
||||||
for section_key, section_value in sections:
|
for section_key, section_value in sections:
|
||||||
|
@ -1845,7 +1844,7 @@ def _get_app_config_panel(app_id):
|
||||||
"options": [],
|
"options": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
options = filter(lambda (k, v): k not in ("name",) and isinstance(v, OrderedDict),
|
options = filter(lambda k_v: k_v[0] not in ("name",) and isinstance(k_v[1], OrderedDict),
|
||||||
section_value.items())
|
section_value.items())
|
||||||
|
|
||||||
for option_key, option_value in options:
|
for option_key, option_value in options:
|
||||||
|
@ -1884,12 +1883,12 @@ def _get_app_settings(app_id):
|
||||||
settings = yaml.load(f)
|
settings = yaml.load(f)
|
||||||
# If label contains unicode char, this may later trigger issues when building strings...
|
# If label contains unicode char, this may later trigger issues when building strings...
|
||||||
# FIXME: this should be propagated to read_yaml so that this fix applies everywhere I think...
|
# FIXME: this should be propagated to read_yaml so that this fix applies everywhere I think...
|
||||||
settings = {k:_encode_string(v) for k,v in settings.items()}
|
settings = {k: _encode_string(v) for k, v in settings.items()}
|
||||||
if app_id == settings['id']:
|
if app_id == settings['id']:
|
||||||
return settings
|
return settings
|
||||||
except (IOError, TypeError, KeyError):
|
except (IOError, TypeError, KeyError):
|
||||||
logger.error(m18n.n('app_not_correctly_installed',
|
logger.error(m18n.n('app_not_correctly_installed',
|
||||||
app=app_id))
|
app=app_id))
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3095,7 +3094,7 @@ def _patch_legacy_helpers(app_folder):
|
||||||
},
|
},
|
||||||
# We can't migrate easily port-available
|
# We can't migrate easily port-available
|
||||||
# .. but at the time of writing this code, only two non-working apps are using it.
|
# .. but at the time of writing this code, only two non-working apps are using it.
|
||||||
"yunohost tools port-available": {"important":True},
|
"yunohost tools port-available": {"important": True},
|
||||||
# Replace
|
# Replace
|
||||||
# yunohost app checkurl "${domain}${path_url}" -a "${app}"
|
# yunohost app checkurl "${domain}${path_url}" -a "${app}"
|
||||||
# by
|
# by
|
||||||
|
@ -3151,7 +3150,7 @@ def _patch_legacy_helpers(app_folder):
|
||||||
if filename.split("/")[-1] in ["install", "remove", "upgrade", "backup", "restore"]:
|
if filename.split("/")[-1] in ["install", "remove", "upgrade", "backup", "restore"]:
|
||||||
source_helpers = "source /usr/share/yunohost/helpers"
|
source_helpers = "source /usr/share/yunohost/helpers"
|
||||||
if source_helpers not in content:
|
if source_helpers not in content:
|
||||||
content.replace("#!/bin/bash", "#!/bin/bash\n"+source_helpers)
|
content.replace("#!/bin/bash", "#!/bin/bash\n" + source_helpers)
|
||||||
if source_helpers not in content:
|
if source_helpers not in content:
|
||||||
content = source_helpers + "\n" + content
|
content = source_helpers + "\n" + content
|
||||||
|
|
||||||
|
@ -3160,4 +3159,4 @@ def _patch_legacy_helpers(app_folder):
|
||||||
|
|
||||||
if show_warning:
|
if show_warning:
|
||||||
# And complain about those damn deprecated helpers
|
# And complain about those damn deprecated helpers
|
||||||
logger.error("/!\ Packagers ! This app uses a very old deprecated helpers ... Yunohost automatically patched the helpers to use the new recommended practice, but please do consider fixing the upstream code right now ...")
|
logger.error(r"/!\ Packagers ! This app uses a very old deprecated helpers ... Yunohost automatically patched the helpers to use the new recommended practice, but please do consider fixing the upstream code right now ...")
|
||||||
|
|
|
@ -882,7 +882,6 @@ class RestoreManager():
|
||||||
logger.debug("executing the post-install...")
|
logger.debug("executing the post-install...")
|
||||||
tools_postinstall(domain, 'Yunohost', True)
|
tools_postinstall(domain, 'Yunohost', True)
|
||||||
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""
|
"""
|
||||||
End a restore operations by cleaning the working directory and
|
End a restore operations by cleaning the working directory and
|
||||||
|
@ -951,7 +950,7 @@ class RestoreManager():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
hook_paths = self.info['system'][system_part]['paths']
|
hook_paths = self.info['system'][system_part]['paths']
|
||||||
hook_paths = [ 'hooks/restore/%s' % os.path.basename(p) for p in hook_paths ]
|
hook_paths = ['hooks/restore/%s' % os.path.basename(p) for p in hook_paths]
|
||||||
|
|
||||||
# Otherwise, add it from the archive to the system
|
# Otherwise, add it from the archive to the system
|
||||||
# FIXME: Refactor hook_add and use it instead
|
# FIXME: Refactor hook_add and use it instead
|
||||||
|
@ -1200,7 +1199,7 @@ class RestoreManager():
|
||||||
# do the migration 0011 : setup group and permission
|
# do the migration 0011 : setup group and permission
|
||||||
#
|
#
|
||||||
# Legacy code
|
# Legacy code
|
||||||
if not "all_users" in user_group_list()["groups"].keys():
|
if "all_users" not in user_group_list()["groups"].keys():
|
||||||
from yunohost.utils.legacy import SetupGroupPermissions
|
from yunohost.utils.legacy import SetupGroupPermissions
|
||||||
# Update LDAP schema restart slapd
|
# Update LDAP schema restart slapd
|
||||||
logger.info(m18n.n("migration_0011_update_LDAP_schema"))
|
logger.info(m18n.n("migration_0011_update_LDAP_schema"))
|
||||||
|
@ -1225,7 +1224,6 @@ class RestoreManager():
|
||||||
|
|
||||||
permission_sync_to_user()
|
permission_sync_to_user()
|
||||||
|
|
||||||
|
|
||||||
def _restore_apps(self):
|
def _restore_apps(self):
|
||||||
"""Restore all apps targeted"""
|
"""Restore all apps targeted"""
|
||||||
|
|
||||||
|
@ -1423,7 +1421,7 @@ class RestoreManager():
|
||||||
|
|
||||||
# Remove all permission in LDAP for this app
|
# Remove all permission in LDAP for this app
|
||||||
for permission_name in user_permission_list()["permissions"].keys():
|
for permission_name in user_permission_list()["permissions"].keys():
|
||||||
if permission_name.startswith(app_instance_name+"."):
|
if permission_name.startswith(app_instance_name + "."):
|
||||||
permission_delete(permission_name, force=True)
|
permission_delete(permission_name, force=True)
|
||||||
|
|
||||||
# TODO Cleaning app hooks
|
# TODO Cleaning app hooks
|
||||||
|
@ -1518,7 +1516,7 @@ class BackupMethod(object):
|
||||||
|
|
||||||
Return a BackupMethod instance
|
Return a BackupMethod instance
|
||||||
"""
|
"""
|
||||||
known_methods = {c.method_name:c for c in BackupMethod.__subclasses__()}
|
known_methods = {c.method_name: c for c in BackupMethod.__subclasses__()}
|
||||||
backup_method = known_methods.get(method, CustomBackupMethod)
|
backup_method = known_methods.get(method, CustomBackupMethod)
|
||||||
return backup_method(manager, method=method, **kwargs)
|
return backup_method(manager, method=method, **kwargs)
|
||||||
|
|
||||||
|
@ -1780,14 +1778,14 @@ class CopyBackupMethod(BackupMethod):
|
||||||
|
|
||||||
filesystem.mkdir(self.work_dir, parent=True)
|
filesystem.mkdir(self.work_dir, parent=True)
|
||||||
ret = subprocess.call(["mount", "-r", "--rbind", self.repo,
|
ret = subprocess.call(["mount", "-r", "--rbind", self.repo,
|
||||||
self.work_dir])
|
self.work_dir])
|
||||||
if ret == 0:
|
if ret == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.warning("Could not mount the backup in readonly mode with --rbind ... Unmounting")
|
logger.warning("Could not mount the backup in readonly mode with --rbind ... Unmounting")
|
||||||
# FIXME : Does this stuff really works ? '&&' is going to be interpreted as an argument for mounpoint here ... Not as a classical '&&' ...
|
# FIXME : Does this stuff really works ? '&&' is going to be interpreted as an argument for mounpoint here ... Not as a classical '&&' ...
|
||||||
subprocess.call(["mountpoint", "-q", self.work_dir,
|
subprocess.call(["mountpoint", "-q", self.work_dir,
|
||||||
"&&", "umount", "-R", self.work_dir])
|
"&&", "umount", "-R", self.work_dir])
|
||||||
raise YunohostError('backup_cant_mount_uncompress_archive')
|
raise YunohostError('backup_cant_mount_uncompress_archive')
|
||||||
|
|
||||||
def copy(self, file, target):
|
def copy(self, file, target):
|
||||||
|
@ -1911,12 +1909,12 @@ class TarBackupMethod(BackupMethod):
|
||||||
system_part = system_part.replace("_", "/") + "/"
|
system_part = system_part.replace("_", "/") + "/"
|
||||||
subdir_and_files = [
|
subdir_and_files = [
|
||||||
tarinfo for tarinfo in tar.getmembers()
|
tarinfo for tarinfo in tar.getmembers()
|
||||||
if tarinfo.name.startswith(leading_dot+system_part)
|
if tarinfo.name.startswith(leading_dot + system_part)
|
||||||
]
|
]
|
||||||
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
||||||
subdir_and_files = [
|
subdir_and_files = [
|
||||||
tarinfo for tarinfo in tar.getmembers()
|
tarinfo for tarinfo in tar.getmembers()
|
||||||
if tarinfo.name.startswith(leading_dot+"hooks/restore/")
|
if tarinfo.name.startswith(leading_dot + "hooks/restore/")
|
||||||
]
|
]
|
||||||
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
||||||
|
|
||||||
|
@ -1924,7 +1922,7 @@ class TarBackupMethod(BackupMethod):
|
||||||
for app in apps_targets:
|
for app in apps_targets:
|
||||||
subdir_and_files = [
|
subdir_and_files = [
|
||||||
tarinfo for tarinfo in tar.getmembers()
|
tarinfo for tarinfo in tar.getmembers()
|
||||||
if tarinfo.name.startswith(leading_dot+"apps/" + app)
|
if tarinfo.name.startswith(leading_dot + "apps/" + app)
|
||||||
]
|
]
|
||||||
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
||||||
|
|
||||||
|
@ -2176,6 +2174,7 @@ def backup_list(with_info=False, human_readable=False):
|
||||||
archives = set([os.path.realpath(archive) for archive in archives])
|
archives = set([os.path.realpath(archive) for archive in archives])
|
||||||
archives = sorted(archives, key=lambda x: os.path.getctime(x))
|
archives = sorted(archives, key=lambda x: os.path.getctime(x))
|
||||||
# Extract only filename without the extension
|
# Extract only filename without the extension
|
||||||
|
|
||||||
def remove_extension(f):
|
def remove_extension(f):
|
||||||
if f.endswith(".tar.gz"):
|
if f.endswith(".tar.gz"):
|
||||||
return os.path.basename(f)[:-len(".tar.gz")]
|
return os.path.basename(f)[:-len(".tar.gz")]
|
||||||
|
@ -2192,7 +2191,7 @@ def backup_list(with_info=False, human_readable=False):
|
||||||
logger.warning(str(e))
|
logger.warning(str(e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
logger.warning("Could not check infos for archive %s: %s" % (archive, '\n'+traceback.format_exc()))
|
logger.warning("Could not check infos for archive %s: %s" % (archive, '\n' + traceback.format_exc()))
|
||||||
|
|
||||||
archives = d
|
archives = d
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ def domain_list(exclude_subdomains=False):
|
||||||
result_list = sorted(result_list, cmp_domain)
|
result_list = sorted(result_list, cmp_domain)
|
||||||
|
|
||||||
return {'domains': result_list}
|
return {'domains': result_list}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'domains': result_list,
|
'domains': result_list,
|
||||||
'main': _get_maindomain()
|
'main': _get_maindomain()
|
||||||
|
|
|
@ -140,8 +140,8 @@ def user_permission_update(operation_logger, permission, add=None, remove=None,
|
||||||
raise YunohostError('permission_require_account', permission=permission)
|
raise YunohostError('permission_require_account', permission=permission)
|
||||||
|
|
||||||
# Refuse to add "visitors" to protected permission
|
# Refuse to add "visitors" to protected permission
|
||||||
if ((add and "visitors" in add and existing_permission["protected"]) or \
|
if ((add and "visitors" in add and existing_permission["protected"]) or
|
||||||
(remove and "visitors" in remove and existing_permission["protected"])) and not force:
|
(remove and "visitors" in remove and existing_permission["protected"])) and not force:
|
||||||
raise YunohostError('permission_protected', permission=permission)
|
raise YunohostError('permission_protected', permission=permission)
|
||||||
|
|
||||||
# Fetch currently allowed groups for this permission
|
# Fetch currently allowed groups for this permission
|
||||||
|
@ -447,7 +447,7 @@ def permission_url(operation_logger, permission,
|
||||||
ldap.update('cn=%s,ou=permission' % permission, {'URL': [url] if url is not None else [],
|
ldap.update('cn=%s,ou=permission' % permission, {'URL': [url] if url is not None else [],
|
||||||
'additionalUrls': new_additional_urls,
|
'additionalUrls': new_additional_urls,
|
||||||
'authHeader': [str(auth_header).upper()],
|
'authHeader': [str(auth_header).upper()],
|
||||||
'showTile': [str(show_tile).upper()],})
|
'showTile': [str(show_tile).upper()], })
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise YunohostError('permission_update_failed', permission=permission, error=e)
|
raise YunohostError('permission_update_failed', permission=permission, error=e)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue