Commit 3f6ef2c4 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'noc-py3-clean-3' into 'master'

2to3 set literal

See merge request noc/noc!1983
parents 66694638 cc982f49
This diff is collapsed.
......@@ -146,7 +146,7 @@ class Command(BaseCommand):
"""
Generator yielding all affected managed objects
"""
seen = set([alarm.managed_object])
seen = {alarm.managed_object}
yield alarm.managed_object
for a in iter_consequences(alarm):
if a.managed_object not in seen:
......
......@@ -191,7 +191,7 @@ class Command(BaseCommand):
if not os.path.isdir(ts_root):
raise CommandError("Inconsistent template set %s" % templateset)
# Get installed modules
modules = set([a[4:] for a in INSTALLED_APPS if a.startswith("noc.")])
modules = {a[4:] for a in INSTALLED_APPS if a.startswith("noc.")}
# Fill templates
for app in args:
self.print("Creating skeleton for %s" % app)
......
......@@ -17,7 +17,7 @@ from noc.core.fileutils import read_file
class Command(BaseCommand):
help = "Display todo's left in code"
exclude = set(["commands/todos.py"])
exclude = {"commands/todos.py"}
def handle(self, *args, **options):
dirs = ["lib"] + [a[4:] for a in INSTALLED_APPS if a.startswith("noc.")]
......
......@@ -19,7 +19,7 @@ IR_FAIL = 0 # Fail on first conflict
IR_SKIP = 1 # Skip conflicted records
IR_UPDATE = 2 # Overwrite conflicted records
# Set of ignored fields
IGNORED_FIELDS = set(["id", "bi_id"])
IGNORED_FIELDS = {"id", "bi_id"}
def update_if_changed(obj, values):
......@@ -123,15 +123,13 @@ def csv_import(model, f, resolution=IR_FAIL, delimiter=","):
# Process model fields
field_names = set()
required_fields = set()
unique_fields = set([ff.name for ff in model._meta.fields if ff.unique])
unique_fields = {ff.name for ff in model._meta.fields if ff.unique}
fk = {} # Foreign keys: name->(model,field)
# find boolean fields
booleans = set([ff.name for ff in model._meta.fields if
isinstance(ff, models.BooleanField)])
integers = set([ff.name for ff in model._meta.fields if
isinstance(ff, models.IntegerField)])
booleans = {ff.name for ff in model._meta.fields if isinstance(ff, models.BooleanField)}
integers = {ff.name for ff in model._meta.fields if isinstance(ff, models.IntegerField)}
# Search for foreign keys and required fields
ir = set(["id", "bi_id"])
ir = {"id", "bi_id"}
ir.update(getattr(model, "csv_ignored_fields", []))
for name, required, rel, rname in get_model_fields(model):
field_names.add(name)
......
......@@ -24,7 +24,7 @@ from noc.core.http.client import fetch
from noc.core.perf import metrics
from .base import DCSBase, ResolverBase
ConsulRepearableCodes = set([500, 598, 599])
ConsulRepearableCodes = {500, 598, 599}
ConsulRepeatableErrors = consul.base.Timeout
CONSUL_CONNECT_TIMEOUT = config.consul.connect_timeout
......
......@@ -75,7 +75,7 @@ class BaseLoader(object):
# Discard records which cannot be dereferenced
discard_deferred = False
# Ignore auto-generated unique fields
ignore_unique = set(["bi_id"])
ignore_unique = {"bi_id"}
REPORT_INTERVAL = 1000
......
......@@ -55,7 +55,7 @@ DEFAULT_PORTS = {
}
# Methods require Content-Length header
REQUIRE_LENGTH_METHODS = set(["POST", "PUT"])
REQUIRE_LENGTH_METHODS = {"POST", "PUT"}
ns_lock = threading.Lock()
ns_cache = cachetools.TTLCache(NS_CACHE_SIZE, ttl=RESOLVER_TTL)
......
......@@ -87,7 +87,7 @@ class ProfileLoader(BaseLoader):
"""
Scan all available profiles
"""
ns = set([GENERIC_PROFILE])
ns = {GENERIC_PROFILE}
for px in config.get_customized_paths(os.path.join("sa", "profiles"), prefer_custom=True):
px = os.path.join(px, "*", "*", "__init__.py")
for path in glob.glob(px):
......
......@@ -34,7 +34,7 @@ IAC_CMD = {
WONT: "WONT"
}
IGNORED_CMD = set([AO, AYT])
IGNORED_CMD = {AO, AYT}
TELNET_OPTIONS = {
0: "BINARY",
......
......@@ -94,7 +94,7 @@ def get_shortest_path(start, goal):
closed_set = set()
# Currently discovered nodes than are not evaluated yet.
# Start node is already known
open_set = set([start])
open_set = {start}
# For each node, which node it can most efficiently be reached from.
# If a node can be reached from many nodes, cameFrom will eventually contain the
# most efficient previous step.
......
......@@ -541,7 +541,7 @@ class ActiveAlarm(Document):
"""
Generator yielding all affected managed objects
"""
seen = set([self.managed_object])
seen = {self.managed_object}
yield self.managed_object
for a in self.iter_consequences():
if a.managed_object not in seen:
......
......@@ -162,7 +162,7 @@ class Address(Document):
#
RU_SHORT_AFTER = set([u"б-р", u"проезд", u"пер", u"ш"])
RU_SHORT_AFTER = {u"б-р", u"проезд", u"пер", u"ш"}
# Signals
post_save.connect(Address.update_primary, sender=Address)
......@@ -259,7 +259,7 @@ class NetworkSegment(Document):
def get_siblings(self, seen=None):
seen = seen or set()
ss = set([self])
ss = {self}
seen |= ss
if self.sibling and self.sibling not in seen:
ss |= self.sibling.get_siblings(seen)
......
......@@ -66,14 +66,14 @@ class AuditTrail(Document):
changes = ListField(EmbeddedDocumentField(FieldChange))
expires = DateTimeField()
EXCLUDE = set([
EXCLUDE = {
"admin.logentry",
"main.audittrail",
"kb.kbentryhistory",
"kb.kbentrypreviewlog",
"sa.maptask",
"sa.reducetask",
])
}
DEFAULT_TTL = config.audit.db_ttl
_model_ttls = {}
......
......@@ -56,23 +56,23 @@ class Script(BaseScript):
slot_id = 0
IGNORED_SERIAL = set([
IGNORED_SERIAL = {
"H22L714"
])
}
IGNORED_NAMES = set([
IGNORED_NAMES = {
"c7201"
])
}
GBIC_MODULES = set([
GBIC_MODULES = {
"WS-X6K-SUP2-2GE",
"WS-X6724-SFP"
])
}
ISR_MB = set([
ISR_MB = {
"CISCO2801",
"CISCO2811"
])
}
def get_inv(self):
objects = []
......
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# Cisco.IOS.get_switchport
# ---------------------------------------------------------------------
# Copyright (C) 2007-2016 The NOC Project
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -167,8 +167,7 @@ class Script(BaseScript):
for p in self.get_description():
descriptions[p["interface"]] = p["description"]
# Get vlans
known_vlans = set([vlan["vlan_id"] for vlan in
self.scripts.get_vlans()])
known_vlans = {vlan["vlan_id"] for vlan in self.scripts.get_vlans()}
# For each interface
for s in self.rx_line.split(v)[1:]:
match = self.rx_body.search(s)
......
......@@ -49,12 +49,12 @@ class Script(BaseScript):
r"^cisco (?P<part_no>\S+) \(\S+\) processor( "
r"\(revision(?P<revision>.+?)\))? with",
re.IGNORECASE | re.MULTILINE)
IGNORED_SERIAL = set([
IGNORED_SERIAL = {
"H22L714"
])
IGNORED_NAMES = set([
}
IGNORED_NAMES = {
"c7201"
])
}
def clear_platform(self, platform):
"""
......
......@@ -34,10 +34,10 @@ class Script(BaseScript):
)
rx_trans = re.compile(r"((?:100|1000|10G)BASE\S+)")
# set of pids GEM modules w/o transceivers
gem_w_o_sfp = set([
gem_w_o_sfp = {
"N55-M160L3",
"N55-M160L3-V2"
])
}
def execute_cli(self):
objects = []
......
......@@ -2,11 +2,10 @@
# ---------------------------------------------------------------------
# Cisco.NXOS.get_switchport
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
"""
"""
# Python modules
import re
# NOC modules
......@@ -21,26 +20,32 @@ class Script(BaseScript):
rx_cont = re.compile(r",\s*$\s+", re.MULTILINE)
rx_line = re.compile(r"\n+Name:\s+", re.MULTILINE)
rx_body = re.compile(r"^(?P<interface>\S+).+"
"^ Switchport: .+"
"^ Switchport Monitor: .+"
"^ Operational Mode: (?P<omode>\S+).+"
"^ Access Mode VLAN: (?P<avlan>\d+) \(.+\).+"
"^ Trunking Native Mode VLAN: (?P<nvlan>\d+) \(.+\).+"
"^ Trunking VLANs Allowed: (?P<vlans>.+?)$",
# "Pruning VLANs Enabled:",
re.MULTILINE | re.DOTALL)
rx_body = re.compile(
r"^(?P<interface>\S+).+"
"^ Switchport: .+"
"^ Switchport Monitor: .+"
"^ Operational Mode: (?P<omode>\S+).+"
"^ Access Mode VLAN: (?P<avlan>\d+) \(.+\).+"
"^ Trunking Native Mode VLAN: (?P<nvlan>\d+) \(.+\).+"
"^ Trunking VLANs Allowed: (?P<vlans>.+?)$",
# "Pruning VLANs Enabled:",
re.MULTILINE | re.DOTALL
)
rx_body_name = re.compile(r"^(?P<interface>\S+).+", re.MULTILINE)
rx_body_omode = re.compile(
r"^Operational Mode: (?P<omode>\S+)\s*$", re.MULTILINE)
r"^Operational Mode: (?P<omode>\S+)\s*$", re.MULTILINE
)
rx_body_nvlan = re.compile(
r"^Trunking Native Mode VLAN: (?P<nvlan>\d+) \(.+\).+", re.MULTILINE)
r"^Trunking Native Mode VLAN: (?P<nvlan>\d+) \(.+\).+", re.MULTILINE
)
rx_descr_if = re.compile(r"^(?P<interface>\S+)\s+(?:up|down|admin down|deleted)\s+(?:up|down)\s+"
r"(?P<description>.+)")
rx_descr_if = re.compile(
r"^(?P<interface>\S+)\s+(?:up|down|admin down|deleted)\s+(?:up|down)\s+"
r"(?P<description>.+)"
)
def get_description(self):
r = []
......@@ -72,8 +77,7 @@ class Script(BaseScript):
for p in self.get_description():
descriptions[p["interface"]] = p["description"]
# Get vlans
known_vlans = set([vlan["vlan_id"] for vlan in
self.scripts.get_vlans()])
known_vlans = {vlan["vlan_id"] for vlan in self.scripts.get_vlans()}
# For each interface
for s in self.rx_line.split(v)[1:]:
match = self.rx_body.search(s)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment