blob: 6a9948d4c1e77fa06e162c177304b33903224e36 [file] [log] [blame]
Mike Frysingerd03e6b52019-08-03 12:49:01 -04001#!/usr/bin/python2
Shuqian Zhaocbe11cb2015-04-13 11:10:36 -07002
3# Copyright (c) 2015 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
7"""This script creates a whitelist of test attributes based on the 'suite' read
8from test control files.
9"""
10import argparse
11
12import common
13from autotest_lib.client.common_lib.cros import dev_server
14from autotest_lib.server.cros.dynamic_suite.suite import Suite
15
16
17def main():
18 """main script."""
19 # Parse filepath from cmd line.
20 parser = argparse.ArgumentParser(description='Create attribute whitelist.')
21 parser.add_argument('path', metavar='WHITELIST_FILE_PATH',
22 help='Path to the file whitelist is written to. E.g. '
23 './attribute_whitelist.txt')
24 args = parser.parse_args()
25
26 # Get all the suites from current test control files, and order them.
27 fs_getter = Suite.create_fs_getter(common.autotest_dir)
28 devserver = dev_server.ImageServer('')
29 suite_list = Suite.list_all_suites('', devserver, fs_getter)
30 suite_list.sort(key = str.lower)
31
32 # Parse attributes from suites, and write to a file
33 whitelist = ['suite:' + x for x in suite_list]
34 _WriteToFile(whitelist, args.path)
35
36
37def _WriteToFile(whitelist, path):
38 """"Write the whitelist to a file under the path.
39
40 The format of the file used here is a list, which can be easily read to a list
41 by using ast.literal_eval.
42
43 Args:
44 whitelist: a list contains all the allowed attributes.
45 path: path to the file.
46 """
47 with open(path, 'wb') as attr_file:
48 attr_file.write('\n'.join(whitelist))
49
50
51if __name__ == '__main__':
52 main()