def test_ast_item_to_string(): strings = ( '# some command file', '', 'write /tgt/file:data\\\nmore data\\\neven more data', 'copy /some/data.dat:/var/lib/data.dat', 'root-password password:some-password', 'run /some/script.sh', ) for string in strings: items = tuple(lines_to_ast(StringIO(string + '\n'))) assert len(items) == 1 item = items[0] assert ast_item_to_string(item) == string
def check_command_file(cmd_file): """Helper tool to writing complex virt-* command files Read the given command file, attempt to perform all file inclusions and emdebbed script execution and yeild the resulting composit command file :param str cmd_file: The command file to check """ ast = tuple(perform_ast_includes(file_to_ast(expanduser(cmd_file)))) for used_file in ast_to_used_files(ast): used_file_path = find_included_file(used_file.path, used_file.context) if not exists(used_file_path): abort('File "{0}" included from "{1}" line {2} not found!'.format( used_file.path, used_file.context.file, used_file.context.line )) for item in ast: puts(ast_item_to_string(item))