mirror of
https://github.com/netbox-community/devicetype-library.git
synced 2024-12-25 00:19:44 +01:00
7ab7852a3b
* Migrated device slugs for 3com * Migrated device slugs for A10 * migrating manufacturers slugs * Migrated device slugs for AVM * Migrated device slugs for Avocent * Migrated device slugs for Brocade * Migrated device slugs for Calix * Migrated device slugs for Checkpoint * Migrated device slugs for more Checkpoint files * Migrated device slugs for Ciena * Migrated device slugs for Citrix * Migrated device slugs for Colable * Migrated device slugs for Corning * Migrated device slugs for CryptoPro * Migrated device slugs for CyberPower * Migrated device slugs for Datacom * Migrating slug definition for manufacturer Deciso * Migrating slug definition for manufacturer Dell * Migrating slug definition for manufacturer Extreme Networks * Migrating slug definition for manufacturer F5 * Migrating slug definition for manufacturer Fortinet * Migrating slug definition for manufacturer FS * Migrating slug definition for manufacturer Generic * Migrating slug definition for manufacturer Huawei * Migrating slug definition for manufacturer LANCOM * Migrating slug definition for manufacturer Lenovo * Migrating slug definition for manufacturer Mikrotik * Migrating slug definition for manufacturer Opengear * Migrating slug definition for manufacturer Palo Alto * Migrating slug definition for manufacturer Panduit * Migrating slug definition for manufacturer QNAP * Migrating slug definition for manufacturer Rockwell Automation * Migrating slug definition for manufacturer Ubiquiti * Migrating slug definition for manufacturer Yamaha * Migrating slug definition for manufacturer WTI * Migrating slug definition for manufacturers * Migrating slug definition for manufacturer Rohde & Schwarz * fixing double slugs and file names * fixing slug names to match proper format * fixing slug names to match proper format * fixing slugs to match proper format * fixing slugs to match proper format for Nokia. Also fixed file names for elevation images. * fixing slugs to match proper format * fixing slugs to match proper format * fixing slugs to match proper format for manufacturer Cisco * fixing slugs to match proper format for manufacturer MikroTik * fixing slugs to match proper format for manufacturer Ubiquiti * adding sloppy script used to migrate files
81 lines
3.7 KiB
Python
81 lines
3.7 KiB
Python
from os import walk, path
|
|
import yaml
|
|
|
|
root_dir = f"{path.dirname(path.realpath(__file__))}/../device-types"
|
|
# root_dir = f"{path.dirname(path.realpath(__file__))}/../device-types/Cisco"
|
|
|
|
total = 0
|
|
|
|
for root, dirs, files in walk(root_dir):
|
|
for file in files:
|
|
if file.split(".")[1] == "yaml" or file.split(".")[1] == "yml":
|
|
fileChanged = False
|
|
data = []
|
|
with open(path.join(root, file), 'r') as stream:
|
|
try:
|
|
data = stream.readlines()
|
|
# data = yaml.safe_load(stream)
|
|
|
|
slugManufacturer = ""
|
|
slugManufacturerIDX = 0
|
|
slug = ""
|
|
slugIDX = 0
|
|
model = ""
|
|
modelIDX = 0
|
|
partNumber = ""
|
|
partNumberIDX = 0
|
|
|
|
for idx, line in enumerate(data):
|
|
if "manufacturer: " in line:
|
|
# slugManufacturer = data['manufacturer'].casefold().replace(" ", "-")
|
|
slugManufacturer = line.split(": ")[1].casefold().replace(" ", "-").strip()
|
|
slugManufacturerIDX = idx
|
|
if "slug: " in line:
|
|
slug = line.split(": ")[1].strip()
|
|
slugIDX = idx
|
|
if "model: " in line:
|
|
model = line.split(": ")[1].strip()
|
|
modelIDX = idx
|
|
if "part_number: " in line:
|
|
partNumber = line.split(": ")[1].strip()
|
|
partNumberIDX = idx
|
|
|
|
transformedModel = model.casefold().replace(" ", "-").replace("sfp+", "sfpp").replace("poe+", "poep").replace("-+", "-plus").replace("+", "-plus-").replace("_", "-").replace("&", "-and-").replace("!", "").replace("/", "-").replace(",", "").replace("'", "").replace("*", "-")
|
|
transformedPartNumber = partNumber.casefold().replace(" ", "-").replace("-+", "-plus").replace("+", "-plus-").replace("_", "-").replace("&", "-and-").replace("!", "").replace("/", "-").replace(",", "").replace("'", "").replace("*", "-")
|
|
transformedManufacturer = slugManufacturer.casefold().replace(" ", "-").replace("sfp+", "sfpp").replace("poe+", "poep").replace("-+", "-plus-").replace("+", "-plus").replace("_", "-").replace("!", "").replace("/", "-").replace(",", "").replace("'", "").replace("*", "-")
|
|
|
|
if "&" in transformedManufacturer:
|
|
transformedManufacturer = transformedManufacturer.replace("&", "-and-")
|
|
if "--and--" in transformedManufacturer:
|
|
transformedManufacturer = transformedManufacturer.replace("--and--", "-and-")
|
|
|
|
newSlug = f"{transformedManufacturer}-{transformedModel}"
|
|
newPartSlug = f"{slugManufacturer}-{transformedPartNumber}"
|
|
newComboSlug = f"{slugManufacturer}-{transformedModel}-{transformedPartNumber}"
|
|
slugManufacturerDash = f"{slugManufacturer}-"
|
|
if slugManufacturer != "apple":
|
|
if newSlug.count(slugManufacturerDash) > 1:
|
|
newSlug = newSlug.replace(f"{slugManufacturer}-", "", 1)
|
|
if newPartSlug.count(slugManufacturerDash) > 1:
|
|
newPartSlug = newPartSlug.replace(f"{slugManufacturer}-", "", 1)
|
|
if newComboSlug.count(slugManufacturerDash) > 1:
|
|
newComboSlug = newComboSlug.replace(f"{slugManufacturer}-", "", 1)
|
|
|
|
if newSlug[-1] == "-":
|
|
newSlug = newSlug[:-1]
|
|
if newSlug != slug and newPartSlug != slug and newComboSlug != slug:
|
|
print(f"{newSlug} != {slug}")
|
|
data[slugIDX] = f"slug: {newSlug}\n"
|
|
total = total + 1
|
|
fileChanged = True
|
|
|
|
except yaml.YAMLError as exc:
|
|
print(exc)
|
|
stream.close()
|
|
|
|
if fileChanged:
|
|
with open(path.join(root, file), 'w') as file:
|
|
file.writelines(data)
|
|
file.close()
|
|
|
|
print(f"Total Left: {total}") |