aboutsummaryrefslogtreecommitdiff
path: root/tools/refactoring/fixnames.py
blob: 15381e38d421c146ad0e2555abac6bfd82565984 (plain)
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#!/usr/bin/env python

import stringmanipulation
import filemanagement
import p4commands
import sys

name_space_to_ignore = 'GIPS::'
#only allow one prefix to be removed since allowing multiple will complicate
# things
prefix_to_filter = 'gips'
#words_to_filter = ['Module']
# it might be dangerous to remove GIPS but keep it default
words_to_filter = ['Module','GIPS']

# This script finds all the words that should be replaced in an h-file. Once
# all words that should be replaced are found it does a global search and
# replace.

extensions_to_edit = ['.cpp','.cc','.h']

#line = '    ~hiGIPSCriticalSectionScoped()'
#print line
#position = stringmanipulation.getword(line,11)
#old_word = line[position[0]:position[0]+position[1]]
#result = stringmanipulation.removealloccurances(old_word,'gips')
#new_word = result
#print old_word
#print position[0]
#print position[0]+position[1]
#print new_word
#quit()

# Ignore whole line if any item in this table is a substring of the line
do_not_replace_line_table = []
do_not_replace_line_table.append('namespace GIPS')

# [old_string,new_string]
# List of things to remove that are static:
manual_replace_table = []
#manual_replace_table.append(['using namespace GIPS;',''])
#manual_replace_table.append(['CreateGipsEvent','CreateEvent'])
#manual_replace_table.append(['CreateGIPSTrace','CreateTrace'])
#manual_replace_table.append(['ReturnGIPSTrace','ReturnTrace'])
#manual_replace_table.append(['CreateGIPSFile','CreateFile'])
replace_table = manual_replace_table
#replace_table.append(['GIPS::','webrtc::'])
# List of things to not remove that are static, i.e. exceptions:
# don't replace any of the GIPS_Words since that will affect all files
# do that in a separate script!
do_not_replace_table = []
do_not_replace_table.append('GIPS_CipherTypes')
do_not_replace_table.append('GIPS_AuthenticationTypes')
do_not_replace_table.append('GIPS_SecurityLevels')
do_not_replace_table.append('GIPS_encryption')
do_not_replace_table.append('~GIPS_encryption')
do_not_replace_table.append('GIPS_transport')
do_not_replace_table.append('~GIPS_transport')
do_not_replace_table.append('GIPSTraceCallback')
do_not_replace_table.append('~GIPSTraceCallback')
do_not_replace_table.append('GIPS_RTP_CSRC_SIZE')
do_not_replace_table.append('GIPS_RTPDirections')
do_not_replace_table.append('GIPS_RTP_INCOMING')
do_not_replace_table.append('GIPS_RTP_OUTGOING')
do_not_replace_table.append('GIPSFrameType')
do_not_replace_table.append('GIPS_FRAME_EMPTY')
do_not_replace_table.append('GIPS_AUDIO_FRAME_SPEECH')
do_not_replace_table.append('GIPS_AUDIO_FRAME_CN')
do_not_replace_table.append('GIPS_VIDEO_FRAME_KEY')
do_not_replace_table.append('GIPS_VIDEO_FRAME_DELTA')
do_not_replace_table.append('GIPS_VIDEO_FRAME_GOLDEN')
do_not_replace_table.append('GIPS_VIDEO_FRAME_DELTA_KEY')
do_not_replace_table.append('GIPS_PacketType')
do_not_replace_table.append('GIPS_PACKET_TYPE_RTP')
do_not_replace_table.append('GIPS_PACKET_TYPE_KEEP_ALIVE')
do_not_replace_table.append('GIPS_AudioLayers')
do_not_replace_table.append('GIPS_AUDIO_PLATFORM_DEFAULT')
do_not_replace_table.append('GIPS_AUDIO_WINDOWS_WAVE')
do_not_replace_table.append('GIPS_AUDIO_WINDOWS_CORE')
do_not_replace_table.append('GIPS_AUDIO_LINUX_ALSA')
do_not_replace_table.append('GIPS_AUDIO_LINUX_PULSE')
do_not_replace_table.append('GIPS_AUDIO_FORMAT')
do_not_replace_table.append('GIPS_PCM_16_16KHZ')
do_not_replace_table.append('GIPS_PCM_16_8KHZ')
do_not_replace_table.append('GIPS_G729')
do_not_replace_table.append('GIPSAMRmode')
do_not_replace_table.append('GIPS_RFC3267_BWEFFICIENT')
do_not_replace_table.append('GIPS_RFC3267_OCTETALIGNED')
do_not_replace_table.append('GIPS_RFC3267_FILESTORAGE')
do_not_replace_table.append('GIPS_NCModes')
do_not_replace_table.append('GIPS_NC_OFF')
do_not_replace_table.append('GIPS_NC_MILD')
do_not_replace_table.append('GIPS_NC_MODERATE')
do_not_replace_table.append('GIPS_NC_AGGRESSIVE')
do_not_replace_table.append('GIPS_NC_VERY_AGGRESSIVE')
do_not_replace_table.append('GIPS_AGCModes')
do_not_replace_table.append('GIPS_AGC_OFF')
do_not_replace_table.append('GIPS_AGC_ANALOG')
do_not_replace_table.append('GIPS_AGC_DIGITAL')
do_not_replace_table.append('GIPS_AGC_STANDALONE_DIG')
do_not_replace_table.append('GIPS_ECModes')
do_not_replace_table.append('GIPS_EC_UNCHANGED')
do_not_replace_table.append('GIPS_EC_DEFAULT')
do_not_replace_table.append('GIPS_EC_CONFERENCE')
do_not_replace_table.append('GIPS_EC_AEC')
do_not_replace_table.append('GIPS_EC_AES')
do_not_replace_table.append('GIPS_EC_AECM')
do_not_replace_table.append('GIPS_EC_NEC_IAD')
do_not_replace_table.append('GIPS_AESModes')
do_not_replace_table.append('GIPS_AES_DEFAULT')
do_not_replace_table.append('GIPS_AES_NORMAL')
do_not_replace_table.append('GIPS_AES_HIGH')
do_not_replace_table.append('GIPS_AES_ATTENUATE')
do_not_replace_table.append('GIPS_AES_NORMAL_SOFT_TRANS')
do_not_replace_table.append('GIPS_AES_HIGH_SOFT_TRANS')
do_not_replace_table.append('GIPS_AES_ATTENUATE_SOFT_TRANS')
do_not_replace_table.append('GIPS_AECMModes')
do_not_replace_table.append('GIPS_AECM_QUIET_EARPIECE_OR_HEADSET')
do_not_replace_table.append('GIPS_AECM_EARPIECE')
do_not_replace_table.append('GIPS_AECM_LOUD_EARPIECE')
do_not_replace_table.append('GIPS_AECM_SPEAKERPHONE')
do_not_replace_table.append('GIPS_AECM_LOUD_SPEAKERPHONE')
do_not_replace_table.append('AECM_LOUD_SPEAKERPHONE')
do_not_replace_table.append('GIPS_VAD_CONVENTIONAL')
do_not_replace_table.append('GIPS_VAD_AGGRESSIVE_LOW')
do_not_replace_table.append('GIPS_VAD_AGGRESSIVE_MID')
do_not_replace_table.append('GIPS_VAD_AGGRESSIVE_HIGH')
do_not_replace_table.append('GIPS_NetEQModes')
do_not_replace_table.append('GIPS_NETEQ_DEFAULT')
do_not_replace_table.append('GIPS_NETEQ_STREAMING')
do_not_replace_table.append('GIPS_NETEQ_FAX')
do_not_replace_table.append('GIPS_NetEQBGNModes')
do_not_replace_table.append('GIPS_BGN_ON')
do_not_replace_table.append('GIPS_BGN_FADE')
do_not_replace_table.append('GIPS_BGN_OFF')
do_not_replace_table.append('GIPS_OnHoldModes')
do_not_replace_table.append('GIPS_HOLD_SEND_AND_PLAY')
do_not_replace_table.append('GIPS_HOLD_SEND_ONLY')
do_not_replace_table.append('GIPS_HOLD_PLAY_ONLY')
do_not_replace_table.append('GIPS_PayloadFrequencies')
do_not_replace_table.append('GIPS_FREQ_8000_HZ')
do_not_replace_table.append('GIPS_FREQ_16000_HZ')
do_not_replace_table.append('GIPS_FREQ_32000_HZ')
do_not_replace_table.append('GIPS_TelephoneEventDetectionMethods')
do_not_replace_table.append('GIPS_IN_BAND')
do_not_replace_table.append('GIPS_OUT_OF_BAND')
do_not_replace_table.append('GIPS_IN_AND_OUT_OF_BAND')
do_not_replace_table.append('GIPS_ProcessingTypes')
do_not_replace_table.append('GIPS_PLAYBACK_PER_CHANNEL')
do_not_replace_table.append('GIPS_PLAYBACK_ALL_CHANNELS_MIXED')
do_not_replace_table.append('GIPS_RECORDING_PER_CHANNEL')
do_not_replace_table.append('GIPS_RECORDING_ALL_CHANNELS_MIXED')
do_not_replace_table.append('GIPS_StereoChannel')
do_not_replace_table.append('GIPS_StereoLeft')
do_not_replace_table.append('GIPS_StereoRight')
do_not_replace_table.append('GIPS_StereoBoth')
do_not_replace_table.append('GIPS_stat_val')
do_not_replace_table.append('GIPS_P56_statistics')
do_not_replace_table.append('GIPS_echo_statistics')
do_not_replace_table.append('GIPS_NetworkStatistics')
do_not_replace_table.append('GIPS_JitterStatistics')
do_not_replace_table.append('GIPSVideoRawType')
do_not_replace_table.append('GIPS_VIDEO_I420')
do_not_replace_table.append('GIPS_VIDEO_YV12')
do_not_replace_table.append('GIPS_VIDEO_YUY2')
do_not_replace_table.append('GIPS_VIDEO_UYVY')
do_not_replace_table.append('GIPS_VIDEO_IYUV')
do_not_replace_table.append('GIPS_VIDEO_ARGB')
do_not_replace_table.append('GIPS_VIDEO_RGB24')
do_not_replace_table.append('GIPS_VIDEO_RGB565')
do_not_replace_table.append('GIPS_VIDEO_ARGB4444')
do_not_replace_table.append('GIPS_VIDEO_ARGB1555')
do_not_replace_table.append('GIPS_VIDEO_MJPG')
do_not_replace_table.append('GIPS_VIDEO_NV12')
do_not_replace_table.append('GIPS_VIDEO_NV21')
do_not_replace_table.append('GIPS_VIDEO_Unknown')
do_not_replace_table.append('GIPSVideoLayouts')
do_not_replace_table.append('GIPS_LAYOUT_NONE')
do_not_replace_table.append('GIPS_LAYOUT_DEFAULT')
do_not_replace_table.append('GIPS_LAYOUT_ADVANCED1')
do_not_replace_table.append('GIPS_LAYOUT_ADVANCED2')
do_not_replace_table.append('GIPS_LAYOUT_ADVANCED3')
do_not_replace_table.append('GIPS_LAYOUT_ADVANCED4')
do_not_replace_table.append('GIPS_LAYOUT_FULL')
do_not_replace_table.append('KGIPSConfigParameterSize')
do_not_replace_table.append('KGIPSPayloadNameSize')
do_not_replace_table.append('GIPSVideoCodecH263')
do_not_replace_table.append('GIPSVideoH264Packetization')
do_not_replace_table.append('GIPS_H264_SingleMode')
do_not_replace_table.append('GIPS_H264_NonInterleavedMode')
do_not_replace_table.append('GIPSVideoCodecComplexity')
do_not_replace_table.append('GIPSVideoCodec_Complexity_Normal')
do_not_replace_table.append('GIPSVideoCodec_Comlexity_High')
do_not_replace_table.append('GIPSVideoCodec_Comlexity_Higher')
do_not_replace_table.append('GIPSVideoCodec_Comlexity_Max')
do_not_replace_table.append('GIPSVideoCodecH264')
do_not_replace_table.append('GIPSVideoH264Packetization')
do_not_replace_table.append('GIPSVideoCodecComplexity')
do_not_replace_table.append('GIPSVideoCodecProfile')
do_not_replace_table.append('KGIPSConfigParameterSize')
do_not_replace_table.append('KGIPSMaxSVCLayers')
do_not_replace_table.append('GIPSVideoH264LayerTypes')
do_not_replace_table.append('GIPS_H264SVC_Base')
do_not_replace_table.append('GIPS_H264SVC_Extend_2X2')
do_not_replace_table.append('GIPS_H264SVC_Extend_1X1')
do_not_replace_table.append('GIPS_H264SVC_Extend_MGS')
do_not_replace_table.append('GIPS_H264SVC_Extend_1_5')
do_not_replace_table.append('GIPS_H264SVC_Extend_Custom')
do_not_replace_table.append('GIPSVideoH264LayersProperties')
do_not_replace_table.append('GIPSVideoH264LayerTypes')
do_not_replace_table.append('GIPSVideoH264Layers')
do_not_replace_table.append('GIPSVideoH264LayersProperties')
do_not_replace_table.append('GIPSVideoCodecH264SVC')
do_not_replace_table.append('GIPSVideoCodecComplexity')
do_not_replace_table.append('GIPSVideoCodecProfile')
do_not_replace_table.append('GIPSVideoH264Layers')
do_not_replace_table.append('GIPSVideoCodecVP8')
do_not_replace_table.append('GIPSVideoCodecComplexity')
do_not_replace_table.append('GIPSVideoCodecMPEG')
do_not_replace_table.append('GIPSVideoCodecGeneric')
do_not_replace_table.append('GIPSVideoCodecType')
do_not_replace_table.append('GIPSVideoCodec_H263')
do_not_replace_table.append('GIPSVideoCodec_H264')
do_not_replace_table.append('GIPSVideoCodec_H264SVC')
do_not_replace_table.append('GIPSVideoCodec_VP8')
do_not_replace_table.append('GIPSVideoCodec_MPEG4')
do_not_replace_table.append('GIPSVideoCodec_I420')
do_not_replace_table.append('GIPSVideoCodec_RED')
do_not_replace_table.append('GIPSVideoCodec_ULPFEC')
do_not_replace_table.append('GIPSVideoCodec_Unknown')
do_not_replace_table.append('GIPSVideoCodecUnion')
do_not_replace_table.append('GIPSVideoCodecH263')
do_not_replace_table.append('GIPSVideoCodecH264')
do_not_replace_table.append('GIPSVideoCodecH264SVC')
do_not_replace_table.append('GIPSVideoCodecVP8')
do_not_replace_table.append('GIPSVideoCodecMPEG4')
do_not_replace_table.append('GIPSVideoCodecGeneric')
do_not_replace_table.append('GIPSVideoCodec')
do_not_replace_table.append('GIPSVideoCodecType')
do_not_replace_table.append('GIPSVideoCodecUnion')
do_not_replace_table.append('GIPSAudioFrame')
do_not_replace_table.append('GIPS_CodecInst')
do_not_replace_table.append('GIPS_FileFormats')
do_not_replace_table.append('GIPSTickTime')
do_not_replace_table.append('GIPS_Word64')
do_not_replace_table.append('GIPS_UWord64')
do_not_replace_table.append('GIPS_Word32')
do_not_replace_table.append('GIPS_UWord32')
do_not_replace_table.append('GIPS_Word16')
do_not_replace_table.append('GIPS_UWord16')
do_not_replace_table.append('GIPS_Word8')
do_not_replace_table.append('GIPS_UWord8')

if((len(sys.argv) != 2) and (len(sys.argv) != 3)):
    print 'parameters are: parent directory [--commit]'
    quit()

if((len(sys.argv) == 3) and (sys.argv[2] != '--commit')):
    print 'parameters are: parent directory [--commit]'
    quit()

commit = (len(sys.argv) == 3)

directory = sys.argv[1];
if(not filemanagement.pathexist(directory)):
    print 'path ' + directory + ' does not exist'
    quit()

# APIs are all in h-files
extension = '.h'

# All h-files
files_to_modify = filemanagement.listallfilesinfolder(directory,\
                                                      extension)

def isinmanualremovetable( compare_word ):
    for old_word, new_word in manual_replace_table:
        if(old_word == compare_word):
            return True
    return False

# Begin
# This function looks at each line and decides which words should be replaced
# that is this is the only part of the script that you will ever want to change!
def findstringstoreplace(line):
    original_line = line
# Dont replace compiler directives
    if(line[0] == '#'):
        return []
# Dont allow global removal of namespace gips since it is very intrusive
    for sub_string_compare in do_not_replace_line_table:
        index = stringmanipulation.issubstring(line,sub_string_compare)
        if(index != -1):
            return []

    return_value = []

    line = stringmanipulation.removeccomment(line)
    line = stringmanipulation.whitespacestoonespace(line)
    if(len(line) == 0):
        return []
    if(line[0] == '*'):
        return []
    index = stringmanipulation.issubstring(line,prefix_to_filter)
    while index >= 0:
        dont_store_hit = False
        word_position = stringmanipulation.getword(line, index)
        start_of_word = word_position[0]
        size_of_word = word_position[1]
        end_of_word = start_of_word + size_of_word
        old_word = line[start_of_word:end_of_word]
        if(isinmanualremovetable(old_word)):
            dont_store_hit = True
        if((end_of_word + 2 < len(line)) and\
           name_space_to_ignore == line[start_of_word:end_of_word+2]):
            dont_store_hit = True

        result = stringmanipulation.removeprefix(old_word,prefix_to_filter)
        new_word = result[1]
        for word_to_filter in words_to_filter:
            new_word = stringmanipulation.removealloccurances(new_word,word_to_filter)
        result = stringmanipulation.removeprefix(new_word,'_')
        new_word = result[1]
        new_word = stringmanipulation.fixabbreviations(new_word)
        new_word = stringmanipulation.removealloccurances(new_word,'_')
        if(not dont_store_hit):
            return_value.append([old_word,new_word])
# remove the word we found from the string so we dont find it again
        line = line[0:start_of_word] + line[end_of_word:len(line)]
        index = stringmanipulation.issubstring(line,'GIPS')

    return return_value
# End

# loop through all files
for path, file_name in files_to_modify:
#    if(file_name != 'GIPSTickUtil.h'):
#        continue
    full_file_name = path + file_name
    file_pointer = open(full_file_name,'r')
#    print file_name
#loop through all lines
    for line in file_pointer:
#        print line
        local_replace_string = findstringstoreplace(line)
        #print local_replace_string
        if(len(local_replace_string) != 0):
            replace_table.extend(local_replace_string)


# we have built our replace table now
replace_table = stringmanipulation.removeduplicates( replace_table )
replace_table = stringmanipulation.ordertablesizefirst( replace_table )
replace_table = stringmanipulation.complement(replace_table,\
                                              do_not_replace_table)

def replaceoriginal( path,my_table ):
    size_of_table = len(my_table)
    for index in range(len(my_table)):
        old_name = my_table[index][0]
        new_name = my_table[index][1]
        filemanagement.replacestringinfolder(path, old_name, new_name,\
                                             ".h")
        print (100*index) / (size_of_table*2)

def replaceall( my_table, extension_list ):
    size_of_table = len(my_table)
    for index in range(len(my_table)):
        old_name = my_table[index][0]
        new_name = my_table[index][1]
        new_name = new_name
        for extension in extensions_to_edit:
            filemanagement.replacestringinallsubfolders(old_name, new_name,
                                                        extension)
        print 100*(size_of_table + index) / (size_of_table*2)


if(commit):
    print 'commiting'
    replace_table = stringmanipulation.removenochange(replace_table)
    p4commands.checkoutallfiles()
    replaceoriginal(directory,replace_table)
    replaceall(replace_table,extensions_to_edit)
    p4commands.revertunchangedfiles()
else:
    for old_name, new_name in replace_table:
        print 'Going to replace [' + old_name + '] with [' + new_name + ']'