Trying to fix some lgtm warnings

This commit is contained in:
Kay0u 2021-12-30 00:08:49 +01:00
parent 2cc09aca91
commit bbe0486935
No known key found for this signature in database
GPG key ID: AE1DCADB6415A156
8 changed files with 66 additions and 55 deletions

View file

@ -627,7 +627,7 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False
if upgrade_failed or broke_the_system: if upgrade_failed or broke_the_system:
# display this if there are remaining apps # display this if there are remaining apps
if apps[number + 1 :]: if apps[number + 1:]:
not_upgraded_apps = apps[number:] not_upgraded_apps = apps[number:]
logger.error( logger.error(
m18n.n( m18n.n(
@ -1626,9 +1626,12 @@ class AppConfigPanel(ConfigPanel):
error=message, error=message,
) )
def _call_config_script(self, action, env={}): def _call_config_script(self, action, env=None):
from yunohost.hook import hook_exec from yunohost.hook import hook_exec
if env is None:
env = {}
# Add default config script if needed # Add default config script if needed
config_script = os.path.join( config_script = os.path.join(
APPS_SETTING_PATH, self.entity, "scripts", "config" APPS_SETTING_PATH, self.entity, "scripts", "config"

View file

@ -70,28 +70,28 @@ PRODUCTION_CERTIFICATION_AUTHORITY = "https://acme-v02.api.letsencrypt.org"
# #
def certificate_status(domain_list, full=False): def certificate_status(domains, full=False):
""" """
Print the status of certificate for given domains (all by default) Print the status of certificate for given domains (all by default)
Keyword argument: Keyword argument:
domain_list -- Domains to be checked domains -- Domains to be checked
full -- Display more info about the certificates full -- Display more info about the certificates
""" """
import yunohost.domain from yunohost.domain import domain_list, _assert_domain_exists
# If no domains given, consider all yunohost domains # If no domains given, consider all yunohost domains
if domain_list == []: if domains == []:
domain_list = yunohost.domain.domain_list()["domains"] domains = domain_list()["domains"]
# Else, validate that yunohost knows the domains given # Else, validate that yunohost knows the domains given
else: else:
for domain in domain_list: for domain in domains:
yunohost.domain._assert_domain_exists(domain) _assert_domain_exists(domain)
certificates = {} certificates = {}
for domain in domain_list: for domain in domains:
status = _get_status(domain) status = _get_status(domain)
if not full: if not full:
@ -239,28 +239,28 @@ def _certificate_install_selfsigned(domain_list, force=False):
def _certificate_install_letsencrypt( def _certificate_install_letsencrypt(
domain_list, force=False, no_checks=False, staging=False domains, force=False, no_checks=False, staging=False
): ):
import yunohost.domain from yunohost.domain import domain_list, _assert_domain_exists
if not os.path.exists(ACCOUNT_KEY_FILE): if not os.path.exists(ACCOUNT_KEY_FILE):
_generate_account_key() _generate_account_key()
# If no domains given, consider all yunohost domains with self-signed # If no domains given, consider all yunohost domains with self-signed
# certificates # certificates
if domain_list == []: if domains == []:
for domain in yunohost.domain.domain_list()["domains"]: for domain in domain_list()["domains"]:
status = _get_status(domain) status = _get_status(domain)
if status["CA_type"]["code"] != "self-signed": if status["CA_type"]["code"] != "self-signed":
continue continue
domain_list.append(domain) domains.append(domain)
# Else, validate that yunohost knows the domains given # Else, validate that yunohost knows the domains given
else: else:
for domain in domain_list: for domain in domains:
yunohost.domain._assert_domain_exists(domain) _assert_domain_exists(domain)
# Is it self-signed? # Is it self-signed?
status = _get_status(domain) status = _get_status(domain)
@ -275,7 +275,7 @@ def _certificate_install_letsencrypt(
) )
# Actual install steps # Actual install steps
for domain in domain_list: for domain in domains:
if not no_checks: if not no_checks:
try: try:
@ -311,25 +311,25 @@ def _certificate_install_letsencrypt(
def certificate_renew( def certificate_renew(
domain_list, force=False, no_checks=False, email=False, staging=False domains, force=False, no_checks=False, email=False, staging=False
): ):
""" """
Renew Let's Encrypt certificate for given domains (all by default) Renew Let's Encrypt certificate for given domains (all by default)
Keyword argument: Keyword argument:
domain_list -- Domains for which to renew the certificates domains -- Domains for which to renew the certificates
force -- Ignore the validity threshold (15 days) force -- Ignore the validity threshold (15 days)
no-check -- Disable some checks about the reachability of web server no-check -- Disable some checks about the reachability of web server
before attempting the renewing before attempting the renewing
email -- Emails root if some renewing failed email -- Emails root if some renewing failed
""" """
import yunohost.domain from yunohost.domain import domain_list, _assert_domain_exists
# If no domains given, consider all yunohost domains with Let's Encrypt # If no domains given, consider all yunohost domains with Let's Encrypt
# certificates # certificates
if domain_list == []: if domains == []:
for domain in yunohost.domain.domain_list()["domains"]: for domain in domain_list()["domains"]:
# Does it have a Let's Encrypt cert? # Does it have a Let's Encrypt cert?
status = _get_status(domain) status = _get_status(domain)
@ -347,17 +347,17 @@ def certificate_renew(
) )
continue continue
domain_list.append(domain) domains.append(domain)
if len(domain_list) == 0 and not email: if len(domains) == 0 and not email:
logger.info("No certificate needs to be renewed.") logger.info("No certificate needs to be renewed.")
# Else, validate the domain list given # Else, validate the domain list given
else: else:
for domain in domain_list: for domain in domains:
# Is it in Yunohost domain list? # Is it in Yunohost domain list?
yunohost.domain._assert_domain_exists(domain) _assert_domain_exists(domain)
status = _get_status(domain) status = _get_status(domain)
@ -385,7 +385,7 @@ def certificate_renew(
) )
# Actual renew steps # Actual renew steps
for domain in domain_list: for domain in domains:
if not no_checks: if not no_checks:
try: try:

View file

@ -41,7 +41,8 @@ class MyMigration(Migration):
) # For some reason if we don't do this, iptables-legacy-save is empty ? ) # For some reason if we don't do this, iptables-legacy-save is empty ?
self.runcmd("iptables-legacy-save > %s" % self.backup_rules_ipv4) self.runcmd("iptables-legacy-save > %s" % self.backup_rules_ipv4)
assert ( assert (
open(self.backup_rules_ipv4).read().strip() os.path.exists(self.backup_rules_ipv4) and
os.stat(self.backup_rules_ipv4).st_size > 0
), "Uhoh backup of legacy ipv4 rules is empty !?" ), "Uhoh backup of legacy ipv4 rules is empty !?"
if self.do_ipv6 and not os.path.exists(self.backup_rules_ipv6): if self.do_ipv6 and not os.path.exists(self.backup_rules_ipv6):
self.runcmd( self.runcmd(
@ -49,7 +50,8 @@ class MyMigration(Migration):
) # For some reason if we don't do this, iptables-legacy-save is empty ? ) # For some reason if we don't do this, iptables-legacy-save is empty ?
self.runcmd("ip6tables-legacy-save > %s" % self.backup_rules_ipv6) self.runcmd("ip6tables-legacy-save > %s" % self.backup_rules_ipv6)
assert ( assert (
open(self.backup_rules_ipv6).read().strip() os.path.exists(self.backup_rules_ipv6) and
os.stat(self.backup_rules_ipv6).st_size > 0
), "Uhoh backup of legacy ipv6 rules is empty !?" ), "Uhoh backup of legacy ipv6 rules is empty !?"
# We inject the legacy rules (iptables-legacy) into the new iptable (just "iptables") # We inject the legacy rules (iptables-legacy) into the new iptable (just "iptables")

View file

@ -507,17 +507,17 @@ def _set_domain_settings(domain: str, settings: dict) -> None:
def domain_cert_status(domain_list, full=False): def domain_cert_status(domain_list, full=False):
import yunohost.certificate from yunohost.certificate import certificate_status
return yunohost.certificate.certificate_status(domain_list, full) return certificate_status(domain_list, full)
def domain_cert_install( def domain_cert_install(
domain_list, force=False, no_checks=False, self_signed=False, staging=False domain_list, force=False, no_checks=False, self_signed=False, staging=False
): ):
import yunohost.certificate from yunohost.certificate import certificate_install
return yunohost.certificate.certificate_install( return certificate_install(
domain_list, force, no_checks, self_signed, staging domain_list, force, no_checks, self_signed, staging
) )
@ -525,9 +525,9 @@ def domain_cert_install(
def domain_cert_renew( def domain_cert_renew(
domain_list, force=False, no_checks=False, email=False, staging=False domain_list, force=False, no_checks=False, email=False, staging=False
): ):
import yunohost.certificate from yunohost.certificate import certificate_renew
return yunohost.certificate.certificate_renew( return certificate_renew(
domain_list, force, no_checks, email, staging domain_list, force, no_checks, email, staging
) )
@ -537,12 +537,12 @@ def domain_dns_conf(domain):
def domain_dns_suggest(domain): def domain_dns_suggest(domain):
import yunohost.dns from yunohost.dns import domain_dns_suggest
return yunohost.dns.domain_dns_suggest(domain) return domain_dns_suggest(domain)
def domain_dns_push(domain, dry_run, force, purge): def domain_dns_push(domain, dry_run, force, purge):
import yunohost.dns from yunohost.dns import domain_dns_push
return yunohost.dns.domain_dns_push(domain, dry_run, force, purge) return domain_dns_push(domain, dry_run, force, purge)

View file

@ -48,7 +48,7 @@ logger = log.getActionLogger("yunohost.regenconf")
@is_unit_operation([("names", "configuration")]) @is_unit_operation([("names", "configuration")])
def regen_conf( def regen_conf(
operation_logger, operation_logger,
names=[], names=None,
with_diff=False, with_diff=False,
force=False, force=False,
dry_run=False, dry_run=False,
@ -66,6 +66,9 @@ def regen_conf(
""" """
if names is None:
names = []
result = {} result = {}
# Return the list of pending conf # Return the list of pending conf

View file

@ -1130,7 +1130,7 @@ class Migration:
def description(self): def description(self):
return m18n.n("migration_description_%s" % self.id) return m18n.n("migration_description_%s" % self.id)
def ldap_migration(run): def ldap_migration(self, run):
def func(self): def func(self):
# Backup LDAP before the migration # Backup LDAP before the migration

View file

@ -1263,25 +1263,25 @@ def user_group_remove(groupname, usernames, force=False, sync_perm=True):
def user_permission_list(short=False, full=False, apps=[]): def user_permission_list(short=False, full=False, apps=[]):
import yunohost.permission from yunohost.permission import user_permission_list
return yunohost.permission.user_permission_list( return user_permission_list(
short, full, absolute_urls=True, apps=apps short, full, absolute_urls=True, apps=apps
) )
def user_permission_update(permission, label=None, show_tile=None, sync_perm=True): def user_permission_update(permission, label=None, show_tile=None, sync_perm=True):
import yunohost.permission from yunohost.permission import user_permission_update
return yunohost.permission.user_permission_update( return user_permission_update(
permission, label=label, show_tile=show_tile, sync_perm=sync_perm permission, label=label, show_tile=show_tile, sync_perm=sync_perm
) )
def user_permission_add(permission, names, protected=None, force=False, sync_perm=True): def user_permission_add(permission, names, protected=None, force=False, sync_perm=True):
import yunohost.permission from yunohost.permission import user_permission_update
return yunohost.permission.user_permission_update( return user_permission_update(
permission, add=names, protected=protected, force=force, sync_perm=sync_perm permission, add=names, protected=protected, force=force, sync_perm=sync_perm
) )
@ -1289,23 +1289,23 @@ def user_permission_add(permission, names, protected=None, force=False, sync_per
def user_permission_remove( def user_permission_remove(
permission, names, protected=None, force=False, sync_perm=True permission, names, protected=None, force=False, sync_perm=True
): ):
import yunohost.permission from yunohost.permission import user_permission_update
return yunohost.permission.user_permission_update( return user_permission_update(
permission, remove=names, protected=protected, force=force, sync_perm=sync_perm permission, remove=names, protected=protected, force=force, sync_perm=sync_perm
) )
def user_permission_reset(permission, sync_perm=True): def user_permission_reset(permission, sync_perm=True):
import yunohost.permission from yunohost.permission import user_permission_reset
return yunohost.permission.user_permission_reset(permission, sync_perm=sync_perm) return user_permission_reset(permission, sync_perm=sync_perm)
def user_permission_info(permission): def user_permission_info(permission):
import yunohost.permission from yunohost.permission import user_permission_info
return yunohost.permission.user_permission_info(permission) return user_permission_info(permission)
# #

View file

@ -52,7 +52,10 @@ CONFIG_PANEL_VERSION_SUPPORTED = 1.0
# Those js-like evaluate functions are used to eval safely visible attributes # Those js-like evaluate functions are used to eval safely visible attributes
# The goal is to evaluate in the same way than js simple-evaluate # The goal is to evaluate in the same way than js simple-evaluate
# https://github.com/shepherdwind/simple-evaluate # https://github.com/shepherdwind/simple-evaluate
def evaluate_simple_ast(node, context={}): def evaluate_simple_ast(node, context=None):
if context is None:
context = {}
operators = { operators = {
ast.Not: op.not_, ast.Not: op.not_,
ast.Mult: op.mul, ast.Mult: op.mul,