1#!/usr/bin/python
2"""Reexecute parser in scenario and store the result at specified tag.
3"""
4
5import optparse, sys
6from os import path
7import common
8from autotest_lib.tko.parsers.test import scenario_base
9
10usage = 'usage: %prog [options] scenario_dirpath parser_result_tag'
11parser = optparse.OptionParser(usage=usage)
12
13
14def main():
15    (options, args) = parser.parse_args()
16    if len(args) < 2:
17        parser.print_help()
18        sys.exit(1)
19
20    scenario_dirpath = path.normpath(args[0])
21    parser_result_tag = args[1]
22
23    if not path.exists(scenario_dirpath) or not path.isdir(scenario_dirpath):
24        print 'Invalid scenarios_dirpath:', scenario_dirpath
25        parser.print_help()
26        sys.exit(1)
27
28    tempdir, results_dirpath = scenario_base.load_results_dir(scenario_dirpath)
29    harness = scenario_base.new_parser_harness(results_dirpath)
30    try:
31        parser_result = harness.execute()
32    except Exception, e:
33        parser_result = e
34    scenario_base.store_parser_result(
35        scenario_dirpath, parser_result, parser_result_tag)
36    tempdir.clean()
37
38
39if __name__ == '__main__':
40    main()
41