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 19import shutil 20 21 22def main(): 23 parser = argparse.ArgumentParser() 24 parser.add_argument('--source-dir', nargs='+', help='', required=True) 25 parser.add_argument('--output-dir', help='', required=True) 26 args = parser.parse_args() 27 28 str_out_basename = os.path.basename(args.output_dir) 29 if (str_out_basename == "backup" and not os.path.exists(args.output_dir)): 30 os.mkdir(args.output_dir) 31 32 # move source dir 33 for source in args.source_dir: 34 print(source) 35 if os.path.exists(source): 36 output_path = None 37 if str_out_basename == "backup": 38 output_path = os.path.join( 39 args.output_dir, os.path.basename(source)) 40 if str_out_basename == "restore": 41 output_path = args.output_dir.replace( 42 str_out_basename, os.path.basename(source)) 43 if str_out_basename == "restore_symbols": 44 asan_symbols_path = args.output_dir.replace( 45 str_out_basename, os.path.basename(source)) 46 asan_symbols_backup_path = source.replace(os.path.basename( 47 source), os.path.join(os.path.basename(source), "asan")) 48 shutil.move(asan_symbols_path, asan_symbols_backup_path) 49 output_path = asan_symbols_path 50 if output_path is not None: 51 print("Move:{},To:{}".format(source, output_path)) 52 shutil.move(source, output_path) 53 54 return 0 55 56 57if __name__ == '__main__': 58 sys.exit(main()) 59