fix pep8, fix argparse

This commit is contained in:
Fabian Weisshaar 2017-12-28 18:55:44 +01:00 committed by Fabian Weisshaar
parent d50c225eab
commit fe1c697631
3 changed files with 55 additions and 52 deletions

View File

@ -20,7 +20,6 @@ from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
from django.utils.six import text_type
from . import dnstools
RESULT_MSG_LEN = 255
@ -64,6 +63,7 @@ def host_blacklist_validator(value):
from collections import namedtuple
UpdateAlgorithm = namedtuple("update_algorithm", "bitlength bind_name")
UPDATE_ALGORITHM_DEFAULT = 'HMAC_SHA512'
@ -128,7 +128,8 @@ class Domain(models.Model):
last_update = models.DateTimeField(_("last update"), auto_now=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):
return self.name
@ -149,7 +150,7 @@ class Domain(models.Model):
class Meta:
verbose_name = _('domain')
verbose_name_plural = _('domains')
ordering = ('name', )
ordering = ('name',)
@python_2_unicode_compatible
@ -249,14 +250,15 @@ class Host(models.Model):
last_update = models.DateTimeField(_("last update"), auto_now=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):
return u"%s.%s" % (self.name, self.domain.name)
class Meta(object):
unique_together = (('name', 'domain'), )
index_together = (('name', 'domain'), )
unique_together = (('name', 'domain'),)
index_together = (('name', 'domain'),)
verbose_name = _('host')
verbose_name_plural = _('hosts')
ordering = ('domain', 'name') # groupby domain and sort by name
@ -345,10 +347,11 @@ def pre_delete_host(sender, **kwargs):
except (dnstools.Timeout, dnstools.NameServerNotAvailable):
# well, we tried to clean up, but we didn't reach the nameserver
pass
except (dnstools.DnsUpdateError, ):
except (dnstools.DnsUpdateError,):
# e.g. PeerBadSignature if host is protected by a key we do not have
pass
pre_delete.connect(pre_delete_host, sender=Host)
@ -360,10 +363,11 @@ def post_save_host(sender, **kwargs):
except (dnstools.Timeout, dnstools.NameServerNotAvailable):
# well, we tried to clean up, but we didn't reach the nameserver
pass
except (dnstools.DnsUpdateError, ):
except (dnstools.DnsUpdateError,):
# e.g. PeerBadSignature if host is protected by a key we do not have
pass
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))
class Meta(object):
unique_together = (('name', 'main_host'), )
unique_together = (('name', 'main_host'),)
verbose_name = _('related host')
verbose_name_plural = _('related hosts')
ordering = ('main_host', 'name')
@ -528,7 +532,7 @@ class ServiceUpdaterHostConfig(models.Model):
verbose_name=_("created by"), on_delete=models.CASCADE)
def __str__(self):
return u"%s (%s)" % (self.hostname, self.service.name, )
return u"%s (%s)" % (self.hostname, self.service.name,)
class Meta(object):
verbose_name = _('service updater host config')

View File

@ -12,7 +12,6 @@ from django.utils.translation import ugettext_lazy as _
from nsupdate.main.models import Host
from nsupdate.utils.mail import translate_for_user, send_mail_to_user
ABUSE_MSG = _("""\
Your host: %(fqdn)s (comment: %(comment)s)
@ -90,8 +89,8 @@ class Command(BaseCommand):
action='store',
dest='flag_abuse',
default=None,
type='int',
help='if client faults > N then set abuse flag and reset client faults')
type=int,
help='if client faults N then set abuse flag and reset client faults')
parser.add_argument('--notify-user',
action='store_true',
dest='notify_user',
@ -117,7 +116,7 @@ class Command(BaseCommand):
output += u"%-6d " % h.client_faults
if show_server:
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)
if (flag_abuse is not None or reset_client or reset_server or
reset_available or reset_abuse or reset_abuse_blocked):
@ -154,7 +153,7 @@ class Command(BaseCommand):
h.save()
except Exception:
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)
except Exception:
pass

View File

@ -21,7 +21,7 @@ all_files = 1
[upload_sphinx]
upload-dir = docs/_build/html
[pytest]
[tool:pytest]
DJANGO_SETTINGS_MODULE = nsupdate.settings.dev
pep8maxlinelength = 120
norecursedirs = .git