blob: cd4def42f7a85ded6e88cffa1cc2566654ea5eea [file] [log] [blame]
Keyar Hood01e1d9e2013-08-13 15:29:30 -07001#!/usr/bin/python
2#
3# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import logging, os, subprocess, sys
8
9THIS_DIR = os.path.dirname(__file__)
10UTILS_DIR = os.path.abspath(os.path.join(THIS_DIR, os.pardir, os.pardir,
11 'utils'))
12TEST_IMPORTER = os.path.join(UTILS_DIR, 'test_importer.py')
13
14# The list of scripts are passed as lists as this allows us to add arguments
15# as the list is just passed to subprocess.call(). We expect the scripts to
16# return 0 on success and a non-zero value on failure.
17
18# Scripts that need to be ran first to do any preperation. E.g. update the
19# database.
20PREP_SCRIPTS = [
21 [TEST_IMPORTER]
22 ]
23
24COMPLETE_FAILURES = os.path.join(THIS_DIR, 'complete_failures.py')
25PASSING_EXPERIMENTAL = os.path.join(THIS_DIR, 'passing_experimental.py')
26# Scripts ran to do the analysis.
27ANALYSIS_SCRIPTS = [
28 [COMPLETE_FAILURES],
29 [PASSING_EXPERIMENTAL]
30 ]
31
32
33def run_prep_scripts(scripts):
34 """
35 Run the scripts that are required to be ran before the analysis.
36
37 This stops and returns False at the first script failure.
38
39 @param scripts: A list of lists. Where the inner list is the script name
40 and arguments to be called (as subprocess.call() expects).
41
42 @return True if all the scripts succeeded and False otherwise.
43
44 """
45
46 for script in scripts:
47 logging.info('Running %s', ' '.join(script))
48 return_code = subprocess.call(script)
49 if return_code != 0:
50 logging.error('\'%s\' failed with return code %d',
51 (' '.join(script), return_code))
52 return False
53
54 return True
55
56
57def run_analysis_scripts(scripts):
58 """
59 Run the scripts that analyze the database.
60
61 All scripts are ran even if one fails.
62
63 @param scripts: A list of lists, where the inner list is the script name
64 and arguments to be called (as subprocess.call() expects).
65
66 @return True if all the scripts succeeded and False otherwise.
67
68 """
69
70 success = True
71
72 for script in scripts:
73 logging.info('Running %s', ' '.join(script))
74 return_code = subprocess.call(script)
75 if return_code != 0:
76 logging.error('\'%s\' failed with return code %d',
77 (' '.join(script), return_code))
78 success = False
79
80 return success
81
82
83def main():
84 """
85 The main function.
86
87 This allows us to test this function by calling it in the unit test file.
88
89 @return 0 if everything succeeded and a non-zero integer otherwise.
90
91 """
92
93 logging.getLogger().setLevel(logging.INFO)
94
95 prep_success = run_prep_scripts(PREP_SCRIPTS)
96 if not prep_success:
97 return 1
98
99 analysis_success = run_analysis_scripts(ANALYSIS_SCRIPTS)
100 if not analysis_success:
101 return 1
102
103 return 0
104
105
106if __name__ == '__main__':
107 sys.exit(main())