10f66f451Sopenharmony_ci#!/usr/bin/env python 20f66f451Sopenharmony_ci# -*- coding: utf-8 -*- 30f66f451Sopenharmony_ci# 40f66f451Sopenharmony_ci# Copyright (c) 2020-2022 Huawei Device Co., Ltd. 50f66f451Sopenharmony_ci# 60f66f451Sopenharmony_ciimport argparse 70f66f451Sopenharmony_ciimport os 80f66f451Sopenharmony_ciimport sys 90f66f451Sopenharmony_ci 100f66f451Sopenharmony_ci 110f66f451Sopenharmony_cidef main(): 120f66f451Sopenharmony_ci parser = argparse.ArgumentParser() 130f66f451Sopenharmony_ci parser.add_argument( 140f66f451Sopenharmony_ci '--long_path', help='Toybox cmd long path', required=True) 150f66f451Sopenharmony_ci parser.add_argument( 160f66f451Sopenharmony_ci '--out_dir', help='Build out directoty', required=True) 170f66f451Sopenharmony_ci args = parser.parse_args() 180f66f451Sopenharmony_ci 190f66f451Sopenharmony_ci out_dir = args.out_dir 200f66f451Sopenharmony_ci bin_dir = os.path.join(out_dir, 'bin') 210f66f451Sopenharmony_ci if not os.path.exists(bin_dir): 220f66f451Sopenharmony_ci os.makedirs(bin_dir) 230f66f451Sopenharmony_ci 240f66f451Sopenharmony_ci sbin_dir = os.path.join(out_dir, 'sbin') 250f66f451Sopenharmony_ci if not os.path.exists(sbin_dir): 260f66f451Sopenharmony_ci os.makedirs(sbin_dir) 270f66f451Sopenharmony_ci 280f66f451Sopenharmony_ci usr_bin_dir = os.path.join(out_dir, 'usr', 'bin') 290f66f451Sopenharmony_ci if not os.path.exists(usr_bin_dir): 300f66f451Sopenharmony_ci os.makedirs(usr_bin_dir) 310f66f451Sopenharmony_ci 320f66f451Sopenharmony_ci usr_sbin_dir = os.path.join(out_dir, 'usr', 'sbin') 330f66f451Sopenharmony_ci if not os.path.exists(usr_sbin_dir): 340f66f451Sopenharmony_ci os.makedirs(usr_sbin_dir) 350f66f451Sopenharmony_ci 360f66f451Sopenharmony_ci # Making links by toybox long command. 370f66f451Sopenharmony_ci target_link = args.long_path 380f66f451Sopenharmony_ci if os.path.exists(target_link): 390f66f451Sopenharmony_ci os.remove(target_link) 400f66f451Sopenharmony_ci elif os.path.islink(target_link): 410f66f451Sopenharmony_ci os.unlink(target_link) 420f66f451Sopenharmony_ci 430f66f451Sopenharmony_ci if target_link.find("usr") != -1: 440f66f451Sopenharmony_ci os.symlink("../../bin/toybox", target_link) 450f66f451Sopenharmony_ci if target_link.find("sbin") != -1: 460f66f451Sopenharmony_ci os.symlink("../bin/toybox", target_link) 470f66f451Sopenharmony_ci else: 480f66f451Sopenharmony_ci os.symlink("toybox", target_link) 490f66f451Sopenharmony_ci 500f66f451Sopenharmony_ci return 0 510f66f451Sopenharmony_ci 520f66f451Sopenharmony_ci 530f66f451Sopenharmony_ciif __name__ == '__main__': 540f66f451Sopenharmony_ci sys.exit(main()) 550f66f451Sopenharmony_ci 56