mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Make the PEP8 gods less angry
This commit is contained in:
parent
5f4450ab87
commit
aed53786f2
3 changed files with 51 additions and 58 deletions
|
@ -3,13 +3,13 @@
|
|||
import os
|
||||
import random
|
||||
|
||||
from moulinette import m18n
|
||||
from moulinette.utils.network import download_text
|
||||
from moulinette.utils.process import check_output
|
||||
from moulinette.utils.filesystem import read_file
|
||||
|
||||
from yunohost.diagnosis import Diagnoser
|
||||
|
||||
|
||||
class IPDiagnoser(Diagnoser):
|
||||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
|
@ -64,7 +64,7 @@ class IPDiagnoser(Diagnoser):
|
|||
yield dict(meta={"version": 4},
|
||||
data=ipv4,
|
||||
status="SUCCESS" if ipv4 else "ERROR",
|
||||
summary = ("diagnosis_ip_connected_ipv4", {}) if ipv4 \
|
||||
summary=("diagnosis_ip_connected_ipv4", {}) if ipv4
|
||||
else ("diagnosis_ip_no_ipv4", {}))
|
||||
|
||||
if 6 in versions:
|
||||
|
@ -77,10 +77,9 @@ class IPDiagnoser(Diagnoser):
|
|||
yield dict(meta={"version": 6},
|
||||
data=ipv6,
|
||||
status="SUCCESS" if ipv6 else "WARNING",
|
||||
summary = ("diagnosis_ip_connected_ipv6", {}) if ipv6 \
|
||||
summary=("diagnosis_ip_connected_ipv6", {}) if ipv6
|
||||
else ("diagnosis_ip_no_ipv6", {}))
|
||||
|
||||
|
||||
def can_ping_outside(self, protocol=4):
|
||||
|
||||
assert protocol in [4, 6], "Invalid protocol version, it should be either 4 or 6 and was '%s'" % repr(protocol)
|
||||
|
@ -113,11 +112,9 @@ class IPDiagnoser(Diagnoser):
|
|||
random.shuffle(resolvers)
|
||||
return any(ping(protocol, resolver) for resolver in resolvers[:5])
|
||||
|
||||
|
||||
def can_resolve_dns(self):
|
||||
return os.system("dig +short ip.yunohost.org >/dev/null 2>/dev/null") == 0
|
||||
|
||||
|
||||
def resolvconf_is_symlink(self):
|
||||
return os.path.realpath("/etc/resolv.conf") == "/run/resolvconf/resolv.conf"
|
||||
|
||||
|
@ -126,7 +123,6 @@ class IPDiagnoser(Diagnoser):
|
|||
resolvers = [r.split(" ")[1] for r in read_file(file_).split("\n") if r.startswith("nameserver")]
|
||||
return resolvers == ["127.0.0.1"]
|
||||
|
||||
|
||||
def get_public_ip(self, protocol=4):
|
||||
|
||||
# FIXME - TODO : here we assume that DNS resolution for ip.yunohost.org is working
|
||||
|
@ -149,4 +145,3 @@ class IPDiagnoser(Diagnoser):
|
|||
|
||||
def main(args, env, loggers):
|
||||
return IPDiagnoser(args, env, loggers).diagnose()
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
import os
|
||||
|
||||
from moulinette.utils.network import download_text
|
||||
from moulinette.utils.process import check_output
|
||||
from moulinette.utils.filesystem import read_file
|
||||
|
||||
from yunohost.diagnosis import Diagnoser
|
||||
from yunohost.domain import domain_list, _build_dns_conf, _get_maindomain
|
||||
|
||||
|
||||
class DNSRecordsDiagnoser(Diagnoser):
|
||||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
|
@ -73,7 +73,6 @@ class DNSRecordsDiagnoser(Diagnoser):
|
|||
|
||||
yield output
|
||||
|
||||
|
||||
def get_current_record(self, domain, name, type_):
|
||||
if name == "@":
|
||||
command = "dig +short @%s %s %s" % (self.resolver, type_, domain)
|
||||
|
@ -83,7 +82,6 @@ class DNSRecordsDiagnoser(Diagnoser):
|
|||
# e.g. no internet connectivity (dependency mechanism to good result from 'ip' diagosis ?)
|
||||
# or the resolver is unavailable for some reason
|
||||
output = check_output(command).strip()
|
||||
output = output.replace("\;",";")
|
||||
if output.startswith('"') and output.endswith('"'):
|
||||
output = '"' + ' '.join(output.replace('"', ' ').split()) + '"'
|
||||
return output
|
||||
|
@ -91,4 +89,3 @@ class DNSRecordsDiagnoser(Diagnoser):
|
|||
|
||||
def main(args, env, loggers):
|
||||
return DNSRecordsDiagnoser(args, env, loggers).diagnose()
|
||||
|
||||
|
|
|
@ -38,10 +38,12 @@ logger = log.getActionLogger('yunohost.diagnosis')
|
|||
|
||||
DIAGNOSIS_CACHE = "/var/cache/yunohost/diagnosis/"
|
||||
|
||||
|
||||
def diagnosis_list():
|
||||
all_categories_names = [h for h, _ in _list_diagnosis_categories()]
|
||||
return {"categories": all_categories_names}
|
||||
|
||||
|
||||
def diagnosis_show(categories=[], issues=False, full=False):
|
||||
|
||||
# Get all the categories
|
||||
|
@ -79,9 +81,9 @@ def diagnosis_show(categories=[], issues=False, full=False):
|
|||
|
||||
all_reports.append(report)
|
||||
|
||||
|
||||
return {"reports": all_reports}
|
||||
|
||||
|
||||
def diagnosis_run(categories=[], force=False, args=None):
|
||||
|
||||
# Get all the categories
|
||||
|
@ -127,6 +129,7 @@ def diagnosis_run(categories=[], force=False, args=None):
|
|||
|
||||
return
|
||||
|
||||
|
||||
def diagnosis_ignore(category, args="", unignore=False):
|
||||
pass
|
||||
|
||||
|
@ -149,7 +152,6 @@ class Diagnoser():
|
|||
if self.description == descr_key:
|
||||
self.description = self.id_
|
||||
|
||||
|
||||
def cached_time_ago(self):
|
||||
|
||||
if not os.path.exists(self.cache_file):
|
||||
|
@ -174,8 +176,7 @@ class Diagnoser():
|
|||
|
||||
new_report = {"id": self.id_,
|
||||
"cached_for": self.cache_duration,
|
||||
"items": items
|
||||
}
|
||||
"items": items}
|
||||
|
||||
# TODO / FIXME : should handle the case where we only did a partial diagnosis
|
||||
self.logger_debug("Updating cache %s" % self.cache_file)
|
||||
|
|
Loading…
Add table
Reference in a new issue