Skip to content

Commit 909726d

Browse files
authored
Fixed regression caused by externally calling script. Discovered from netbox-community#76
1 parent 3002a97 commit 909726d

File tree

3 files changed

+5
-44
lines changed

3 files changed

+5
-44
lines changed

nb-dt-import.py

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,6 @@
1717
module_port_added=0,
1818
)
1919

20-
def get_files_modules(vendors=None):
21-
'''Get files list for modules.
22-
23-
Args:
24-
vendors: List of vendors to sync or None to sync all vendors.
25-
26-
Returns:
27-
A 2-tuple of:
28-
- list of filenames found
29-
- list of vendors found
30-
31-
'''
32-
33-
files = []
34-
discoveredVendors = []
35-
base_path = './repo/module-types/'
36-
if vendors:
37-
for r, d, f in os.walk(base_path):
38-
for folder in d:
39-
for vendor in vendors:
40-
if vendor.lower() == folder.lower():
41-
discoveredVendors.append({'name': folder,
42-
'slug': settings.dtl_repo.slug_format(folder)})
43-
for extension in settings.dtl_repo.yaml_extensions:
44-
files.extend(
45-
glob(
46-
base_path + folder + f'/*.{extension}'
47-
)
48-
)
49-
else:
50-
for r, d, f in os.walk(base_path):
51-
for folder in d:
52-
if folder.lower() != "Testing":
53-
discoveredVendors.append({'name': folder,
54-
'slug': settings.dtl_repo.slug_format(folder)})
55-
for extension in settings.dtl_repo.yaml_extensions:
56-
files.extend(glob(base_path + f'[!Testing]*/*.{extension}'))
57-
58-
return files, discoveredVendors
5920

6021
def read_yaml_modules(files, **kwargs):
6122

@@ -662,7 +623,7 @@ def main():
662623

663624
netbox = NetBox(settings)
664625
nb = netbox.get_api()
665-
files, vendors = settings.dtl_repo.get_devices('./repo/device-types/', args.vendors)
626+
files, vendors = settings.dtl_repo.get_devices(f'{settings.dtl_repo.repo_path}/device-types/', args.vendors)
666627

667628
settings.handle.log(f'{len(vendors)} Vendors Found')
668629
device_types = settings.dtl_repo.parse_files(files, slugs=args.slugs)
@@ -672,7 +633,7 @@ def main():
672633

673634
if netbox.modules:
674635
settings.handle.log("Modules Enabled. Creating Modules...")
675-
files, vendors = settings.dtl_repo.get_devices('./repo/module-types/', args.vendors)
636+
files, vendors = settings.dtl_repo.get_devices(f'{settings.dtl_repo.repo_path}/module-types/', args.vendors)
676637
settings.handle.log(f'{len(vendors)} Module Vendors Found')
677638
module_types = settings.dtl_repo.parse_files(files, slugs=args.slugs)
678639
settings.handle.log(f'{len(module_types)} Module-Types Found')

repo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, args, repo_path, exception_handler):
1414
self.url = args.url
1515
self.repo_path = repo_path
1616
self.branch = args.branch
17-
self.repo = Repo()
17+
self.repo = None
1818
self.cwd = os.getcwd()
1919

2020
if os.path.isdir(self.repo_path):

settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from repo import DTLRepo
55
from dotenv import load_dotenv
66
load_dotenv()
7-
7+
print()
88
REPO_URL = os.getenv("REPO_URL",
99
default="https://github.com/netbox-community/devicetype-library.git")
1010
REPO_BRANCH = os.getenv("REPO_BRANCH", default="master")
1111
NETBOX_URL = os.getenv("NETBOX_URL")
1212
NETBOX_TOKEN = os.getenv("NETBOX_TOKEN")
1313
IGNORE_SSL_ERRORS = (os.getenv("IGNORE_SSL_ERRORS", default="False") == "True")
14-
REPO_PATH = "./repo"
14+
REPO_PATH = f"{os.path.dirname(os.path.realpath(__file__))}/repo"
1515

1616
# optionally load vendors through a comma separated list as env var
1717
VENDORS = list(filter(None, os.getenv("VENDORS", "").split(",")))

0 commit comments

Comments
 (0)