summaryrefslogtreecommitdiff
path: root/bsp/phytium/tools/reduce_rtt_code.py
blob: e2c1ec5d62ee319f1d98e51cc3d38bee8dab88e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
# Copyright : (C) 2022 Phytium Information Technology, Inc. 
# All Rights Reserved.
 
# This program is OPEN SOURCE software: you can redistribute it and/or modify it  
# under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,  
# either version 1.0 of the License, or (at your option) any later version. 
 
# This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;  
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the Phytium Public License for more details. 
 
# FilePath: reduce_rtt_cde.py
# Date: 2021-10-14 08:19:30
# LastEditTime: 2022-02-18 09:26:24
# Description:  This files is for install phytiunm standalone sdk

# Modify History: 
#  Ver   Who        Date         Changes
# ----- ------     --------    --------------------------------------
# 1.0   zhugengyu  2023/1/12   init commit

#
# ./reduce_rtt_code.py -i=/mnt/d/proj/rt-thread/rt-thread-base -o=/mnt/d/proj/rt-thread/rt-thread-lite
#


import sys
import os
import argparse
import shutil

src_path = []
dst_path = []

dry_run = False #True

def append_path(path):
    src_path.append(os.path.abspath(path))

parser = argparse.ArgumentParser()
parser.description='please enter two parameters <input-PATH> and <export-PATH> ...'
parser.add_argument("-i", "--input", help="input PATH of RTT", type=str, default="./rt-thread")
parser.add_argument("-o", "--output", help="export PATH for RTT",  type=str, default="./rt-thread-lite")
args = parser.parse_args()

rtt_src_dir = os.path.abspath(args.input)
rtt_dst_dir = os.path.abspath(args.output)

os.chdir(rtt_src_dir) # change to rt-thread folder

# append path and files need to reserve

## root
append_path(r'./.git')
append_path(r'./.gitee')
append_path(r'./.github')
append_path(r'./.gitattributes')
append_path(r'./.gitignore')
append_path(r'./ChangeLog.md')
append_path(r'./Kconfig')
append_path(r'./LICENSE')
append_path(r'./README.md')
append_path(r'./README_de.md')
append_path(r'./README_es.md')
append_path(r'./README_zh.md')

## bsp
append_path(r'./bsp/phytium')

## components
append_path(r'./components')

## examples
append_path(r'./examples')

## include
append_path(r'./include')

## libcpu
append_path(r'./libcpu/Kconfig')
append_path(r'./libcpu/SConscript')
append_path(r'./libcpu/aarch64')
append_path(r'./libcpu/arm')

## src
append_path(r'./src')

## tools
append_path(r'./tools')

print('Source path ======')
for path in src_path:
    print(path)
print('====================')

for path in src_path:
    dst_path.append(path.replace(rtt_src_dir, rtt_dst_dir))

print('Destination path ======')
for path in dst_path:
    print(path)
print('====================')

print('Total {} items'.format(len(src_path)))
print('Current dir: {}'.format(os.getcwd()))

if dry_run:
    for i in range(len(src_path)):
        print('copy {} to {}'.format(src_path[i], dst_path[i]))           
else:
    root_dir = r'.' + rtt_dst_dir
    if os.path.exists(root_dir):
        shutil.rmtree(root_dir)

    for i in range(len(src_path)):
        if os.path.exists(dst_path[i]):
            continue

        # do real copy !!!!
        if os.path.isdir(src_path[i]):
            shutil.copytree(src_path[i], dst_path[i])
        else:
            file_dir = os.path.dirname(dst_path[i])
            if not os.path.exists(file_dir):
                os.mkdir(file_dir)
            shutil.copyfile(src_path[i], dst_path[i])


    os.chdir(rtt_dst_dir) # change to rt-thread folder