1313counter = Counter (added = 0 , updated = 0 , manufacturer = 0 )
1414
1515
16- def update_package (path : str ):
16+ def update_package (path : str , branch : str ):
1717 try :
1818 repo = Repo (path )
1919 if repo .remotes .origin .url .endswith ('.git' ):
2020 repo .remotes .origin .pull ()
21+ repo .git .checkout (branch )
2122 print (f"Pulled Repo { repo .remotes .origin .url } " )
2223 except exc .InvalidGitRepositoryError :
2324 pass
@@ -387,12 +388,16 @@ def main():
387388
388389 VENDORS = settings .VENDORS
389390 REPO_URL = settings .REPO_URL
391+ REPO_BRANCH = settings .REPO_BRANCH
392+
390393
391394 parser = argparse .ArgumentParser (description = 'Import Netbox Device Types' )
392395 parser .add_argument ('--vendors' , nargs = '+' , default = VENDORS ,
393396 help = "List of vendors to import eg. apc cisco" )
394397 parser .add_argument ('--url' , '--git' , default = REPO_URL ,
395398 help = "Git URL with valid Device Type YAML files" )
399+ parser .add_argument ('--branch' , default = REPO_BRANCH ,
400+ help = "Git branch to use from repo" )
396401 args = parser .parse_args ()
397402
398403
@@ -402,7 +407,7 @@ def main():
402407 + f"updating { os .path .join (cwd , 'repo' )} " )
403408 update_package ('./repo' )
404409 else :
405- repo = Repo .clone_from (args .url , os .path .join (cwd , 'repo' ))
410+ repo = Repo .clone_from (args .url , os .path .join (cwd , 'repo' ), branch = args . branch )
406411 print (f"Package Installed { repo .remotes .origin .url } " )
407412 except exc .GitCommandError as error :
408413 print ("Couldn't clone {} ({})" .format (args .url , error ))
0 commit comments