From 4cabb2f7f991d0135221e546cb8165420377f798 Mon Sep 17 00:00:00 2001 From: opi Date: Sun, 27 Mar 2016 15:56:41 +0200 Subject: [PATCH] [enh] Use named arguments with m18n. --- locales/en.json | 20 ++++++++++---------- src/yunohost/dyndns.py | 2 +- src/yunohost/firewall.py | 6 +++--- src/yunohost/hook.py | 2 +- src/yunohost/monitor.py | 6 +++--- src/yunohost/tools.py | 2 +- src/yunohost/user.py | 10 +++++----- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/locales/en.json b/locales/en.json index 7931fa003..e2d12cbf9 100644 --- a/locales/en.json +++ b/locales/en.json @@ -5,7 +5,7 @@ "installation_complete" : "Installation complete", "installation_failed" : "Installation failed", "unexpected_error" : "An unexpected error occured", - "action_invalid" : "Invalid action '{:s}'", + "action_invalid" : "Invalid action '{action:s}'", "not_enough_disk_space" : "Not enough free disk space on '{path:s}'", "license_undefined" : "undefined", @@ -70,7 +70,7 @@ "dyndns_key_generating" : "DNS key is being generated, it may take a while...", "dyndns_unavailable" : "Unavailable DynDNS subdomain", - "dyndns_registration_failed" : "Unable to register DynDNS domain: {:s}", + "dyndns_registration_failed" : "Unable to register DynDNS domain: {error:s}", "dyndns_registered" : "DynDNS domain successfully registered", "dyndns_ip_update_failed" : "Unable to update IP address on DynDNS", "dyndns_ip_updated" : "IP address successfully updated on DynDNS", @@ -80,8 +80,8 @@ "port_available" : "Port {port:d} is available", "port_unavailable" : "Port {port:d} is not available", - "port_already_opened" : "Port {} is already opened for {:s} connections", - "port_already_closed" : "Port {} is already closed for {:s} connections", + "port_already_opened" : "Port {port:d} is already opened for {ip_version:s} connections", + "port_already_closed" : "Port {port:d} is already closed for {ip_version:s} connections", "iptables_unavailable" : "You cannot play with iptables here. You are either in a container or your kernel does not support it.", "ip6tables_unavailable" : "You cannot play with ip6tables here. You are either in a container or your kernel does not support it.", "upnp_dev_not_found" : "No UPnP device found", @@ -93,12 +93,12 @@ "firewall_reloaded" : "Firewall successfully reloaded", "hook_list_by_invalid" : "Invalid property to list hook by", - "hook_name_unknown" : "Unknown hook name '{:s}'", + "hook_name_unknown" : "Unknown hook name '{name:s}'", "hook_exec_failed" : "Script execution failed: {path:s}", "hook_exec_not_terminated" : "Script execution hasn’t terminated: {path:s}", "mountpoint_unknown" : "Unknown mountpoint", - "unit_unknown" : "Unknown unit '{:s}'", + "unit_unknown" : "Unknown unit '{unit:s}'", "monitor_period_invalid" : "Invalid time period", "monitor_stats_no_update" : "No monitoring statistics to update", "monitor_stats_file_not_found" : "Statistics file not found", @@ -150,7 +150,7 @@ "updating_apt_cache" : "Updating the lists of available packages...", "update_cache_failed" : "Unable to update APT cache", "packages_no_upgrade" : "There is no package to upgrade", - "packages_upgrade_critical_later" : "Critical packages ({:s}) will be upgraded later", + "packages_upgrade_critical_later" : "Critical packages ({packages:s}) will be upgraded later", "upgrading_packages" : "Upgrading packages...", "packages_upgrade_failed" : "Unable to upgrade all packages", "system_upgraded" : "System successfully upgraded", @@ -192,9 +192,9 @@ "backup_deleted" : "Backup successfully deleted", "field_invalid" : "Invalid field '{:s}'", - "mail_domain_unknown" : "Unknown mail address domain '{:s}'", - "mail_alias_remove_failed" : "Unable to remove mail alias '{:s}'", - "mail_forward_remove_failed" : "Unable to remove mail forward '{:s}'", + "mail_domain_unknown" : "Unknown mail address domain '{domain:s}'", + "mail_alias_remove_failed" : "Unable to remove mail alias '{mail:s}'", + "mail_forward_remove_failed" : "Unable to remove mail forward '{mail:s}'", "user_unknown" : "Unknown user", "system_username_exists" : "Username already exists in the system users", "user_creation_failed" : "Unable to create user", diff --git a/src/yunohost/dyndns.py b/src/yunohost/dyndns.py index 412bd84b1..4d95ebeab 100644 --- a/src/yunohost/dyndns.py +++ b/src/yunohost/dyndns.py @@ -107,7 +107,7 @@ def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None try: error = json.loads(r.text)['error'] except: error = "Server error" raise MoulinetteError(errno.EPERM, - m18n.n('dyndns_registration_failed', error)) + m18n.n('dyndns_registration_failed', error=error)) logger.success(m18n.n('dyndns_registered')) diff --git a/src/yunohost/firewall.py b/src/yunohost/firewall.py index 678ff7db5..ef6249434 100644 --- a/src/yunohost/firewall.py +++ b/src/yunohost/firewall.py @@ -83,7 +83,7 @@ def firewall_allow(protocol, port, ipv4_only=False, ipv6_only=False, firewall[i][p].append(port) else: ipv = "IPv%s" % i[3] - logger.warning(m18n.n('port_already_opened', port, ipv)) + logger.warning(m18n.n('port_already_opened', port=port, ip_version=ipv)) # Add port forwarding with UPnP if not no_upnp and port not in firewall['uPnP'][p]: firewall['uPnP'][p].append(port) @@ -140,7 +140,7 @@ def firewall_disallow(protocol, port, ipv4_only=False, ipv6_only=False, firewall[i][p].remove(port) else: ipv = "IPv%s" % i[3] - logger.warning(m18n.n('port_already_closed', port, ipv)) + logger.warning(m18n.n('port_already_closed', port=port, ip_version=ipv)) # Remove port forwarding with UPnP if upnp and port in firewall['uPnP'][p]: firewall['uPnP'][p].remove(port) @@ -335,7 +335,7 @@ def firewall_upnp(action='status', no_refresh=False): if action == 'status': no_refresh = True else: - raise MoulinetteError(errno.EINVAL, m18n.n('action_invalid', action)) + raise MoulinetteError(errno.EINVAL, m18n.n('action_invalid', action=action)) # Refresh port mapping using UPnP if not no_refresh: diff --git a/src/yunohost/hook.py b/src/yunohost/hook.py index 1365c8289..a095efb6f 100644 --- a/src/yunohost/hook.py +++ b/src/yunohost/hook.py @@ -110,7 +110,7 @@ def hook_info(action, name): }) if not hooks: - raise MoulinetteError(errno.EINVAL, m18n.n('hook_name_unknown', name)) + raise MoulinetteError(errno.EINVAL, m18n.n('hook_name_unknown', name=name)) return { 'action': action, 'name': name, diff --git a/src/yunohost/monitor.py b/src/yunohost/monitor.py index 542455dd7..5142c8305 100644 --- a/src/yunohost/monitor.py +++ b/src/yunohost/monitor.py @@ -139,7 +139,7 @@ def monitor_disk(units=None, mountpoint=None, human_readable=False): for dname in devices_names: _set(dname, 'not-available') else: - raise MoulinetteError(errno.EINVAL, m18n.n('unit_unknown', u)) + raise MoulinetteError(errno.EINVAL, m18n.n('unit_unknown', unit=u)) if result_dname is not None: return result[result_dname] @@ -237,7 +237,7 @@ def monitor_network(units=None, human_readable=False): 'gateway': gateway, } else: - raise MoulinetteError(errno.EINVAL, m18n.n('unit_unknown', u)) + raise MoulinetteError(errno.EINVAL, m18n.n('unit_unknown', unit=u)) if len(units) == 1: return result[units[0]] @@ -287,7 +287,7 @@ def monitor_system(units=None, human_readable=False): elif u == 'infos': result[u] = json.loads(glances.getSystem()) else: - raise MoulinetteError(errno.EINVAL, m18n.n('unit_unknown', u)) + raise MoulinetteError(errno.EINVAL, m18n.n('unit_unknown', unit=u)) if len(units) == 1 and type(result[units[0]]) is not str: return result[units[0]] diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index b9b81723c..a17128ed0 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -380,7 +380,7 @@ def tools_upgrade(auth, ignore_apps=False, ignore_packages=False): # ... and set a hourly cron up to upgrade critical packages if critical_upgrades: logger.info(m18n.n('packages_upgrade_critical_later', - ', '.join(critical_upgrades))) + packages=', '.join(critical_upgrades))) with open('/etc/cron.d/yunohost-upgrade', 'w+') as f: f.write('00 * * * * root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin apt-get install %s -y && rm -f /etc/cron.d/yunohost-upgrade\n' % ' '.join(critical_upgrades)) diff --git a/src/yunohost/user.py b/src/yunohost/user.py index dc3c3d6fa..4cc77632d 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -128,7 +128,7 @@ def user_create(auth, username, firstname, lastname, mail, password, if mail[mail.find('@')+1:] not in domain_list(auth)['domains']: raise MoulinetteError(errno.EINVAL, m18n.n('mail_domain_unknown', - mail[mail.find('@')+1:])) + domain=mail[mail.find('@')+1:])) # Get random UID/GID uid_check = gid_check = 0 @@ -301,7 +301,7 @@ def user_update(auth, username, firstname=None, lastname=None, mail=None, if mail[mail.find('@')+1:] not in domains: raise MoulinetteError(errno.EINVAL, m18n.n('mail_domain_unknown', - mail[mail.find('@')+1:])) + domain=mail[mail.find('@')+1:])) del user['mail'][0] new_attr_dict['mail'] = [mail] + user['mail'] @@ -313,7 +313,7 @@ def user_update(auth, username, firstname=None, lastname=None, mail=None, if mail[mail.find('@')+1:] not in domains: raise MoulinetteError(errno.EINVAL, m18n.n('mail_domain_unknown', - mail[mail.find('@')+1:])) + domain=mail[mail.find('@')+1:])) user['mail'].append(mail) new_attr_dict['mail'] = user['mail'] @@ -325,7 +325,7 @@ def user_update(auth, username, firstname=None, lastname=None, mail=None, user['mail'].remove(mail) else: raise MoulinetteError(errno.EINVAL, - m18n.n('mail_alias_remove_failed', mail)) + m18n.n('mail_alias_remove_failed', mail=mail)) new_attr_dict['mail'] = user['mail'] if add_mailforward: @@ -345,7 +345,7 @@ def user_update(auth, username, firstname=None, lastname=None, mail=None, user['maildrop'].remove(mail) else: raise MoulinetteError(errno.EINVAL, - m18n.n('mail_forward_remove_failed', mail)) + m18n.n('mail_forward_remove_failed', mail=mail)) new_attr_dict['maildrop'] = user['maildrop'] if mailbox_quota is not None: