mirror of
https://github.com/netbox-community/Device-Type-Library-Import.git
synced 2025-03-12 05:08:10 +01:00
Add branch support
Set default branch name of 'master' in settings.py and then checkout the branch as appropriate.
This commit is contained in:
parent
3aaf98bfe4
commit
bee2eb7776
@ -13,11 +13,12 @@ import settings
|
||||
counter = Counter(added=0, updated=0, manufacturer=0)
|
||||
|
||||
|
||||
def update_package(path: str):
|
||||
def update_package(path: str, branch: str):
|
||||
try:
|
||||
repo = Repo(path)
|
||||
if repo.remotes.origin.url.endswith('.git'):
|
||||
repo.remotes.origin.pull()
|
||||
repo.git.checkout(branch)
|
||||
print(f"Pulled Repo {repo.remotes.origin.url}")
|
||||
except exc.InvalidGitRepositoryError:
|
||||
pass
|
||||
@ -387,12 +388,16 @@ def main():
|
||||
|
||||
VENDORS = settings.VENDORS
|
||||
REPO_URL = settings.REPO_URL
|
||||
REPO_BRANCH = settings.REPO_BRANCH
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Import Netbox Device Types')
|
||||
parser.add_argument('--vendors', nargs='+', default=VENDORS,
|
||||
help="List of vendors to import eg. apc cisco")
|
||||
parser.add_argument('--url', '--git', default=REPO_URL,
|
||||
help="Git URL with valid Device Type YAML files")
|
||||
parser.add_argument('--branch', default=REPO_BRANCH,
|
||||
help="Git branch to use from repo")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
@ -402,7 +407,7 @@ def main():
|
||||
+ f"updating {os.path.join(cwd, 'repo')}")
|
||||
update_package('./repo')
|
||||
else:
|
||||
repo = Repo.clone_from(args.url, os.path.join(cwd, 'repo'))
|
||||
repo = Repo.clone_from(args.url, os.path.join(cwd, 'repo'), branch=args.branch)
|
||||
print(f"Package Installed {repo.remotes.origin.url}")
|
||||
except exc.GitCommandError as error:
|
||||
print("Couldn't clone {} ({})".format(args.url, error))
|
||||
|
@ -3,6 +3,7 @@ from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
REPO_URL = os.getenv("REPO_URL")
|
||||
REPO_BRANCH = os.getenv("REPO_BRANCH", 'master')
|
||||
NETBOX_URL = os.getenv("NETBOX_URL")
|
||||
NETBOX_TOKEN = os.getenv("NETBOX_TOKEN")
|
||||
IGNORE_SSL_ERRORS = (os.getenv("IGNORE_SSL_ERRORS", "False") == "True")
|
||||
|
Loading…
Reference in New Issue
Block a user