forked from project-violet/violet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess-ios.py
112 lines (93 loc) · 2.61 KB
/
preprocess-ios.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# This source code is a part of Project Violet.
# Copyright (C) 2021.violet-team. Licensed under the Apache-2.0 License.
import sys
import os
import os.path
import re
target = 'ios'
def process_dart(path):
f = open(path, 'r')
w = []
nl = False
op = False
for line in f.readlines():
if '//' in line:
annote = re.split(r': |, | ',line.split('//')[-1].strip())
if not annote[0].startswith('@dependent'):
if nl or op:
nl = False
else:
w.append(line)
continue
if annote[1] == target:
w.append(line)
continue
if len(annote) == 2:
continue
if annote[2] == '=>':
nl = True
continue
if annote[2] == '[':
op = True
continue
if annote[2] == ']':
op = False
continue
else:
if nl or op:
nl = False
else:
w.append(line)
f.close()
f = open(path, 'w+')
f.writelines(w)
f.close()
def process_yaml(path):
f = open(path, 'r')
w = []
nl = False
op = False
for line in f.readlines():
if '#' in line:
annote = re.split(r': |, | ', line.split('#')[-1].strip())
if not annote[0].startswith('@dependent'):
if nl or op:
nl = False
else:
w.append(line)
continue
if annote[1] == target:
w.append(line)
continue
if len(annote) == 2:
continue
if annote[2] == '=>':
nl = True
continue
if annote[2] == '[':
op = True
continue
if annote[2] == ']':
op = False
continue
else:
if nl or op:
nl = False
else:
w.append(line)
f.close()
f = open(path, 'w+')
f.writelines(w)
f.close()
def create_dummy_valid(path):
f = open(path, 'w')
f.writelines(['String getValid(foo) {return foo;}'])
f.close()
for root, subdirs, files in os.walk('./'):
for filename in files:
if filename.endswith(".dart"):
process_dart(root + '/' + filename)
elif filename.endswith(".yaml"):
process_yaml(root + '/' + filename)
create_dummy_valid('./lib/server/salt.dart')
create_dummy_valid('./lib/server/wsalt.dart')