reduce_rtt_code.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/env python3
  2. # Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. # All Rights Reserved.
  4. # This program is OPEN SOURCE software: you can redistribute it and/or modify it
  5. # under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  6. # either version 1.0 of the License, or (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  8. # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the Phytium Public License for more details.
  10. # FilePath: reduce_rtt_cde.py
  11. # Date: 2021-10-14 08:19:30
  12. # LastEditTime: 2022-02-18 09:26:24
  13. # Description:  This files is for install phytiunm standalone sdk
  14. # Modify History:
  15. # Ver   Who        Date         Changes
  16. # ----- ------     --------    --------------------------------------
  17. # 1.0 zhugengyu 2023/1/12 init commit
  18. #
  19. # ./reduce_rtt_code.py -i=/mnt/d/proj/rt-thread/rt-thread-base -o=/mnt/d/proj/rt-thread/rt-thread-lite
  20. #
  21. import sys
  22. import os
  23. import argparse
  24. import shutil
  25. src_path = []
  26. dst_path = []
  27. dry_run = False #True
  28. def append_path(path):
  29. src_path.append(os.path.abspath(path))
  30. parser = argparse.ArgumentParser()
  31. parser.description='please enter two parameters <input-PATH> and <export-PATH> ...'
  32. parser.add_argument("-i", "--input", help="input PATH of RTT", type=str, default="./rt-thread")
  33. parser.add_argument("-o", "--output", help="export PATH for RTT", type=str, default="./rt-thread-lite")
  34. args = parser.parse_args()
  35. rtt_src_dir = os.path.abspath(args.input)
  36. rtt_dst_dir = os.path.abspath(args.output)
  37. os.chdir(rtt_src_dir) # change to rt-thread folder
  38. # append path and files need to reserve
  39. ## root
  40. append_path(r'./.git')
  41. append_path(r'./.gitee')
  42. append_path(r'./.github')
  43. append_path(r'./.gitattributes')
  44. append_path(r'./.gitignore')
  45. append_path(r'./ChangeLog.md')
  46. append_path(r'./Kconfig')
  47. append_path(r'./LICENSE')
  48. append_path(r'./README.md')
  49. append_path(r'./README_de.md')
  50. append_path(r'./README_es.md')
  51. append_path(r'./README_zh.md')
  52. ## bsp
  53. append_path(r'./bsp/phytium')
  54. ## components
  55. append_path(r'./components')
  56. ## examples
  57. append_path(r'./examples')
  58. ## include
  59. append_path(r'./include')
  60. ## libcpu
  61. append_path(r'./libcpu/Kconfig')
  62. append_path(r'./libcpu/SConscript')
  63. append_path(r'./libcpu/aarch64')
  64. append_path(r'./libcpu/arm')
  65. ## src
  66. append_path(r'./src')
  67. ## tools
  68. append_path(r'./tools')
  69. print('Source path ======')
  70. for path in src_path:
  71. print(path)
  72. print('====================')
  73. for path in src_path:
  74. dst_path.append(path.replace(rtt_src_dir, rtt_dst_dir))
  75. print('Destination path ======')
  76. for path in dst_path:
  77. print(path)
  78. print('====================')
  79. print('Total {} items'.format(len(src_path)))
  80. print('Current dir: {}'.format(os.getcwd()))
  81. if dry_run:
  82. for i in range(len(src_path)):
  83. print('copy {} to {}'.format(src_path[i], dst_path[i]))
  84. else:
  85. root_dir = r'.' + rtt_dst_dir
  86. if os.path.exists(root_dir):
  87. shutil.rmtree(root_dir)
  88. for i in range(len(src_path)):
  89. if os.path.exists(dst_path[i]):
  90. continue
  91. # do real copy !!!!
  92. if os.path.isdir(src_path[i]):
  93. shutil.copytree(src_path[i], dst_path[i])
  94. else:
  95. file_dir = os.path.dirname(dst_path[i])
  96. if not os.path.exists(file_dir):
  97. os.mkdir(file_dir)
  98. shutil.copyfile(src_path[i], dst_path[i])
  99. os.chdir(rtt_dst_dir) # change to rt-thread folder