1 #!/usr/bin/python 2 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 8 from test control files. 9 """ 10 import argparse 11 12 import common 13 from autotest_lib.client.common_lib.cros import dev_server 14 from autotest_lib.server.cros.dynamic_suite.suite import Suite 15 16 17 def 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 37 def _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 51 if __name__ == '__main__': 52 main() 53