OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 | |
3 import stringmanipulation | |
4 import filemanagement | |
5 import p4commands | |
6 import sys | |
7 | |
8 name_space_to_ignore = 'GIPS::' | |
9 #only allow one prefix to be removed since allowing multiple will complicate | |
10 # things | |
11 prefix_to_filter = 'gips' | |
12 #words_to_filter = ['Module'] | |
13 # it might be dangerous to remove GIPS but keep it default | |
14 words_to_filter = ['Module','GIPS'] | |
15 | |
16 # This script finds all the words that should be replaced in an h-file. Once | |
17 # all words that should be replaced are found it does a global search and | |
18 # replace. | |
19 | |
20 extensions_to_edit = ['.cpp','.cc','.h'] | |
21 | |
22 #line = ' ~hiGIPSCriticalSectionScoped()' | |
23 #print line | |
24 #position = stringmanipulation.getword(line,11) | |
25 #old_word = line[position[0]:position[0]+position[1]] | |
26 #result = stringmanipulation.removealloccurances(old_word,'gips') | |
27 #new_word = result | |
28 #print old_word | |
29 #print position[0] | |
30 #print position[0]+position[1] | |
31 #print new_word | |
32 #quit() | |
33 | |
34 # Ignore whole line if any item in this table is a substring of the line | |
35 do_not_replace_line_table = [] | |
36 do_not_replace_line_table.append('namespace GIPS') | |
37 | |
38 # [old_string,new_string] | |
39 # List of things to remove that are static: | |
40 manual_replace_table = [] | |
41 #manual_replace_table.append(['using namespace GIPS;','']) | |
42 #manual_replace_table.append(['CreateGipsEvent','CreateEvent']) | |
43 #manual_replace_table.append(['CreateGIPSTrace','CreateTrace']) | |
44 #manual_replace_table.append(['ReturnGIPSTrace','ReturnTrace']) | |
45 #manual_replace_table.append(['CreateGIPSFile','CreateFile']) | |
46 replace_table = manual_replace_table | |
47 #replace_table.append(['GIPS::','webrtc::']) | |
48 # List of things to not remove that are static, i.e. exceptions: | |
49 # don't replace any of the GIPS_Words since that will affect all files | |
50 # do that in a separate script! | |
51 do_not_replace_table = [] | |
52 do_not_replace_table.append('GIPS_CipherTypes') | |
53 do_not_replace_table.append('GIPS_AuthenticationTypes') | |
54 do_not_replace_table.append('GIPS_SecurityLevels') | |
55 do_not_replace_table.append('GIPS_encryption') | |
56 do_not_replace_table.append('~GIPS_encryption') | |
57 do_not_replace_table.append('GIPS_transport') | |
58 do_not_replace_table.append('~GIPS_transport') | |
59 do_not_replace_table.append('GIPSTraceCallback') | |
60 do_not_replace_table.append('~GIPSTraceCallback') | |
61 do_not_replace_table.append('GIPS_RTP_CSRC_SIZE') | |
62 do_not_replace_table.append('GIPS_RTPDirections') | |
63 do_not_replace_table.append('GIPS_RTP_INCOMING') | |
64 do_not_replace_table.append('GIPS_RTP_OUTGOING') | |
65 do_not_replace_table.append('GIPSFrameType') | |
66 do_not_replace_table.append('GIPS_FRAME_EMPTY') | |
67 do_not_replace_table.append('GIPS_AUDIO_FRAME_SPEECH') | |
68 do_not_replace_table.append('GIPS_AUDIO_FRAME_CN') | |
69 do_not_replace_table.append('GIPS_VIDEO_FRAME_KEY') | |
70 do_not_replace_table.append('GIPS_VIDEO_FRAME_DELTA') | |
71 do_not_replace_table.append('GIPS_VIDEO_FRAME_GOLDEN') | |
72 do_not_replace_table.append('GIPS_VIDEO_FRAME_DELTA_KEY') | |
73 do_not_replace_table.append('GIPS_PacketType') | |
74 do_not_replace_table.append('GIPS_PACKET_TYPE_RTP') | |
75 do_not_replace_table.append('GIPS_PACKET_TYPE_KEEP_ALIVE') | |
76 do_not_replace_table.append('GIPS_AudioLayers') | |
77 do_not_replace_table.append('GIPS_AUDIO_PLATFORM_DEFAULT') | |
78 do_not_replace_table.append('GIPS_AUDIO_WINDOWS_WAVE') | |
79 do_not_replace_table.append('GIPS_AUDIO_WINDOWS_CORE') | |
80 do_not_replace_table.append('GIPS_AUDIO_LINUX_ALSA') | |
81 do_not_replace_table.append('GIPS_AUDIO_LINUX_PULSE') | |
82 do_not_replace_table.append('GIPS_AUDIO_FORMAT') | |
83 do_not_replace_table.append('GIPS_PCM_16_16KHZ') | |
84 do_not_replace_table.append('GIPS_PCM_16_8KHZ') | |
85 do_not_replace_table.append('GIPS_G729') | |
86 do_not_replace_table.append('GIPSAMRmode') | |
87 do_not_replace_table.append('GIPS_RFC3267_BWEFFICIENT') | |
88 do_not_replace_table.append('GIPS_RFC3267_OCTETALIGNED') | |
89 do_not_replace_table.append('GIPS_RFC3267_FILESTORAGE') | |
90 do_not_replace_table.append('GIPS_NCModes') | |
91 do_not_replace_table.append('GIPS_NC_OFF') | |
92 do_not_replace_table.append('GIPS_NC_MILD') | |
93 do_not_replace_table.append('GIPS_NC_MODERATE') | |
94 do_not_replace_table.append('GIPS_NC_AGGRESSIVE') | |
95 do_not_replace_table.append('GIPS_NC_VERY_AGGRESSIVE') | |
96 do_not_replace_table.append('GIPS_AGCModes') | |
97 do_not_replace_table.append('GIPS_AGC_OFF') | |
98 do_not_replace_table.append('GIPS_AGC_ANALOG') | |
99 do_not_replace_table.append('GIPS_AGC_DIGITAL') | |
100 do_not_replace_table.append('GIPS_AGC_STANDALONE_DIG') | |
101 do_not_replace_table.append('GIPS_ECModes') | |
102 do_not_replace_table.append('GIPS_EC_UNCHANGED') | |
103 do_not_replace_table.append('GIPS_EC_DEFAULT') | |
104 do_not_replace_table.append('GIPS_EC_CONFERENCE') | |
105 do_not_replace_table.append('GIPS_EC_AEC') | |
106 do_not_replace_table.append('GIPS_EC_AES') | |
107 do_not_replace_table.append('GIPS_EC_AECM') | |
108 do_not_replace_table.append('GIPS_EC_NEC_IAD') | |
109 do_not_replace_table.append('GIPS_AESModes') | |
110 do_not_replace_table.append('GIPS_AES_DEFAULT') | |
111 do_not_replace_table.append('GIPS_AES_NORMAL') | |
112 do_not_replace_table.append('GIPS_AES_HIGH') | |
113 do_not_replace_table.append('GIPS_AES_ATTENUATE') | |
114 do_not_replace_table.append('GIPS_AES_NORMAL_SOFT_TRANS') | |
115 do_not_replace_table.append('GIPS_AES_HIGH_SOFT_TRANS') | |
116 do_not_replace_table.append('GIPS_AES_ATTENUATE_SOFT_TRANS') | |
117 do_not_replace_table.append('GIPS_AECMModes') | |
118 do_not_replace_table.append('GIPS_AECM_QUIET_EARPIECE_OR_HEADSET') | |
119 do_not_replace_table.append('GIPS_AECM_EARPIECE') | |
120 do_not_replace_table.append('GIPS_AECM_LOUD_EARPIECE') | |
121 do_not_replace_table.append('GIPS_AECM_SPEAKERPHONE') | |
122 do_not_replace_table.append('GIPS_AECM_LOUD_SPEAKERPHONE') | |
123 do_not_replace_table.append('AECM_LOUD_SPEAKERPHONE') | |
124 do_not_replace_table.append('GIPS_VAD_CONVENTIONAL') | |
125 do_not_replace_table.append('GIPS_VAD_AGGRESSIVE_LOW') | |
126 do_not_replace_table.append('GIPS_VAD_AGGRESSIVE_MID') | |
127 do_not_replace_table.append('GIPS_VAD_AGGRESSIVE_HIGH') | |
128 do_not_replace_table.append('GIPS_NetEQModes') | |
129 do_not_replace_table.append('GIPS_NETEQ_DEFAULT') | |
130 do_not_replace_table.append('GIPS_NETEQ_STREAMING') | |
131 do_not_replace_table.append('GIPS_NETEQ_FAX') | |
132 do_not_replace_table.append('GIPS_NetEQBGNModes') | |
133 do_not_replace_table.append('GIPS_BGN_ON') | |
134 do_not_replace_table.append('GIPS_BGN_FADE') | |
135 do_not_replace_table.append('GIPS_BGN_OFF') | |
136 do_not_replace_table.append('GIPS_OnHoldModes') | |
137 do_not_replace_table.append('GIPS_HOLD_SEND_AND_PLAY') | |
138 do_not_replace_table.append('GIPS_HOLD_SEND_ONLY') | |
139 do_not_replace_table.append('GIPS_HOLD_PLAY_ONLY') | |
140 do_not_replace_table.append('GIPS_PayloadFrequencies') | |
141 do_not_replace_table.append('GIPS_FREQ_8000_HZ') | |
142 do_not_replace_table.append('GIPS_FREQ_16000_HZ') | |
143 do_not_replace_table.append('GIPS_FREQ_32000_HZ') | |
144 do_not_replace_table.append('GIPS_TelephoneEventDetectionMethods') | |
145 do_not_replace_table.append('GIPS_IN_BAND') | |
146 do_not_replace_table.append('GIPS_OUT_OF_BAND') | |
147 do_not_replace_table.append('GIPS_IN_AND_OUT_OF_BAND') | |
148 do_not_replace_table.append('GIPS_ProcessingTypes') | |
149 do_not_replace_table.append('GIPS_PLAYBACK_PER_CHANNEL') | |
150 do_not_replace_table.append('GIPS_PLAYBACK_ALL_CHANNELS_MIXED') | |
151 do_not_replace_table.append('GIPS_RECORDING_PER_CHANNEL') | |
152 do_not_replace_table.append('GIPS_RECORDING_ALL_CHANNELS_MIXED') | |
153 do_not_replace_table.append('GIPS_StereoChannel') | |
154 do_not_replace_table.append('GIPS_StereoLeft') | |
155 do_not_replace_table.append('GIPS_StereoRight') | |
156 do_not_replace_table.append('GIPS_StereoBoth') | |
157 do_not_replace_table.append('GIPS_stat_val') | |
158 do_not_replace_table.append('GIPS_P56_statistics') | |
159 do_not_replace_table.append('GIPS_echo_statistics') | |
160 do_not_replace_table.append('GIPS_NetworkStatistics') | |
161 do_not_replace_table.append('GIPS_JitterStatistics') | |
162 do_not_replace_table.append('GIPSVideoRawType') | |
163 do_not_replace_table.append('GIPS_VIDEO_I420') | |
164 do_not_replace_table.append('GIPS_VIDEO_YV12') | |
165 do_not_replace_table.append('GIPS_VIDEO_YUY2') | |
166 do_not_replace_table.append('GIPS_VIDEO_UYVY') | |
167 do_not_replace_table.append('GIPS_VIDEO_IYUV') | |
168 do_not_replace_table.append('GIPS_VIDEO_ARGB') | |
169 do_not_replace_table.append('GIPS_VIDEO_RGB24') | |
170 do_not_replace_table.append('GIPS_VIDEO_RGB565') | |
171 do_not_replace_table.append('GIPS_VIDEO_ARGB4444') | |
172 do_not_replace_table.append('GIPS_VIDEO_ARGB1555') | |
173 do_not_replace_table.append('GIPS_VIDEO_MJPG') | |
174 do_not_replace_table.append('GIPS_VIDEO_NV12') | |
175 do_not_replace_table.append('GIPS_VIDEO_NV21') | |
176 do_not_replace_table.append('GIPS_VIDEO_Unknown') | |
177 do_not_replace_table.append('GIPSVideoLayouts') | |
178 do_not_replace_table.append('GIPS_LAYOUT_NONE') | |
179 do_not_replace_table.append('GIPS_LAYOUT_DEFAULT') | |
180 do_not_replace_table.append('GIPS_LAYOUT_ADVANCED1') | |
181 do_not_replace_table.append('GIPS_LAYOUT_ADVANCED2') | |
182 do_not_replace_table.append('GIPS_LAYOUT_ADVANCED3') | |
183 do_not_replace_table.append('GIPS_LAYOUT_ADVANCED4') | |
184 do_not_replace_table.append('GIPS_LAYOUT_FULL') | |
185 do_not_replace_table.append('KGIPSConfigParameterSize') | |
186 do_not_replace_table.append('KGIPSPayloadNameSize') | |
187 do_not_replace_table.append('GIPSVideoCodecH263') | |
188 do_not_replace_table.append('GIPSVideoH264Packetization') | |
189 do_not_replace_table.append('GIPS_H264_SingleMode') | |
190 do_not_replace_table.append('GIPS_H264_NonInterleavedMode') | |
191 do_not_replace_table.append('GIPSVideoCodecComplexity') | |
192 do_not_replace_table.append('GIPSVideoCodec_Complexity_Normal') | |
193 do_not_replace_table.append('GIPSVideoCodec_Comlexity_High') | |
194 do_not_replace_table.append('GIPSVideoCodec_Comlexity_Higher') | |
195 do_not_replace_table.append('GIPSVideoCodec_Comlexity_Max') | |
196 do_not_replace_table.append('GIPSVideoCodecH264') | |
197 do_not_replace_table.append('GIPSVideoH264Packetization') | |
198 do_not_replace_table.append('GIPSVideoCodecComplexity') | |
199 do_not_replace_table.append('GIPSVideoCodecProfile') | |
200 do_not_replace_table.append('KGIPSConfigParameterSize') | |
201 do_not_replace_table.append('KGIPSMaxSVCLayers') | |
202 do_not_replace_table.append('GIPSVideoH264LayerTypes') | |
203 do_not_replace_table.append('GIPS_H264SVC_Base') | |
204 do_not_replace_table.append('GIPS_H264SVC_Extend_2X2') | |
205 do_not_replace_table.append('GIPS_H264SVC_Extend_1X1') | |
206 do_not_replace_table.append('GIPS_H264SVC_Extend_MGS') | |
207 do_not_replace_table.append('GIPS_H264SVC_Extend_1_5') | |
208 do_not_replace_table.append('GIPS_H264SVC_Extend_Custom') | |
209 do_not_replace_table.append('GIPSVideoH264LayersProperties') | |
210 do_not_replace_table.append('GIPSVideoH264LayerTypes') | |
211 do_not_replace_table.append('GIPSVideoH264Layers') | |
212 do_not_replace_table.append('GIPSVideoH264LayersProperties') | |
213 do_not_replace_table.append('GIPSVideoCodecH264SVC') | |
214 do_not_replace_table.append('GIPSVideoCodecComplexity') | |
215 do_not_replace_table.append('GIPSVideoCodecProfile') | |
216 do_not_replace_table.append('GIPSVideoH264Layers') | |
217 do_not_replace_table.append('GIPSVideoCodecVP8') | |
218 do_not_replace_table.append('GIPSVideoCodecComplexity') | |
219 do_not_replace_table.append('GIPSVideoCodecMPEG') | |
220 do_not_replace_table.append('GIPSVideoCodecGeneric') | |
221 do_not_replace_table.append('GIPSVideoCodecType') | |
222 do_not_replace_table.append('GIPSVideoCodec_H263') | |
223 do_not_replace_table.append('GIPSVideoCodec_H264') | |
224 do_not_replace_table.append('GIPSVideoCodec_H264SVC') | |
225 do_not_replace_table.append('GIPSVideoCodec_VP8') | |
226 do_not_replace_table.append('GIPSVideoCodec_MPEG4') | |
227 do_not_replace_table.append('GIPSVideoCodec_I420') | |
228 do_not_replace_table.append('GIPSVideoCodec_RED') | |
229 do_not_replace_table.append('GIPSVideoCodec_ULPFEC') | |
230 do_not_replace_table.append('GIPSVideoCodec_Unknown') | |
231 do_not_replace_table.append('GIPSVideoCodecUnion') | |
232 do_not_replace_table.append('GIPSVideoCodecH263') | |
233 do_not_replace_table.append('GIPSVideoCodecH264') | |
234 do_not_replace_table.append('GIPSVideoCodecH264SVC') | |
235 do_not_replace_table.append('GIPSVideoCodecVP8') | |
236 do_not_replace_table.append('GIPSVideoCodecMPEG4') | |
237 do_not_replace_table.append('GIPSVideoCodecGeneric') | |
238 do_not_replace_table.append('GIPSVideoCodec') | |
239 do_not_replace_table.append('GIPSVideoCodecType') | |
240 do_not_replace_table.append('GIPSVideoCodecUnion') | |
241 do_not_replace_table.append('GIPSAudioFrame') | |
242 do_not_replace_table.append('GIPS_CodecInst') | |
243 do_not_replace_table.append('GIPS_FileFormats') | |
244 do_not_replace_table.append('GIPSTickTime') | |
245 do_not_replace_table.append('GIPS_Word64') | |
246 do_not_replace_table.append('GIPS_UWord64') | |
247 do_not_replace_table.append('GIPS_Word32') | |
248 do_not_replace_table.append('GIPS_UWord32') | |
249 do_not_replace_table.append('GIPS_Word16') | |
250 do_not_replace_table.append('GIPS_UWord16') | |
251 do_not_replace_table.append('GIPS_Word8') | |
252 do_not_replace_table.append('GIPS_UWord8') | |
253 | |
254 if((len(sys.argv) != 2) and (len(sys.argv) != 3)): | |
255 print 'parameters are: parent directory [--commit]' | |
256 quit() | |
257 | |
258 if((len(sys.argv) == 3) and (sys.argv[2] != '--commit')): | |
259 print 'parameters are: parent directory [--commit]' | |
260 quit() | |
261 | |
262 commit = (len(sys.argv) == 3) | |
263 | |
264 directory = sys.argv[1]; | |
265 if(not filemanagement.pathexist(directory)): | |
266 print 'path ' + directory + ' does not exist' | |
267 quit() | |
268 | |
269 # APIs are all in h-files | |
270 extension = '.h' | |
271 | |
272 # All h-files | |
273 files_to_modify = filemanagement.listallfilesinfolder(directory,\ | |
274 extension) | |
275 | |
276 def isinmanualremovetable( compare_word ): | |
277 for old_word, new_word in manual_replace_table: | |
278 if(old_word == compare_word): | |
279 return True | |
280 return False | |
281 | |
282 # Begin | |
283 # This function looks at each line and decides which words should be replaced | |
284 # that is this is the only part of the script that you will ever want to change! | |
285 def findstringstoreplace(line): | |
286 original_line = line | |
287 # Dont replace compiler directives | |
288 if(line[0] == '#'): | |
289 return [] | |
290 # Dont allow global removal of namespace gips since it is very intrusive | |
291 for sub_string_compare in do_not_replace_line_table: | |
292 index = stringmanipulation.issubstring(line,sub_string_compare) | |
293 if(index != -1): | |
294 return [] | |
295 | |
296 return_value = [] | |
297 | |
298 line = stringmanipulation.removeccomment(line) | |
299 line = stringmanipulation.whitespacestoonespace(line) | |
300 if(len(line) == 0): | |
301 return [] | |
302 if(line[0] == '*'): | |
303 return [] | |
304 index = stringmanipulation.issubstring(line,prefix_to_filter) | |
305 while index >= 0: | |
306 dont_store_hit = False | |
307 word_position = stringmanipulation.getword(line, index) | |
308 start_of_word = word_position[0] | |
309 size_of_word = word_position[1] | |
310 end_of_word = start_of_word + size_of_word | |
311 old_word = line[start_of_word:end_of_word] | |
312 if(isinmanualremovetable(old_word)): | |
313 dont_store_hit = True | |
314 if((end_of_word + 2 < len(line)) and\ | |
315 name_space_to_ignore == line[start_of_word:end_of_word+2]): | |
316 dont_store_hit = True | |
317 | |
318 result = stringmanipulation.removeprefix(old_word,prefix_to_filter) | |
319 new_word = result[1] | |
320 for word_to_filter in words_to_filter: | |
321 new_word = stringmanipulation.removealloccurances(new_word,word_to_f
ilter) | |
322 result = stringmanipulation.removeprefix(new_word,'_') | |
323 new_word = result[1] | |
324 new_word = stringmanipulation.fixabbreviations(new_word) | |
325 new_word = stringmanipulation.removealloccurances(new_word,'_') | |
326 if(not dont_store_hit): | |
327 return_value.append([old_word,new_word]) | |
328 # remove the word we found from the string so we dont find it again | |
329 line = line[0:start_of_word] + line[end_of_word:len(line)] | |
330 index = stringmanipulation.issubstring(line,'GIPS') | |
331 | |
332 return return_value | |
333 # End | |
334 | |
335 # loop through all files | |
336 for path, file_name in files_to_modify: | |
337 # if(file_name != 'GIPSTickUtil.h'): | |
338 # continue | |
339 full_file_name = path + file_name | |
340 file_pointer = open(full_file_name,'r') | |
341 # print file_name | |
342 #loop through all lines | |
343 for line in file_pointer: | |
344 # print line | |
345 local_replace_string = findstringstoreplace(line) | |
346 #print local_replace_string | |
347 if(len(local_replace_string) != 0): | |
348 replace_table.extend(local_replace_string) | |
349 | |
350 | |
351 # we have built our replace table now | |
352 replace_table = stringmanipulation.removeduplicates( replace_table ) | |
353 replace_table = stringmanipulation.ordertablesizefirst( replace_table ) | |
354 replace_table = stringmanipulation.complement(replace_table,\ | |
355 do_not_replace_table) | |
356 | |
357 def replaceoriginal( path,my_table ): | |
358 size_of_table = len(my_table) | |
359 for index in range(len(my_table)): | |
360 old_name = my_table[index][0] | |
361 new_name = my_table[index][1] | |
362 filemanagement.replacestringinfolder(path, old_name, new_name,\ | |
363 ".h") | |
364 print (100*index) / (size_of_table*2) | |
365 | |
366 def replaceall( my_table, extension_list ): | |
367 size_of_table = len(my_table) | |
368 for index in range(len(my_table)): | |
369 old_name = my_table[index][0] | |
370 new_name = my_table[index][1] | |
371 new_name = new_name | |
372 for extension in extensions_to_edit: | |
373 filemanagement.replacestringinallsubfolders(old_name, new_name, | |
374 extension) | |
375 print 100*(size_of_table + index) / (size_of_table*2) | |
376 | |
377 | |
378 if(commit): | |
379 print 'commiting' | |
380 replace_table = stringmanipulation.removenochange(replace_table) | |
381 p4commands.checkoutallfiles() | |
382 replaceoriginal(directory,replace_table) | |
383 replaceall(replace_table,extensions_to_edit) | |
384 p4commands.revertunchangedfiles() | |
385 else: | |
386 for old_name, new_name in replace_table: | |
387 print 'Going to replace [' + old_name + '] with [' + new_name + ']' | |
OLD | NEW |