fix pep8, fix argparse
This commit is contained in:
parent
d50c225eab
commit
fe1c697631
@ -20,7 +20,6 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
from django.utils.six import text_type
|
from django.utils.six import text_type
|
||||||
|
|
||||||
|
|
||||||
from . import dnstools
|
from . import dnstools
|
||||||
|
|
||||||
RESULT_MSG_LEN = 255
|
RESULT_MSG_LEN = 255
|
||||||
@ -64,6 +63,7 @@ def host_blacklist_validator(value):
|
|||||||
|
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
UpdateAlgorithm = namedtuple("update_algorithm", "bitlength bind_name")
|
UpdateAlgorithm = namedtuple("update_algorithm", "bitlength bind_name")
|
||||||
|
|
||||||
UPDATE_ALGORITHM_DEFAULT = 'HMAC_SHA512'
|
UPDATE_ALGORITHM_DEFAULT = 'HMAC_SHA512'
|
||||||
@ -128,7 +128,8 @@ class Domain(models.Model):
|
|||||||
|
|
||||||
last_update = models.DateTimeField(_("last update"), auto_now=True)
|
last_update = models.DateTimeField(_("last update"), auto_now=True)
|
||||||
created = models.DateTimeField(_("created at"), auto_now_add=True)
|
created = models.DateTimeField(_("created at"), auto_now_add=True)
|
||||||
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='domains', verbose_name=_("created by"), on_delete=models.CASCADE)
|
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='domains', verbose_name=_("created by"),
|
||||||
|
on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@ -149,7 +150,7 @@ class Domain(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('domain')
|
verbose_name = _('domain')
|
||||||
verbose_name_plural = _('domains')
|
verbose_name_plural = _('domains')
|
||||||
ordering = ('name', )
|
ordering = ('name',)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
@ -249,14 +250,15 @@ class Host(models.Model):
|
|||||||
|
|
||||||
last_update = models.DateTimeField(_("last update"), auto_now=True)
|
last_update = models.DateTimeField(_("last update"), auto_now=True)
|
||||||
created = models.DateTimeField(_("created at"), auto_now_add=True)
|
created = models.DateTimeField(_("created at"), auto_now_add=True)
|
||||||
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='hosts', verbose_name=_("created by"), on_delete=models.CASCADE)
|
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='hosts', verbose_name=_("created by"),
|
||||||
|
on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u"%s.%s" % (self.name, self.domain.name)
|
return u"%s.%s" % (self.name, self.domain.name)
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
unique_together = (('name', 'domain'), )
|
unique_together = (('name', 'domain'),)
|
||||||
index_together = (('name', 'domain'), )
|
index_together = (('name', 'domain'),)
|
||||||
verbose_name = _('host')
|
verbose_name = _('host')
|
||||||
verbose_name_plural = _('hosts')
|
verbose_name_plural = _('hosts')
|
||||||
ordering = ('domain', 'name') # groupby domain and sort by name
|
ordering = ('domain', 'name') # groupby domain and sort by name
|
||||||
@ -345,10 +347,11 @@ def pre_delete_host(sender, **kwargs):
|
|||||||
except (dnstools.Timeout, dnstools.NameServerNotAvailable):
|
except (dnstools.Timeout, dnstools.NameServerNotAvailable):
|
||||||
# well, we tried to clean up, but we didn't reach the nameserver
|
# well, we tried to clean up, but we didn't reach the nameserver
|
||||||
pass
|
pass
|
||||||
except (dnstools.DnsUpdateError, ):
|
except (dnstools.DnsUpdateError,):
|
||||||
# e.g. PeerBadSignature if host is protected by a key we do not have
|
# e.g. PeerBadSignature if host is protected by a key we do not have
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
pre_delete.connect(pre_delete_host, sender=Host)
|
pre_delete.connect(pre_delete_host, sender=Host)
|
||||||
|
|
||||||
|
|
||||||
@ -360,10 +363,11 @@ def post_save_host(sender, **kwargs):
|
|||||||
except (dnstools.Timeout, dnstools.NameServerNotAvailable):
|
except (dnstools.Timeout, dnstools.NameServerNotAvailable):
|
||||||
# well, we tried to clean up, but we didn't reach the nameserver
|
# well, we tried to clean up, but we didn't reach the nameserver
|
||||||
pass
|
pass
|
||||||
except (dnstools.DnsUpdateError, ):
|
except (dnstools.DnsUpdateError,):
|
||||||
# e.g. PeerBadSignature if host is protected by a key we do not have
|
# e.g. PeerBadSignature if host is protected by a key we do not have
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
post_save.connect(post_save_host, sender=Host)
|
post_save.connect(post_save_host, sender=Host)
|
||||||
|
|
||||||
|
|
||||||
@ -411,7 +415,7 @@ class RelatedHost(models.Model):
|
|||||||
return u"%s.%s" % (self.name, text_type(self.main_host))
|
return u"%s.%s" % (self.name, text_type(self.main_host))
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
unique_together = (('name', 'main_host'), )
|
unique_together = (('name', 'main_host'),)
|
||||||
verbose_name = _('related host')
|
verbose_name = _('related host')
|
||||||
verbose_name_plural = _('related hosts')
|
verbose_name_plural = _('related hosts')
|
||||||
ordering = ('main_host', 'name')
|
ordering = ('main_host', 'name')
|
||||||
@ -528,7 +532,7 @@ class ServiceUpdaterHostConfig(models.Model):
|
|||||||
verbose_name=_("created by"), on_delete=models.CASCADE)
|
verbose_name=_("created by"), on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u"%s (%s)" % (self.hostname, self.service.name, )
|
return u"%s (%s)" % (self.hostname, self.service.name,)
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
verbose_name = _('service updater host config')
|
verbose_name = _('service updater host config')
|
||||||
|
@ -12,7 +12,6 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from nsupdate.main.models import Host
|
from nsupdate.main.models import Host
|
||||||
from nsupdate.utils.mail import translate_for_user, send_mail_to_user
|
from nsupdate.utils.mail import translate_for_user, send_mail_to_user
|
||||||
|
|
||||||
|
|
||||||
ABUSE_MSG = _("""\
|
ABUSE_MSG = _("""\
|
||||||
Your host: %(fqdn)s (comment: %(comment)s)
|
Your host: %(fqdn)s (comment: %(comment)s)
|
||||||
|
|
||||||
@ -52,51 +51,51 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument('--show-server',
|
parser.add_argument('--show-server',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='show_server',
|
dest='show_server',
|
||||||
default=False,
|
default=False,
|
||||||
help='show server fault counters')
|
help='show server fault counters')
|
||||||
parser.add_argument('--show-client',
|
parser.add_argument('--show-client',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='show_client',
|
dest='show_client',
|
||||||
default=False,
|
default=False,
|
||||||
help='show client fault counters')
|
help='show client fault counters')
|
||||||
parser.add_argument('--reset-server',
|
parser.add_argument('--reset-server',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='reset_server',
|
dest='reset_server',
|
||||||
default=False,
|
default=False,
|
||||||
help='reset the server fault counters of all hosts')
|
help='reset the server fault counters of all hosts')
|
||||||
parser.add_argument('--reset-client',
|
parser.add_argument('--reset-client',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='reset_client',
|
dest='reset_client',
|
||||||
default=False,
|
default=False,
|
||||||
help='reset the client fault counters of all hosts')
|
help='reset the client fault counters of all hosts')
|
||||||
parser.add_argument('--reset-abuse',
|
parser.add_argument('--reset-abuse',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='reset_abuse',
|
dest='reset_abuse',
|
||||||
default=False,
|
default=False,
|
||||||
help='reset the abuse flag (to False) of all hosts')
|
help='reset the abuse flag (to False) of all hosts')
|
||||||
parser.add_argument('--reset-abuse-blocked',
|
parser.add_argument('--reset-abuse-blocked',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='reset_abuse_blocked',
|
dest='reset_abuse_blocked',
|
||||||
default=False,
|
default=False,
|
||||||
help='reset the abuse_blocked flag (to False) of all hosts')
|
help='reset the abuse_blocked flag (to False) of all hosts')
|
||||||
parser.add_argument('--reset-available',
|
parser.add_argument('--reset-available',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='reset_available',
|
dest='reset_available',
|
||||||
default=False,
|
default=False,
|
||||||
help='reset the available flag (to True) of all hosts')
|
help='reset the available flag (to True) of all hosts')
|
||||||
parser.add_argument('--flag-abuse',
|
parser.add_argument('--flag-abuse',
|
||||||
action='store',
|
action='store',
|
||||||
dest='flag_abuse',
|
dest='flag_abuse',
|
||||||
default=None,
|
default=None,
|
||||||
type='int',
|
type=int,
|
||||||
help='if client faults > N then set abuse flag and reset client faults')
|
help='if client faults N then set abuse flag and reset client faults')
|
||||||
parser.add_argument('--notify-user',
|
parser.add_argument('--notify-user',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='notify_user',
|
dest='notify_user',
|
||||||
default=False,
|
default=False,
|
||||||
help='notify the user by email when host gets flagged for abuse')
|
help='notify the user by email when host gets flagged for abuse')
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
show_client = options['show_client']
|
show_client = options['show_client']
|
||||||
@ -117,10 +116,10 @@ class Command(BaseCommand):
|
|||||||
output += u"%-6d " % h.client_faults
|
output += u"%-6d " % h.client_faults
|
||||||
if show_server:
|
if show_server:
|
||||||
output += u"%-6d " % h.server_faults
|
output += u"%-6d " % h.server_faults
|
||||||
output += u"%s %s\n" % (h.created_by.username, h.get_fqdn(), )
|
output += u"%s %s\n" % (h.created_by.username, h.get_fqdn(),)
|
||||||
self.stdout.write(output)
|
self.stdout.write(output)
|
||||||
if (flag_abuse is not None or reset_client or reset_server or
|
if (flag_abuse is not None or reset_client or reset_server or
|
||||||
reset_available or reset_abuse or reset_abuse_blocked):
|
reset_available or reset_abuse or reset_abuse_blocked):
|
||||||
if flag_abuse is not None:
|
if flag_abuse is not None:
|
||||||
if h.client_faults > flag_abuse:
|
if h.client_faults > flag_abuse:
|
||||||
h.abuse = True
|
h.abuse = True
|
||||||
@ -154,7 +153,7 @@ class Command(BaseCommand):
|
|||||||
h.save()
|
h.save()
|
||||||
except Exception:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
msg = u"The following Exception occurred when processing host %s!\n" % (h.get_fqdn(), )
|
msg = u"The following Exception occurred when processing host %s!\n" % (h.get_fqdn(),)
|
||||||
self.stderr.write(msg)
|
self.stderr.write(msg)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
@ -21,7 +21,7 @@ all_files = 1
|
|||||||
[upload_sphinx]
|
[upload_sphinx]
|
||||||
upload-dir = docs/_build/html
|
upload-dir = docs/_build/html
|
||||||
|
|
||||||
[pytest]
|
[tool:pytest]
|
||||||
DJANGO_SETTINGS_MODULE = nsupdate.settings.dev
|
DJANGO_SETTINGS_MODULE = nsupdate.settings.dev
|
||||||
pep8maxlinelength = 120
|
pep8maxlinelength = 120
|
||||||
norecursedirs = .git
|
norecursedirs = .git
|
||||||
|
Loading…
x
Reference in New Issue
Block a user