1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00

black formatted

This commit is contained in:
Matt Griswold
2019-12-05 16:57:52 +00:00
parent a53cadb167
commit cf56acbfc4
106 changed files with 7894 additions and 5626 deletions

View File

@@ -11,13 +11,16 @@ class Command(BaseCommand):
help = "Undo object deletion"
def add_arguments(self, parser):
parser.add_argument("reftag", nargs="?",
help="object reftag (net, ix, fac etc..)")
parser.add_argument(
"reftag", nargs="?", help="object reftag (net, ix, fac etc..)"
)
parser.add_argument("id", nargs="?", help="object id")
parser.add_argument("version_id", nargs="?",
help="object version id where it was deleted")
parser.add_argument('--commit', action='store_true',
help="will commit the changes")
parser.add_argument(
"version_id", nargs="?", help="object version id where it was deleted"
)
parser.add_argument(
"--commit", action="store_true", help="will commit the changes"
)
def log(self, msg):
if self.commit:
@@ -36,7 +39,8 @@ class Command(BaseCommand):
self.version_id = options.get("version_id")
self.suppress_warning = None
self.version = version = reversion.models.Version.objects.get(
id=self.version_id)
id=self.version_id
)
self.date = version.revision.date_created
self.log("UNDELETING FROM DATE: {}".format(self.date))
self.undelete(options.get("reftag"), options.get("id"))
@@ -47,15 +51,15 @@ class Command(BaseCommand):
if conflict_ip4:
# ipv4 exists in another netixlan now
others = model.objects.filter(ipaddr4=netixlan.ipaddr4,
status="ok")
for other in [
o for o in others if o.ixlan.ix_id == netixlan.ixlan.ix_id
]:
others = model.objects.filter(ipaddr4=netixlan.ipaddr4, status="ok")
for other in [o for o in others if o.ixlan.ix_id == netixlan.ixlan.ix_id]:
# netixlan is at same ix as the one being undeleted, delete the other
# one so we can proceed with undeletion
self.log("Found duplicate netixlan at same ix: {} - deleting".
format(other.ipaddr4))
self.log(
"Found duplicate netixlan at same ix: {} - deleting".format(
other.ipaddr4
)
)
if self.commit:
other.delete()
else:
@@ -63,24 +67,22 @@ class Command(BaseCommand):
# are not deleting the conflict
self.suppress_warning = True
for other in [
o for o in others if o.ixlan.ix_id != netixlan.ixlan.ix_id
]:
for other in [o for o in others if o.ixlan.ix_id != netixlan.ixlan.ix_id]:
# unless ipv4 also exists in a netixlan that is NOT at the same ix
# then we need the warning again
self.suppress_warning = False
if conflict_ip6:
# ipv6 exists in another netixlan now
others = model.objects.filter(ipaddr6=netixlan.ipaddr6,
status="ok")
for other in [
o for o in others if o.ixlan.ix_id == netixlan.ixlan.ix_id
]:
others = model.objects.filter(ipaddr6=netixlan.ipaddr6, status="ok")
for other in [o for o in others if o.ixlan.ix_id == netixlan.ixlan.ix_id]:
# netixlan is at same ix as the one being undeleted, delete the other
# one so we can proceed with undeletion
self.log("Found duplicate netixlan at same ix: {} - deleting".
format(other.ipaddr6))
self.log(
"Found duplicate netixlan at same ix: {} - deleting".format(
other.ipaddr6
)
)
if self.commit:
other.delete()
else:
@@ -88,9 +90,7 @@ class Command(BaseCommand):
# are not deleting the conflict
self.suppress_warning = True
for other in [
o for o in others if o.ixlan.ix_id != netixlan.ixlan.ix_id
]:
for other in [o for o in others if o.ixlan.ix_id != netixlan.ixlan.ix_id]:
# unless ipv6 also exists in a netixlan that is NOT at the same ix
# then we need the warning again
self.suppress_warning = False
@@ -106,18 +106,22 @@ class Command(BaseCommand):
return obj
if date:
version = reversion.models.Version.objects.get_for_object(
obj).filter(revision__date_created__lt=date).order_by(
"revision__date_created").last()
version = (
reversion.models.Version.objects.get_for_object(obj)
.filter(revision__date_created__lt=date)
.order_by("revision__date_created")
.last()
)
try:
status = json.loads(
version.serialized_data)[0].get("fields")["status"]
status = json.loads(version.serialized_data)[0].get("fields")["status"]
except:
status = None
if status == "deleted":
self.log_warn(
"{} was already deleted at snapshot, skipping ..".format(
_label(obj)))
_label(obj)
)
)
return
can_undelete_obj = True
@@ -133,8 +137,10 @@ class Command(BaseCommand):
if relation.status == "deleted" and relation != parent:
can_undelete_obj = False
self.log_warn(
"Cannot undelete {}, dependent relation marked as deleted: {}"
.format(_label(obj), relation))
"Cannot undelete {}, dependent relation marked as deleted: {}".format(
_label(obj), relation
)
)
if not can_undelete_obj:
return
@@ -153,8 +159,7 @@ class Command(BaseCommand):
obj.save()
except Exception as exc:
if not self.suppress_warning:
self.log_warn("Cannot undelete {}: {}".format(
_label(obj), exc))
self.log_warn("Cannot undelete {}: {}".format(_label(obj), exc))
for field in cls._meta.get_fields():
if field.is_relation:
@@ -167,5 +172,4 @@ class Command(BaseCommand):
if not hasattr(field.related_model, "ref_tag"):
continue
for child in relation.filter(updated__gte=self.date):
self.undelete(child.ref_tag, child.id, obj,
date=self.date)
self.undelete(child.ref_tag, child.id, obj, date=self.date)