1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2021 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import sys 17import os 18import argparse 19 20sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 21from scripts.util.file_utils import write_file # noqa E402 22 23 24def main() -> int: 25 parser = argparse.ArgumentParser() 26 parser.add_argument('--base-dir', required=True) 27 parser.add_argument('--sub-dir-list', nargs='+', required=False) 28 parser.add_argument('--result-file', required=False) 29 args = parser.parse_args() 30 31 file_list = [] 32 dir_list = [] 33 if args.sub_dir_list: 34 for sub_dir in args.sub_dir_list: 35 dir_list.append(os.path.join(args.base_dir, sub_dir)) 36 else: 37 dir_list.append(args.base_dir) 38 for _dir in dir_list: 39 if not os.path.exists(_dir): 40 continue 41 for root, _, files in os.walk(_dir): 42 for _file in files: 43 file_list.append(os.path.realpath(os.path.join(root, _file))) 44 45 if args.result_file: 46 write_file(args.result_file, "\n".join(file_list)) 47 else: 48 for _file in file_list: 49 print(_file) 50 return 0 51 52 53if __name__ == '__main__': 54 sys.exit(main()) 55