From 403b75a44e9c5ee7f4ba4e4455f6ef074dba0389 Mon Sep 17 00:00:00 2001 From: Philipp Rintz <13933258+p-rintz@users.noreply.github.com> Date: Tue, 7 Mar 2023 19:02:24 +0100 Subject: [PATCH 1/2] Remove Repo init from __init__ Initializing the repository from init, before the path has been updated, will lead to various errors when the script is not run directly from the repository. --- gitcmd.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gitcmd.py b/gitcmd.py index 0a6e05b7..36fcfc4d 100644 --- a/gitcmd.py +++ b/gitcmd.py @@ -11,7 +11,6 @@ def __init__(self, args, repo_path): self.url = args.url self.repo_path = repo_path self.branch = args.branch - self.repo = Repo() self.cwd = os.getcwd() if os.path.isdir(self.repo_path): From 5d5d916ae3324aa2460596480c2291c1cde5cfc8 Mon Sep 17 00:00:00 2001 From: "Daniel W. Anner" Date: Tue, 7 Mar 2023 23:53:12 +0000 Subject: [PATCH 2/2] Implemented fix that will allow for running script from any directory --- gitcmd.py | 2 +- nb-dt-import.py | 4 ++-- settings.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gitcmd.py b/gitcmd.py index 36fcfc4d..c1924695 100644 --- a/gitcmd.py +++ b/gitcmd.py @@ -11,6 +11,7 @@ def __init__(self, args, repo_path): self.url = args.url self.repo_path = repo_path self.branch = args.branch +# self.repo = Repo() self.cwd = os.getcwd() if os.path.isdir(self.repo_path): @@ -42,4 +43,3 @@ def clone_repo(self): settings.handle.exception("GitCommandError", self.url, git_error) except Exception as git_error: settings.handle.exception("Exception", 'Git Repository Error', git_error) - diff --git a/nb-dt-import.py b/nb-dt-import.py index 7cfa93d0..7e55e171 100755 --- a/nb-dt-import.py +++ b/nb-dt-import.py @@ -53,7 +53,7 @@ def getFiles(vendors=None): files = [] discoveredVendors = [] - base_path = './repo/device-types/' + base_path = f'{settings.REPO_PATH}/device-types/' if vendors: for r, d, f in os.walk(base_path): for folder in d: @@ -88,7 +88,7 @@ def get_files_modules(vendors=None): files = [] discoveredVendors = [] - base_path = './repo/module-types/' + base_path = f'{settings.REPO_PATH}/module-types/' if vendors: for r, d, f in os.walk(base_path): for folder in d: diff --git a/settings.py b/settings.py index 4a4ef56b..22902a63 100644 --- a/settings.py +++ b/settings.py @@ -12,7 +12,7 @@ NETBOX_URL = os.getenv("NETBOX_URL") NETBOX_TOKEN = os.getenv("NETBOX_TOKEN") IGNORE_SSL_ERRORS = (os.getenv("IGNORE_SSL_ERRORS", default="False") == "True") -REPO_PATH = "./repo" +REPO_PATH = f"{os.path.dirname(os.path.realpath(__file__))}/repo" # optionally load vendors through a comma separated list as env var VENDORS = list(filter(None, os.getenv("VENDORS", "").split(",")))