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