1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# 4# Copyright (c) 2020-2022 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17import argparse 18import os 19import sys 20 21 22def main(): 23 parser = argparse.ArgumentParser() 24 parser.add_argument( 25 '--long_path', help='Toybox cmd long path', required=True) 26 parser.add_argument( 27 '--out_dir', help='Build out directoty', required=True) 28 args = parser.parse_args() 29 30 out_dir = args.out_dir 31 bin_dir = os.path.join(out_dir, 'bin') 32 if not os.path.exists(bin_dir): 33 os.makedirs(bin_dir) 34 35 sbin_dir = os.path.join(out_dir, 'sbin') 36 if not os.path.exists(sbin_dir): 37 os.makedirs(sbin_dir) 38 39 usr_bin_dir = os.path.join(out_dir, 'usr', 'bin') 40 if not os.path.exists(usr_bin_dir): 41 os.makedirs(usr_bin_dir) 42 43 usr_sbin_dir = os.path.join(out_dir, 'usr', 'sbin') 44 if not os.path.exists(usr_sbin_dir): 45 os.makedirs(usr_sbin_dir) 46 47 # Making links by toybox long command. 48 target_link = args.long_path 49 if os.path.exists(target_link): 50 os.remove(target_link) 51 52 if target_link.find("usr") != -1: 53 os.symlink("../../bin/toybox", target_link) 54 if target_link.find("sbin") != -1: 55 os.symlink("../bin/toybox", target_link) 56 else: 57 os.symlink("toybox", target_link) 58 59 return 0 60 61 62if __name__ == '__main__': 63 sys.exit(main()) 64 65