forked from overtake/Telegram-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_wallet_source.py
91 lines (75 loc) · 2.73 KB
/
extract_wallet_source.py
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
import sys
import os
import json
import re
import shutil
def get_file_list(dir):
result_files = []
result_dirs = []
for root, dirs, files in os.walk(dir, topdown=False):
for name in files:
result_files.append(os.path.relpath(os.path.join(root, name), dir))
for name in dirs:
result_dirs.append(os.path.relpath(os.path.join(root, name), dir))
return set(result_dirs), set(result_files)
def clean_files(base_dir, dirs, files):
for file in files:
if file == '.DS_Store':
os.remove(base_dir + '/' + file)
for dir in dirs:
if re.match('.*\\.xcodeproj', dir) or re.match('.*\\.xcworkspace', dir):
shutil.rmtree(base_dir + '/' + dir, ignore_errors=True)
def clean_dep_files(base_dir, dirs, files):
for file in files:
if re.match('^\\.git$', file) or re.match('^.*/\\.git$', file):
os.remove(base_dir + '/' + file)
for dir in dirs:
if re.match('^\\.git$', dir) or re.match('^.*/\\.git$', dir):
shutil.rmtree(base_dir + '/' + dir, ignore_errors=True)
if len(sys.argv) != 2:
print('Usage: extract_wallet_source.py destination')
sys.exit(1)
destination = sys.argv[1]
initial_dirs, initial_files = get_file_list(destination)
for file in initial_files:
if re.match('^\\.git/.*$', file):
continue
os.remove(destination + '/' + file)
for dir in initial_dirs:
if dir == '.git' or re.match('^\\.git/.*$', dir):
continue
shutil.rmtree(destination + '/' + dir, ignore_errors=True)
deps_data = os.popen('make -f Wallet.makefile --silent wallet_deps').read()
deps = json.loads(deps_data)
paths = []
for dep in deps:
dep_type = deps[dep]['buck.type']
if dep_type == 'genrule':
continue
match = re.search('//(.+?):', dep)
if match:
dep_path = match.group(1)
if dep_path not in paths:
paths.append(dep_path)
for dep_path in paths:
shutil.copytree(dep_path, destination + '/' + dep_path)
dep_dirs, dep_files = get_file_list(destination + '/' + dep_path)
clean_dep_files(destination + '/' + dep_path, dep_dirs, dep_files)
result_dirs, result_files = get_file_list(destination)
clean_files(destination, result_dirs, result_files)
with open(destination + '/BUCK', 'w+b') as file:
pass
shutil.copytree('Config', destination + '/' + 'Config')
shutil.copytree('tools/buck-build', destination + '/' + 'tools/buck-build')
shutil.copy('Wallet/README.md', destination + '/' + 'README.md')
os.remove(destination + '/Wallet/' + 'README.md')
copy_files = [
'.buckconfig',
'.gitignore',
'Utils.makefile',
'Wallet.makefile',
'check_env.sh',
'package_app.sh',
]
for file in copy_files:
shutil.copy(file, destination + '/' + file)