diff --git a/src/yunohost/app.py b/src/yunohost/app.py index d32fb59a2..05580fbe1 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -30,10 +30,10 @@ import shutil import yaml import time import re -import urlparse +import urllib.parse import subprocess import glob -import urllib +import urllib.request, urllib.parse, urllib.error from collections import OrderedDict from moulinette import msignals, m18n, msettings @@ -736,7 +736,7 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu # Retrieve arguments list for install script args_dict = {} if not args else \ - dict(urlparse.parse_qsl(args, keep_blank_values=True)) + dict(urllib.parse.parse_qsl(args, keep_blank_values=True)) args_odict = _parse_args_from_manifest(manifest, 'install', args=args_dict) # Validate domain / path availability for webapps @@ -759,7 +759,7 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu # Also redact the % escaped version of the password that might appear in # the 'args' section of metadata (relevant for password with non-alphanumeric char) data_to_redact = [value[0] for value in args_odict.values() if value[1] == "password"] - data_to_redact += [urllib.quote(data) for data in data_to_redact if urllib.quote(data) != data] + data_to_redact += [urllib.parse.quote(data) for data in data_to_redact if urllib.parse.quote(data) != data] operation_logger.data_to_redact.extend(data_to_redact) operation_logger.related_to = [s for s in operation_logger.related_to if s[0] != "app"] @@ -1406,7 +1406,7 @@ def app_ssowatconf(): write_to_json('/etc/ssowat/conf.json', conf_dict, sort_keys=True, indent=4) - from utils.legacy import translate_legacy_rules_in_ssowant_conf_json_persistent + from .utils.legacy import translate_legacy_rules_in_ssowant_conf_json_persistent translate_legacy_rules_in_ssowant_conf_json_persistent() logger.debug(m18n.n('ssowat_conf_generated')) @@ -1456,7 +1456,7 @@ def app_action_run(operation_logger, app, action, args=None): action_declaration = actions[action] # Retrieve arguments list for install script - args_dict = dict(urlparse.parse_qsl(args, keep_blank_values=True)) if args else {} + args_dict = dict(urllib.parse.parse_qsl(args, keep_blank_values=True)) if args else {} args_odict = _parse_args_for_action(actions[action], args=args_dict) args_list = [value[0] for value in args_odict.values()] @@ -1598,7 +1598,7 @@ def app_config_apply(operation_logger, app, args): "YNH_APP_INSTANCE_NAME": app, "YNH_APP_INSTANCE_NUMBER": str(app_instance_nb), } - args = dict(urlparse.parse_qsl(args, keep_blank_values=True)) if args else {} + args = dict(urllib.parse.parse_qsl(args, keep_blank_values=True)) if args else {} for tab in config_panel.get("panel", []): tab_id = tab["id"] # this makes things easier to debug on crash @@ -1817,8 +1817,7 @@ def _get_app_config_panel(app_id): "panel": [], } - panels = filter(lambda key_value: key_value[0] not in ("name", "version") and isinstance(key_value[1], OrderedDict), - toml_config_panel.items()) + panels = [key_value for key_value in toml_config_panel.items() if key_value[0] not in ("name", "version") and isinstance(key_value[1], OrderedDict)] for key, value in panels: panel = { @@ -1827,8 +1826,7 @@ def _get_app_config_panel(app_id): "sections": [], } - sections = filter(lambda k_v1: k_v1[0] not in ("name",) and isinstance(k_v1[1], OrderedDict), - value.items()) + sections = [k_v1 for k_v1 in value.items() if k_v1[0] not in ("name",) and isinstance(k_v1[1], OrderedDict)] for section_key, section_value in sections: section = { @@ -1837,8 +1835,7 @@ def _get_app_config_panel(app_id): "options": [], } - options = filter(lambda k_v: k_v[0] not in ("name",) and isinstance(k_v[1], OrderedDict), - section_value.items()) + options = [k_v for k_v in section_value.items() if k_v[0] not in ("name",) and isinstance(k_v[1], OrderedDict)] for option_key, option_value in options: option = dict(option_value) @@ -2315,7 +2312,7 @@ def _encode_string(value): """ Return the string encoded in utf-8 if needed """ - if isinstance(value, unicode): + if isinstance(value, str): return value.encode('utf8') return value @@ -2926,7 +2923,7 @@ def _load_apps_catalog(): try: apps_catalog_content = read_json(cache_file) if os.path.exists(cache_file) else None except Exception as e: - raise ("Unable to read cache for apps_catalog %s : %s" % (apps_catalog_id, str(e))) + raise "Unable to read cache for apps_catalog %s : %s" # Check that the version of the data matches version .... # ... otherwise it means we updated yunohost in the meantime @@ -2976,7 +2973,7 @@ def is_true(arg): """ if isinstance(arg, bool): return arg - elif isinstance(arg, basestring): + elif isinstance(arg, str): return arg.lower() in ['yes', 'true', 'on'] else: logger.debug('arg should be a boolean or a string, got %r', arg) diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index c0f11eae8..7c75837b0 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -882,7 +882,7 @@ class RestoreManager(): End a restore operations by cleaning the working directory and regenerate ssowat conf (if some apps were restored) """ - from permission import permission_sync_to_user + from .permission import permission_sync_to_user permission_sync_to_user() diff --git a/src/yunohost/certificate.py b/src/yunohost/certificate.py index c9451c2be..fc81ae0a6 100644 --- a/src/yunohost/certificate.py +++ b/src/yunohost/certificate.py @@ -385,7 +385,7 @@ def certificate_renew(domain_list, force=False, no_checks=False, email=False, st _fetch_and_enable_new_certificate(domain, staging, no_checks=no_checks) except Exception as e: import traceback - from StringIO import StringIO + from io import StringIO stack = StringIO() traceback.print_exc(file=stack) msg = "Certificate renewing for %s failed !" % (domain) diff --git a/src/yunohost/dyndns.py b/src/yunohost/dyndns.py index fe2a1bc9b..e43c180ad 100644 --- a/src/yunohost/dyndns.py +++ b/src/yunohost/dyndns.py @@ -105,7 +105,7 @@ def _dyndns_available(provider, domain): raise YunohostError('dyndns_could_not_check_available', domain=domain, provider=provider) - return r == u"Domain %s is available" % domain + return r == "Domain %s is available" % domain @is_unit_operation() diff --git a/src/yunohost/log.py b/src/yunohost/log.py index cf108b989..a21ddd606 100644 --- a/src/yunohost/log.py +++ b/src/yunohost/log.py @@ -65,8 +65,7 @@ def log_list(limit=None, with_details=False, with_suboperations=False): operations = {} - logs = filter(lambda x: x.endswith(METADATA_FILE_EXT), - os.listdir(OPERATIONS_PATH)) + logs = [x for x in os.listdir(OPERATIONS_PATH) if x.endswith(METADATA_FILE_EXT)] logs = list(reversed(sorted(logs))) if limit is not None: @@ -337,7 +336,7 @@ def is_unit_operation(entities=['app', 'domain', 'group', 'service', 'user'], entity_type = entity if entity in kwargs and kwargs[entity] is not None: - if isinstance(kwargs[entity], basestring): + if isinstance(kwargs[entity], str): related_to.append((entity_type, kwargs[entity])) else: for x in kwargs[entity]: @@ -596,7 +595,7 @@ class OperationLogger(object): """ if self.ended_at is not None or self.started_at is None: return - if error is not None and not isinstance(error, basestring): + if error is not None and not isinstance(error, str): error = str(error) self.ended_at = datetime.utcnow() self._error = error diff --git a/src/yunohost/settings.py b/src/yunohost/settings.py index 3c79d7945..060aca6e4 100644 --- a/src/yunohost/settings.py +++ b/src/yunohost/settings.py @@ -29,7 +29,7 @@ def is_boolean(value): """ if isinstance(value, bool): return True, value - elif isinstance(value, basestring): + elif isinstance(value, str): if str(value).lower() in ['true', 'on', 'yes', 'false', 'off', 'no']: return True, str(value).lower() in ['true', 'on', 'yes'] else: @@ -141,7 +141,7 @@ def settings_set(key, value): raise YunohostError('global_settings_bad_type_for_setting', setting=key, received_type=type(value).__name__, expected_type=key_type) elif key_type == "string": - if not isinstance(value, basestring): + if not isinstance(value, str): raise YunohostError('global_settings_bad_type_for_setting', setting=key, received_type=type(value).__name__, expected_type=key_type) elif key_type == "enum": diff --git a/src/yunohost/tests/test_apps.py b/src/yunohost/tests/test_apps.py index 0f4c3749a..baa3d5181 100644 --- a/src/yunohost/tests/test_apps.py +++ b/src/yunohost/tests/test_apps.py @@ -4,7 +4,7 @@ import pytest import shutil import requests -from conftest import message, raiseYunohostError, get_test_apps_dir +from .conftest import message, raiseYunohostError, get_test_apps_dir from moulinette.utils.filesystem import mkdir diff --git a/src/yunohost/tests/test_apps_arguments_parsing.py b/src/yunohost/tests/test_apps_arguments_parsing.py index 88c235252..dfe17d229 100644 --- a/src/yunohost/tests/test_apps_arguments_parsing.py +++ b/src/yunohost/tests/test_apps_arguments_parsing.py @@ -2,7 +2,7 @@ import sys import pytest from mock import patch -from StringIO import StringIO +from io import StringIO from collections import OrderedDict from moulinette import msignals diff --git a/src/yunohost/tests/test_appurl.py b/src/yunohost/tests/test_appurl.py index 11ee7b4f5..3a2313b0e 100644 --- a/src/yunohost/tests/test_appurl.py +++ b/src/yunohost/tests/test_appurl.py @@ -1,7 +1,7 @@ import pytest import os -from conftest import get_test_apps_dir +from .conftest import get_test_apps_dir from yunohost.utils.error import YunohostError from yunohost.app import app_install, app_remove, _normalize_domain_path diff --git a/src/yunohost/tests/test_backuprestore.py b/src/yunohost/tests/test_backuprestore.py index 9c9448879..b88fbd5b3 100644 --- a/src/yunohost/tests/test_backuprestore.py +++ b/src/yunohost/tests/test_backuprestore.py @@ -3,7 +3,7 @@ import os import shutil import subprocess -from conftest import message, raiseYunohostError, get_test_apps_dir +from .conftest import message, raiseYunohostError, get_test_apps_dir from yunohost.app import app_install, app_remove, app_ssowatconf from yunohost.app import _is_installed diff --git a/src/yunohost/tests/test_changeurl.py b/src/yunohost/tests/test_changeurl.py index ecd926a2e..ef076e67b 100644 --- a/src/yunohost/tests/test_changeurl.py +++ b/src/yunohost/tests/test_changeurl.py @@ -3,7 +3,7 @@ import time import requests import os -from conftest import get_test_apps_dir +from .conftest import get_test_apps_dir from yunohost.app import app_install, app_change_url, app_remove, app_map from yunohost.domain import _get_maindomain diff --git a/src/yunohost/tests/test_permission.py b/src/yunohost/tests/test_permission.py index 1d3961585..a1f411b80 100644 --- a/src/yunohost/tests/test_permission.py +++ b/src/yunohost/tests/test_permission.py @@ -6,7 +6,7 @@ import os import json import shutil -from conftest import message, raiseYunohostError, get_test_apps_dir +from .conftest import message, raiseYunohostError, get_test_apps_dir from yunohost.app import app_install, app_upgrade, app_remove, app_change_url, app_map, _installed_apps, APPS_SETTING_PATH, _set_app_settings, _get_app_settings from yunohost.user import user_list, user_create, user_delete, \ diff --git a/src/yunohost/tests/test_regenconf.py b/src/yunohost/tests/test_regenconf.py index 4e1ae679b..c9a3e68f5 100644 --- a/src/yunohost/tests/test_regenconf.py +++ b/src/yunohost/tests/test_regenconf.py @@ -1,6 +1,6 @@ import os -from conftest import message +from .conftest import message from yunohost.domain import domain_add, domain_remove, domain_list from yunohost.regenconf import regen_conf, manually_modified_files, _get_conf_hashes, _force_clear_hashes diff --git a/src/yunohost/tests/test_service.py b/src/yunohost/tests/test_service.py index d0a3d4fc2..0c65a864a 100644 --- a/src/yunohost/tests/test_service.py +++ b/src/yunohost/tests/test_service.py @@ -1,6 +1,6 @@ import os -from conftest import raiseYunohostError +from .conftest import raiseYunohostError from yunohost.service import _get_services, _save_services, service_status, service_add, service_remove, service_log diff --git a/src/yunohost/tests/test_user-group.py b/src/yunohost/tests/test_user-group.py index c0f51e35a..31131e939 100644 --- a/src/yunohost/tests/test_user-group.py +++ b/src/yunohost/tests/test_user-group.py @@ -1,6 +1,6 @@ import pytest -from conftest import message, raiseYunohostError +from .conftest import message, raiseYunohostError from yunohost.user import user_list, user_info, user_create, user_delete, user_update, \ user_group_list, user_group_create, user_group_delete, user_group_update diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 96bd01ed6..f01f6adb8 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -303,7 +303,7 @@ def tools_postinstall(operation_logger, domain, password, ignore_dyndns=False, '/home/yunohost.app' ] - for folder in filter(lambda x: not os.path.exists(x), folders_to_create): + for folder in [x for x in folders_to_create if not os.path.exists(x)]: os.makedirs(folder) # Change folders permissions @@ -953,7 +953,7 @@ def _get_migrations_list(): # (in particular, pending migrations / not already ran are not listed states = tools_migrations_state()["migrations"] - for migration_file in filter(lambda x: re.match(r"^\d+_[a-zA-Z0-9_]+\.py$", x), os.listdir(migrations_path)): + for migration_file in [x for x in os.listdir(migrations_path) if re.match(r"^\d+_[a-zA-Z0-9_]+\.py$", x)]: m = _load_migration(migration_file) m.state = states.get(m.id, "pending") migrations.append(m) @@ -972,7 +972,7 @@ def _get_migration_by_name(migration_name): raise AssertionError("Unable to find migration with name %s" % migration_name) migrations_path = data_migrations.__path__[0] - migrations_found = filter(lambda x: re.match(r"^\d+_%s\.py$" % migration_name, x), os.listdir(migrations_path)) + migrations_found = [x for x in os.listdir(migrations_path) if re.match(r"^\d+_%s\.py$" % migration_name, x)] assert len(migrations_found) == 1, "Unable to find migration with name %s" % migration_name