update_disskeyboard.py
3.2 KB
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
import fileinput
import re
import os
#global hasListView
#hasListView = False
global checkDir
checkDir = './js'
def matchText(text):
if re.match(r'^.*ListView,.*', text):
return True
else:
return False
def matchRnText(text):
if re.match(r'^.*\'react-native\'', text):
return True
elif re.match(r'^.*\"react-native\"', text):
return True
elif re.match(r'^.*ReactNative', text):
return True
else:
return False
def matchKeyboardText(text):
if re.match(r'^.*require\(\'dismissKeyboard\'\)', text):
return True
else:
return False
def matchDismissKeyboardText(text):
if re.match(r'^.*dismissKeyboard\(\)', text):
return True
else:
return False
def matchWithExport(text):
if re.match(r'^export', text):
return True
else:
return False
def updatelist():
for currentpath, folders, files in os.walk(checkDir):
for file in files:
print(os.path.join(currentpath, file))
fullpath = os.path.join(currentpath, file)
hasListView = False
toBeWrite = True
if file.endswith('.js'):
for line in fileinput.input(fullpath, inplace=True):
if matchText(line):
hasListView = True
print(line.replace('ListView,', ''), end='')
if matchRnText(line) and toBeWrite:
print('import ListView from \'deprecated-react-native-listview\'')
toBeWrite = False
continue
elif matchRnText(line) and hasListView and toBeWrite:
print(line, end='')
print('import ListView from \'deprecated-react-native-listview\'')
toBeWrite = False
continue
else:
print(line, end='')
else:
pass
def updateDissmissKeyboard():
for currentpath, folders, files in os.walk(checkDir):
for file in files:
print(os.path.join(currentpath, file))
fullpath = os.path.join(currentpath, file)
hasKeyboard = False
toBeImport = True
if file.endswith('.js'):
#check if require keyboard first ,then add import at the top of the file
for line in fileinput.input(fullpath, inplace=False):
if matchKeyboardText(line):
hasKeyboard = True
else:
pass
for line in fileinput.input(fullpath, inplace=True):
if matchKeyboardText(line):
print('', end='')
elif matchDismissKeyboardText(line):
print('Keyboard.dismiss()')
elif matchWithExport(line) and hasKeyboard and toBeImport:
toBeImport = False
print('import {Keyboard} from \'react-native\'')
print(line, end='')
else:
print(line, end='')
updateDissmissKeyboard()