forked from mossini-smeup/Sme.UP-Documentazione
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearchIndex.py
274 lines (264 loc) · 13.2 KB
/
searchIndex.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
from AreeApplicative import nomiDOC, nomiDOC_OPE, applicazioni, areeApplicative, nomiAreeApplicative, areeApp, moduli, nomiDOC_SCH, nomiDOC_OGG, nomiDOC_NWS, nomiDOC_SER, nomiDOC_NTI, nomiFAQ, nomiGLO, moduliDOC_OPE
import os
dataFile = os.path.abspath('data.js')
basepath = 'Sorgenti'
basepath1 = 'DocumentazioneSmeUP'
with open(dataFile, "w", encoding='utf8') as f:
f.write('var data = [\n')
f.write('\n')
cont = 0
for dirname, dirnames, filenames in os.walk(basepath):
#print(dirname)
for singleFile in filenames:
nomefile = singleFile.replace('.md', '')
path = os.path.join(dirname,singleFile)
f.write('{\n')
f.write('id: ' + str(cont) + ",\n")
if 'OJ\\FILE' in dirname:
nomefile = 'F_' + nomefile
with open('Sorgenti/DOC_OGG_00INDEX.TXT', 'r', encoding='latin1') as indice:
for riga in indice:
if nomefile in riga:
titolo = riga[riga.find('- ')+2 : riga.find(' ')]
titolo = titolo.replace('\'', '\\\'')
break
f.write('title: \'' + titolo + '\',\n')
f.write('cat: "DOC_OGG",\n')
#f.write('voci: "",\n')
elif 'OJ\\PGM' in dirname:
nomefile = 'P_' + nomefile
with open('Sorgenti/DOC_OGG_00INDEX.TXT', 'r', encoding='latin1') as indice:
for riga in indice:
if nomefile in riga:
titolo = riga[riga.find('- ')+2 : riga.find(' ')]
titolo = titolo.replace('\'', '\\\'')
break
f.write('title: \'' + titolo + '\',\n')
f.write('cat: "DOC_OGG",\n')
#f.write('voci: "",\n')
elif 'OG\\OG' in dirname:
nomefile = 'OG_' + nomefile
with open('Sorgenti/DOC_OGG_00INDEX.TXT', 'r', encoding='latin1') as indice:
for riga in indice:
if nomefile in riga:
titolo = riga[riga.find('- ')+2 : riga.find(' ')]
titolo = titolo.replace('\'', '\\\'')
break
f.write('title: \'' + titolo + '\',\n')
f.write('cat: "DOC_OGG",\n')
#f.write('voci: "",\n')
elif 'OG\\TA' in dirname:
nomefile = 'TA_' + nomefile
with open('Sorgenti/DOC_OGG_00INDEX.TXT', 'r', encoding='latin1') as indice:
for riga in indice:
if nomefile in riga:
titolo = riga[riga.find('- ')+2 : riga.find(' ')]
titolo = titolo.replace('\'', '\\\'')
break
f.write('title: \'' + titolo + '\',\n')
f.write('cat: "DOC_OGG",\n')
#f.write('voci: "",\n')
elif 'OG\\V2' in dirname:
nomefile = 'V2_' + nomefile
with open('Sorgenti/DOC_OGG_00INDEX.TXT', 'r', encoding='latin1') as indice:
for riga in indice:
if nomefile in riga:
titolo = riga[riga.find('- ')+2 : riga.find(' ')]
titolo = titolo.replace('\'', '\\\'')
break
f.write('title: \'' + titolo + '\',\n')
f.write('cat: "DOC_OGG",\n')
#f.write('voci: "",\n')
elif 'OG\\V3' in dirname:
nomefile = 'V3_' + nomefile
with open('Sorgenti/DOC_OGG_00INDEX.TXT', 'r', encoding='latin1') as indice:
for riga in indice:
if nomefile in riga:
titolo = riga[riga.find('- ')+2 : riga.find(' ')]
titolo = titolo.replace('\'', '\\\'')
break
f.write('title: \'' + titolo + '\',\n')
f.write('cat: "DOC_OGG",\n')
#f.write('voci: "",\n')
elif 'V2\\LOCOS' in dirname:
with open('Sorgenti/DOC_OGG_00INDEX.TXT', 'r', encoding='latin1') as indice:
for riga in indice:
if nomefile in riga:
titolo = riga[riga.find('- ')+2 : riga.find(' ')]
titolo = titolo.replace('\'', '\\\'')
break
f.write('title: \'' + titolo + '\',\n')
f.write('cat: "DOC_OGG",\n')
#f.write('voci: "",\n')
elif 'DOC\\TA' in dirname:
with open('Sorgenti/DOC_00INDEX.TXT', 'r', encoding='latin1') as indice:
for riga in indice:
if nomefile in riga:
titolo = riga[riga.find('- ')+2 : riga.find(' ')]
titolo = titolo.replace('\'', '\\\'')
break
f.write('title: \'' + titolo + '\',\n')
f.write('cat: "DOC_APP",\n')
#f.write('voci: "",\n')
elif 'DOC_OPE\\TA' in dirname:
f.write('title: "' + nomiDOC_OPE[nomefile] + '",\n')
f.write('cat: "DOC_OPE",\n')
#f.write('voci: "",\n')
elif 'FAQ' in dirname:
nomefile = nomefile + '_FAQ'
f.write('title: "' + nomiFAQ[nomefile] + '",\n')
f.write('cat: "FAQ",\n')
#f.write('voci: "",\n')
elif 'GLO' in dirname:
with open(os.path.join(dirname,singleFile), "r", encoding='utf8') as f1:
voci = []
for line in f1:
if 'Txt="' in line:
txtGLO = line.rsplit('Txt="')[1]
txtGLO = txtGLO.rsplit('"')[0]
voci.append(txtGLO)
nomefile = nomefile + '_GLO'
f.write('title: "' + nomiGLO[nomefile] + '",\n')
f.write('cat: "GLO",\n')
f.write('voci: "')
for voce in voci:
f.write(voce + ' ')
f.write('",\n')
elif 'NWS' in dirname:
with open(os.path.join(dirname,singleFile), "r", encoding='utf8') as f1:
rel = ''
num = ''
for line in f1:
if 'Rel="' in line:
rel = line.rsplit('Rel="')[1]
rel = rel.rsplit('"')[0]
if 'Num="' in line:
num = line.rsplit('Num="')[1]
num = num.rsplit('"')[0]
nomefile = nomefile.replace('_', '_NWS')
f.write('title: "' + nomiDOC_NWS[nomefile] + '",\n')
f.write('cat: "NWS",\n')
f.write('rel: "' + rel + '",\n')
f.write('num: "' + num + '",\n')
elif 'MB\\SCP_SCH' in dirname:
f.write('title: "' + nomiDOC_SCH[nomefile] + '",\n')
f.write('cat: "DOC_SCH",\n')
#f.write('voci: "",\n')
elif 'V3\\ASE' in dirname:
f.write('title: "' + nomiDOC_SER[nomefile] + '",\n')
f.write('cat: "DOC_SER",\n')
#f.write('voci: "",\n')
elif 'TA\\B£A' in dirname:
if nomefile in applicazioni:
f.write('title: "' + applicazioni[nomefile] + '",\n')
f.write('cat: "DOC_VIS",\n')
#f.write('voci: "",\n')
else:
f.write('title: "",\n')
f.write('cat: "",\n')
#f.write('voci: "",\n')
else:
f.write('title: "",\n')
f.write('cat: "",\n')
#f.write('voci: "",\n')
f.write('href: "' + path.replace('\\', '/') + '"\n},')
cont = cont + 1
for dirname, dirnames, filenames in os.walk(basepath1):
#print(dirname)
for singleFile in filenames:
nomefile = singleFile.replace('.md', '')
path = os.path.join(dirname,singleFile)
# print(path)
f.write('{\n')
f.write('id: ' + str(cont) + ",\n")
if 'DOC\\DOC_APP' in dirname:
for key, value in areeApp.items():
if key in dirname:
if dirname.endswith(key):
f.write('title: "' + value + '",\n')
f.write('cat: "Indice DOC_APP",\n')
# f.write('voci: "",\n')
for codice, nome in applicazioni.items():
if codice in dirname:
f.write('title: "' + nome + '",\n')
f.write('cat: "Indice DOC_APP",\n')
# f.write('voci: "",\n')
elif 'DOC\\DOC_SER' in dirname:
for key, value in areeApp.items():
if key in dirname:
if dirname.endswith(key):
f.write('title: "' + value + '",\n')
f.write('cat: "Indice DOC_SER",\n')
#f.write('voci: "",\n')
for codice, nome in applicazioni.items():
if codice in dirname:
f.write('title: "' + nome + '",\n')
f.write('cat: "Indice DOC_SER",\n')
#f.write('voci: "",\n')
elif 'DOC_VIS' in dirname:
for key, value in areeApp.items():
if key in dirname:
if dirname.endswith(key):
f.write('title: "' + value + '",\n')
f.write('cat: "Indice DOC_VIS",\n')
#f.write('voci: "",\n')
for codice, nome in applicazioni.items():
if codice in dirname:
f.write('title: "' + nome + '",\n')
f.write('cat: "Indice DOC_VIS",\n')
#f.write('voci: "",\n')
elif 'DOC_OPE' in dirname:
for key, value in areeApp.items():
if key in dirname:
if dirname.endswith(key):
f.write('title: "' + value + '",\n')
f.write('cat: "Indice DOC_OPE",\n')
#f.write('voci: "",\n')
for codice, nome in applicazioni.items():
if codice in dirname:
f.write('title: "' + nome + '",\n')
f.write('cat: "Indice DOC_OPE",\n')
#f.write('voci: "",\n')
elif 'FAQ' in dirname:
for key, value in areeApp.items():
if key in dirname:
if dirname.endswith(key):
f.write('title: "' + value + '",\n')
f.write('cat: "Indice FAQ",\n')
#f.write('voci: "",\n')
for codice, nome in applicazioni.items():
if codice in dirname:
f.write('title: "' + nome + '",\n')
f.write('cat: "Indice FAQ",\n')
#f.write('voci: "",\n')
elif 'GLO' in dirname:
for key, value in areeApp.items():
if key in dirname:
if dirname.endswith(key):
f.write('title: "' + value + '",\n')
f.write('cat: "Indice GLO",\n')
#f.write('voci: "",\n')
for codice, nome in applicazioni.items():
if '\\' + codice in dirname:
f.write('title: "' + nome + '",\n')
f.write('cat: "Indice GLO",\n')
#f.write('voci: "",\n')
elif 'NWS\\News' in dirname:
for key, value in areeApp.items():
if key in dirname:
if dirname.endswith(key):
f.write('title: "' + value + '",\n')
f.write('cat: "Indice NWS",\n')
#f.write('voci: "",\n')
for codice, nome in applicazioni.items():
if '\\' + codice in dirname:
f.write('title: "' + nome + '",\n')
f.write('cat: "Indice NWS",\n')
#f.write('voci: "",\n')
else:
f.write('title: "",\n')
f.write('cat: "",\n')
#f.write('voci: "",\n')
f.write('href: "' + path.replace('\\', '/') + '"\n},')
cont = cont + 1
f.write('];')