1414counter = Counter (added = 0 , updated = 0 , manufacturer = 0 )
1515
1616
17- def update_package (path : str ):
17+ def update_package (path : str , branch : str ):
1818 try :
1919 repo = Repo (path )
2020 if repo .remotes .origin .url .endswith ('.git' ):
2121 repo .remotes .origin .pull ()
22+ repo .git .checkout (branch )
2223 print (f"Pulled Repo { repo .remotes .origin .url } " )
2324 except exc .InvalidGitRepositoryError :
2425 pass
@@ -394,7 +395,9 @@ def main():
394395
395396 VENDORS = settings .VENDORS
396397 REPO_URL = settings .REPO_URL
398+
397399 SLUGS = settings .SLUGS
400+ REPO_BRANCH = settings .REPO_BRANCH
398401
399402 parser = argparse .ArgumentParser (description = 'Import Netbox Device Types' )
400403 parser .add_argument ('--vendors' , nargs = '+' , default = VENDORS ,
@@ -403,7 +406,8 @@ def main():
403406 help = "Git URL with valid Device Type YAML files" )
404407 parser .add_argument ('--slugs' , nargs = '+' , default = SLUGS ,
405408 help = "List of device-type slugs to import eg. ap4431 ws-c3850-24t-l" )
406-
409+ parser .add_argument ('--branch' , default = REPO_BRANCH ,
410+ help = "Git branch to use from repo" )
407411 args = parser .parse_args ()
408412
409413 try :
@@ -412,7 +416,7 @@ def main():
412416 + f"updating { os .path .join (cwd , 'repo' )} " )
413417 update_package ('./repo' )
414418 else :
415- repo = Repo .clone_from (args .url , os .path .join (cwd , 'repo' ))
419+ repo = Repo .clone_from (args .url , os .path .join (cwd , 'repo' ), branch = args . branch )
416420 print (f"Package Installed { repo .remotes .origin .url } " )
417421 except exc .GitCommandError as error :
418422 print ("Couldn't clone {} ({})" .format (args .url , error ))
0 commit comments