15f9996aaSopenharmony_ci#!/usr/bin/env python 25f9996aaSopenharmony_ci# -*- coding: utf-8 -*- 35f9996aaSopenharmony_ci# Copyright (c) 2021 Huawei Device Co., Ltd. 45f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 55f9996aaSopenharmony_ci# you may not use this file except in compliance with the License. 65f9996aaSopenharmony_ci# You may obtain a copy of the License at 75f9996aaSopenharmony_ci# 85f9996aaSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 95f9996aaSopenharmony_ci# 105f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 115f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 125f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135f9996aaSopenharmony_ci# See the License for the specific language governing permissions and 145f9996aaSopenharmony_ci# limitations under the License. 155f9996aaSopenharmony_ci 165f9996aaSopenharmony_ciimport sys 175f9996aaSopenharmony_ciimport os 185f9996aaSopenharmony_ciimport argparse 195f9996aaSopenharmony_ciimport shutil 205f9996aaSopenharmony_ci 215f9996aaSopenharmony_ci 225f9996aaSopenharmony_cidef main(): 235f9996aaSopenharmony_ci parser = argparse.ArgumentParser() 245f9996aaSopenharmony_ci parser.add_argument('--source-dir', nargs='+', help='', required=True) 255f9996aaSopenharmony_ci parser.add_argument('--output-dir', help='', required=True) 265f9996aaSopenharmony_ci args = parser.parse_args() 275f9996aaSopenharmony_ci 285f9996aaSopenharmony_ci str_out_basename = os.path.basename(args.output_dir) 295f9996aaSopenharmony_ci if (str_out_basename == "backup" and not os.path.exists(args.output_dir)): 305f9996aaSopenharmony_ci os.mkdir(args.output_dir) 315f9996aaSopenharmony_ci 325f9996aaSopenharmony_ci # move source dir 335f9996aaSopenharmony_ci for source in args.source_dir: 345f9996aaSopenharmony_ci print(source) 355f9996aaSopenharmony_ci if os.path.exists(source): 365f9996aaSopenharmony_ci output_path = None 375f9996aaSopenharmony_ci if str_out_basename == "backup": 385f9996aaSopenharmony_ci output_path = os.path.join( 395f9996aaSopenharmony_ci args.output_dir, os.path.basename(source)) 405f9996aaSopenharmony_ci if str_out_basename == "restore": 415f9996aaSopenharmony_ci output_path = args.output_dir.replace( 425f9996aaSopenharmony_ci str_out_basename, os.path.basename(source)) 435f9996aaSopenharmony_ci if str_out_basename == "restore_symbols": 445f9996aaSopenharmony_ci asan_symbols_path = args.output_dir.replace( 455f9996aaSopenharmony_ci str_out_basename, os.path.basename(source)) 465f9996aaSopenharmony_ci asan_symbols_backup_path = source.replace(os.path.basename( 475f9996aaSopenharmony_ci source), os.path.join(os.path.basename(source), "asan")) 485f9996aaSopenharmony_ci shutil.move(asan_symbols_path, asan_symbols_backup_path) 495f9996aaSopenharmony_ci output_path = asan_symbols_path 505f9996aaSopenharmony_ci if output_path is not None: 515f9996aaSopenharmony_ci print("Move:{},To:{}".format(source, output_path)) 525f9996aaSopenharmony_ci shutil.move(source, output_path) 535f9996aaSopenharmony_ci 545f9996aaSopenharmony_ci return 0 555f9996aaSopenharmony_ci 565f9996aaSopenharmony_ci 575f9996aaSopenharmony_ciif __name__ == '__main__': 585f9996aaSopenharmony_ci sys.exit(main()) 59