1212from . import parser_add_verbose ,parser_lab_location ,load_snapshot
1313from .external_commands import set_ansible_flags
1414from . import ansible
15- from ..utils import log
15+ from ..utils import log , files as _files
1616
1717#
1818# CLI parser for 'netlab config' command
@@ -35,14 +35,21 @@ def custom_config_parse(args: typing.List[str]) -> typing.Tuple[argparse.Namespa
3535
3636 return parser .parse_known_args (args )
3737
38+ def path_exists (c_path : str ) -> bool :
39+ return bool (
40+ os .path .isdir (c_path ) or
41+ os .path .exists (c_path + '.j2' ) or
42+ glob .glob (c_path + '.*.j2' ))
43+
3844def template_sanity_check (template : str , topology : Box , verbose : bool ) -> bool :
45+ if template .startswith ("/" ): # Absolute path specified as the template name?
46+ return path_exists (template )
47+
3948 for path in topology .defaults .paths .custom .dirs :
4049 c_path = path + "/" + template
4150 if verbose :
4251 print (f"Looking for { c_path } " )
43- if os .path .isdir (c_path ) or \
44- os .path .exists (c_path + '.j2' ) or \
45- glob .glob (c_path + '.*.j2' ):
52+ if path_exists (c_path ):
4653 return True
4754
4855 return False
@@ -55,6 +62,9 @@ def run(cli_args: typing.List[str]) -> None:
5562 topology = load_snapshot (args )
5663
5764 if args .template != '-' :
65+ if args .template [0 ] in "~/." : # Change directory references into absolute path
66+ args .template = str (_files .absolute_path (args .template ))
67+
5868 if template_sanity_check (args .template ,topology ,args .verbose ):
5969 rest = ['-e' ,'config=' + args .template ] + rest
6070 else :
0 commit comments