devicetype-library/scripts/fix-slugs.py

82 lines
3.7 KiB
Python
Raw Normal View History

Slug Migration (#1375) * 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
2023-05-22 22:38:34 +02:00
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)
Slug Migration (#1375) * 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
2023-05-22 22:38:34 +02:00
slugManufacturer = ""
slugManufacturerIDX = 0
slug = ""
slugIDX = 0
model = ""
modelIDX = 0
partNumber = ""
partNumberIDX = 0
Slug Migration (#1375) * 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
2023-05-22 22:38:34 +02:00
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("*", "-")
Slug Migration (#1375) * 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
2023-05-22 22:38:34 +02:00
if "&" in transformedManufacturer:
transformedManufacturer = transformedManufacturer.replace("&", "-and-")
if "--and--" in transformedManufacturer:
transformedManufacturer = transformedManufacturer.replace("--and--", "-and-")
Slug Migration (#1375) * 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
2023-05-22 22:38:34 +02:00
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)
Slug Migration (#1375) * 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
2023-05-22 22:38:34 +02:00
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}")