Beispiel #1
0
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
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
def findincludeguardidentifier(line):
    for begin_identifier in include_guard_begin_identifier:
        line = stringmanipulation.removealloccurances(line,begin_identifier)
    for second_identifier in include_guard_begin_identifier:
        line = stringmanipulation.removealloccurances(line,second_identifier)
    removed_prefix = [True,'']
    line = stringmanipulation.whitespacestoonespace(line)
    while(removed_prefix[0]):
        removed_prefix = stringmanipulation.removeprefix(line,' ')
        line = removed_prefix[1]
    line = stringmanipulation.removealloccurances(line,'(')
    if(line == ''):
        return ''
    word_pos = stringmanipulation.getword(line,0)
    return_value = line[0:word_pos[1]]
    return_value = return_value.rstrip('\r\n')
    return return_value
def findincludeguardidentifier(line):
    for begin_identifier in include_guard_begin_identifier:
        line = stringmanipulation.removealloccurances(line, begin_identifier)
    for second_identifier in include_guard_begin_identifier:
        line = stringmanipulation.removealloccurances(line, second_identifier)
    removed_prefix = [True, '']
    line = stringmanipulation.whitespacestoonespace(line)
    while (removed_prefix[0]):
        removed_prefix = stringmanipulation.removeprefix(line, ' ')
        line = removed_prefix[1]
    line = stringmanipulation.removealloccurances(line, '(')
    if (line == ''):
        return ''
    word_pos = stringmanipulation.getword(line, 0)
    return_value = line[0:word_pos[1]]
    return_value = return_value.rstrip('\r\n')
    return return_value
        continue

    new_file_name = ''
    is_exception = False
    for exception_name,exception_name_new in exceptions:
        if(filename == exception_name):
            is_exception = True
            new_file_name = exception_name_new
            break

    if(not is_exception):
        new_file_name = filename

        new_file_name = stringmanipulation.removeallprefix(new_file_name,\
                                                       'gips')
        new_file_name = stringmanipulation.removealloccurances(new_file_name,\
                                                       'module')
        new_file_name = stringmanipulation.changeextension(new_file_name,\
                                           old_extension,\
                                           new_extension)
        new_file_name = stringmanipulation.fixabbreviations( new_file_name )
        new_file_name = stringmanipulation.lowercasewithunderscore(new_file_name)
    if(not commit):
        print 'File ' + filename + ' will be replaced with ' + new_file_name
        continue
    full_new_file_name = path_dir + new_file_name
    full_old_file_name = path_dir + filename
    if(full_new_file_name != full_old_file_name):
        p4commands.integratefile(full_old_file_name,full_new_file_name)
    else:
        print 'skipping ' + new_file_name + ' due to no change'
    for extension in extensions: