Michael Walsh | a2a553c | 2017-01-10 11:17:38 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | This module is the python counterpart to run_keyword.robot. |
| 5 | """ |
| 6 | |
| 7 | import gen_print as gp |
| 8 | import gen_robot_print as grp |
| 9 | import gen_robot_valid as grv |
| 10 | |
| 11 | from robot.libraries.BuiltIn import BuiltIn |
| 12 | |
| 13 | |
| 14 | ############################################################################### |
| 15 | def main_py(): |
| 16 | |
| 17 | r""" |
| 18 | Do main program processing. |
| 19 | """ |
| 20 | |
| 21 | setup() |
| 22 | |
| 23 | keyword_string = BuiltIn().get_variable_value("${keyword_string}") |
| 24 | lib_file_path = BuiltIn().get_variable_value("${lib_file_path}") |
| 25 | |
| 26 | cmd_buf = keyword_string.split(" ") |
| 27 | |
| 28 | if lib_file_path != "": |
| 29 | # We don't want global variable getting changed when an import is done |
| 30 | # so we'll save it and restore it. |
| 31 | quiet = int(BuiltIn().get_variable_value("${quiet}")) |
| 32 | if lib_file_path.endswith(".py"): |
| 33 | grp.rdprint_issuing("import_library(\"" + lib_file_path + "\")") |
| 34 | BuiltIn().import_library(lib_file_path) |
| 35 | else: |
| 36 | grp.rdprint_issuing("import_resource(\"" + lib_file_path + "\")") |
| 37 | BuiltIn().import_resource(lib_file_path) |
| 38 | BuiltIn().set_global_variable("${quiet}", quiet) |
| 39 | |
| 40 | error_message = grp.sprint_error_report("Keyword \"" + cmd_buf[0] + |
| 41 | "\" does not exist.\n") |
| 42 | BuiltIn().keyword_should_exist(cmd_buf[0], msg=error_message) |
| 43 | |
| 44 | grp.rqprint_issuing_keyword(cmd_buf) |
| 45 | status, output = BuiltIn().run_keyword_and_ignore_error(*cmd_buf) |
| 46 | if status != "PASS": |
| 47 | error_message = grp.sprint_error_report("\"" + cmd_buf[0] + |
| 48 | "\" failed with the" + |
| 49 | " following error:\n" + output) |
| 50 | if not quiet: |
| 51 | grp.rprint(error_message, 'STDERR') |
| 52 | BuiltIn().fail(error_message) |
| 53 | |
| 54 | if output is not None: |
| 55 | grp.rprint(output) |
| 56 | |
| 57 | ############################################################################### |
| 58 | |
| 59 | |
| 60 | ############################################################################### |
| 61 | def setup(): |
| 62 | |
| 63 | r""" |
| 64 | Do general program setup tasks. |
| 65 | """ |
| 66 | |
| 67 | grp.rqprintn() |
| 68 | |
| 69 | validate_parms() |
| 70 | |
| 71 | grp.rqprint_pgm_header() |
| 72 | |
| 73 | ############################################################################### |
| 74 | |
| 75 | |
| 76 | ############################################################################### |
| 77 | def validate_parms(): |
| 78 | |
| 79 | r""" |
| 80 | Validate all program parameters. |
| 81 | """ |
| 82 | |
| 83 | grv.rvalid_value("keyword_string") |
| 84 | |
| 85 | return True |
| 86 | |
| 87 | ############################################################################### |
| 88 | |
| 89 | |
| 90 | ############################################################################### |
| 91 | def program_teardown(): |
| 92 | |
| 93 | r""" |
| 94 | Clean up after this program. |
| 95 | """ |
| 96 | |
| 97 | grp.rqprint_pgm_footer() |
| 98 | |
| 99 | ############################################################################### |