-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
134 lines (96 loc) · 3.21 KB
/
script.py
File metadata and controls
134 lines (96 loc) · 3.21 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
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
131
132
133
import os
import re
import json
import argparse
import sys
from pprint import pprint
# dictOfKeywords = {}
#load the dictionary
x = sys.argv[1]
with open(x) as config_file:
config_file_data = json.load(config_file)
print(config_file_data)
# if read_config_file["mapping_from"] == "ios":
# print("done")
with open('Dictionary/storage.json') as data_file:
dictOfKeywords = json.load(data_file)
# print(dictOfKeywords)
f = open("jsfilestoparse/test.ios.js").read()
f = f.replace("\n", "$!^#@")
g = f
#regex to find return();
reg = r"return\s*?\((.*?)\);"
# r = r"<[A-Z][a-z]+[A-Z]*[a-z]*"
# r1 = r"</[A-Z][a-z]+[A-Z]*[a-z]*\s*>"
#regex to find Components
# mixR = r"<([A-Z][a-zA-Z]*\s*|/[A-Z][a-zA-Z]*\s*)"
#for any case
mixR = r"<\s*(\s*[a-zA-Z]*\s*|/\s*[a-zA-Z]*\s*)"
#Find the xml part i.e. part within return()
m = re.findall(reg, f)
# print(m)
# print("\n\nlength is : %s"%len(m))
# print(dir(m))
listchange = []
index = -1
listOfKeywordsToBeReplaced = []
for match in m:
m3 = re.findall(mixR, match)
index+=1
# print("**** %s ***"%index)
for string in m3: #strings in m3
try:
s = string.split("/")
# print(s[1]) #key = s[1])
listOfKeywordsToBeReplaced.append(s[1])
except:
s = string.split(" ")
listOfKeywordsToBeReplaced.append(s[0])
f = 0
fault = 1
for keyword in listOfKeywordsToBeReplaced:
if keyword in dictOfKeywords.keys():
fault = 0
else:
dictOfKeywords[keyword] = keyword
if f == 0:
listchange.append(index)
f = 1
listOfKeywordsToBeReplaced = list(set(listOfKeywordsToBeReplaced))
print("List of keywords to be replaced : ",listOfKeywordsToBeReplaced)
# print(index)
# listchange = list(set(listchange))
# print(type(listchange))
print(listchange)
# for keyword in listOfKeywordsToBeReplaced:
# if keyword in dictOfKeywords.keys():
# print("Present")
# else:
# dictOfKeywords[keyword] = 'Comment this line '
commentS = "/**********************************************************************************"
commentE = "**********************************************************************************/"
i = 0
newM = []
for string in m:
# print("Before conversion : ",string)
for keyword in listOfKeywordsToBeReplaced:
# print("keyword ",keyword, dictOfKeywords[keyword])
string = string.replace(keyword, dictOfKeywords[keyword])
if i in listchange:
string = commentS+string+commentE
newM.append(string)
i+=1
# print("After conversion : ",string)
# print("Old M ", m)
# print("============================================================================================================")
# print("NEW M ", newM)
i = 0
for string in m:
g = g.replace(string,newM[i])
# print(string)
# print("============================================================================================================")
# print(newM[i])
i+=1
g = g.replace("$!^#@", "\n")
newFile = open('./webFiles/testweb.js', 'w')
newFile.write(g)