def checkParenthesis(item, index): global badParenthesisList global parenthesisCount global parenthesisFrontCount global parenthesisBackCount frontString = MCOM.getFront(item) backString = MCOM.getBack(item) frontCount = MCOM.frontPar(item, frontString) backCount = MCOM.backPar(item, backString) i = item.lstrip() frontCount = MCOM.frontPar(item, frontString) backCount = MCOM.backPar(item, backString) if not (frontCount == backCount) and (frontCount > 0 and backCount > 0): if frontCount > backCount: print "Mismatched parentheses count more '('s" else: print "Mismatched parentheses count more ')'s" if re.search("%s\(" % frontString, i, re.IGNORECASE): if re.search("\)%s" % backString, i, re.IGNORECASE): parenthesisCount += 1 return parenthesisCount else: parenthesisFrontCount += 1 return parenthesisFrontCount elif re.search("\)%s" % backString, i, re.IGNORECASE): parenthesisBackCount += 1 return parenthesisBackCount else: return badParenthesisList.append({"line": item, "index": index + 1})
def heavyLifter(i, lineCount): # Initalizing the variables that will be used frontString = MCOM.getFront(i) backString = MCOM.getBack(i) mes = "" replace = "" mymes = "" mymes2 = "" parFront = [] parBack = [] # Saves the spaceing before <comment> as a seperate variable commentIndex = i.lower().index("<comment") mes = i[:commentIndex] i = i[commentIndex:] nonBlank = True if frontString == "BLANKCOMMENT!" or backString == "BLANKCOMMENT!": nonBlank = False # C-Adds a "Please" if it doesn't already exist. This checks for "Please" following a "(" or any "<" tags if args.addplease and nonBlank: if ( re.search("%splease" % frontString, i, re.IGNORECASE) == None and re.search("%s\(please" % frontString, i, re.IGNORECASE) == None ): uncap = len(re.search(frontString, i, re.IGNORECASE).group(0)) uncapIndex = i.index(re.search(frontString, i, re.IGNORECASE).group(0)) uncap = uncap + uncapIndex if re.search("%s\(" % frontString, i, re.IGNORECASE): if re.search("%s\(\s*<[^>]*>" % frontString, i, re.IGNORECASE): mysearch = re.search("%s\(\s*<[^>]*>" % frontString, i, re.IGNORECASE).group(0) uncap = uncap + (len(mysearch) - uncap) else: uncap = uncap + 1 elif re.search("%s\(\n" % frontString, i, re.IGNORECASE): uncap = uncap + 2 uncap1 = i[uncap] t = i.replace(" ", "") if ( (t[uncap + 1].islower() or t[uncap + 1] == "<" or t[uncap + 1] == "/") or (t[uncap + 2].islower() or t[uncap + 2] == "<" or t[uncap + 2] == "/") or (t[uncap + 3].islower() or t[uncap + 3] == "<" or t[uncap + 3] == "/") ): uncap1 = uncap1.lower() please = "Please" else: please = "PLEASE" if re.search("%s\(\s*<[^>]*>" % frontString, i, re.IGNORECASE): x = re.search("%s\(\s*<[^>]*>" % frontString, i, re.IGNORECASE).group(0) mymes = x + please + " " + uncap1 i = re.sub("%s\(\s*<[^>]*>%s" % (frontString, re.escape(i[uncap])), mymes, i, flags=re.IGNORECASE) elif re.search("%s\(" % frontString, i, re.IGNORECASE): x = re.search("%s\(" % frontString, i, re.IGNORECASE).group(0) replace = "%s%s %s" % (x, please, uncap1) i = re.sub("%s\(%s" % (frontString, re.escape(i[uncap])), replace, i, flags=re.IGNORECASE) else: x = re.search(frontString, i, re.IGNORECASE).group(0) replace = "%s%s %s" % (x, please, uncap1) i = re.sub("%s%s" % (frontString, re.escape(i[uncap])), replace, i, flags=re.IGNORECASE) # C-Removes the "Please" if it exists. This checks for "Please" following a "(" or any "<" tags elif args.removeplease and nonBlank: recap = len(re.search(frontString, i, re.IGNORECASE).group(0)) + 1 if re.search("%s\(\s*<[^>]*>please" % frontString, i, re.IGNORECASE): mysearch = re.search("%s\(\s*<[^>]*>please" % frontString, i, re.IGNORECASE).group(0) recap = (recap + (len(mysearch) - recap)) + 1 x = re.search("%s\(\s*<[^>]*>" % frontString, i, re.IGNORECASE).group(0) mymes = x + i[recap].upper() i = re.sub("%s\(\s*<[^>]*>please %s" % (frontString, i[recap]), mymes, i, flags=re.IGNORECASE) elif re.search("%splease" % frontString, i, re.IGNORECASE): recap += 6 x = re.search(frontString, i, re.IGNORECASE).group(0) replace = "%s%s" % (x, i[recap].upper()) i = re.sub("%splease %s" % (frontString, i[recap]), replace, i, flags=re.IGNORECASE) elif re.search("%s\(please" % frontString, i, re.IGNORECASE): recap += 7 x = re.search("%s\(" % frontString, i, re.IGNORECASE).group(0) replace = "%s%s" % (x, i[recap].upper()) i = re.sub("%s\(please %s" % (frontString, i[recap]), replace, i, flags=re.IGNORECASE) # C-Checks for and removes the starting "(" and ending ")" if it exists if args.removeParenthesis and nonBlank: frontCount = MCOM.frontPar(i, frontString) backCount = MCOM.backPar(i, backString) x = re.search(frontString, i, re.IGNORECASE).group(0) y = re.search(backString, i, re.IGNORECASE).group(0) if re.search("\)\s*\.%s" % backString, i, re.IGNORECASE): y = re.search("\)\s*\.%s" % backString, i, re.IGNORECASE).group(0) backString = "\s*\." + backString if ( frontCount == backCount and (frontCount > 0 and backCount > 0) and ( not (re.search("\)%s" % backString, i, re.IGNORECASE)) or not (re.search("%s\(" % frontString, i, re.IGNORECASE)) ) ): print "Line %s Skipped: This comment has %s '('s and %s ')'s. These do not encapsulate all of the text." % ( lineCount, frontCount, backCount, ) elif re.search("%s\(" % frontString, i, re.IGNORECASE) and re.search("\)%s" % backString, i, re.IGNORECASE): i = re.sub("%s\(" % frontString, x, i, flags=re.IGNORECASE) i = re.sub("\)%s" % backString, y, i, flags=re.IGNORECASE) elif not (frontCount == backCount) and (frontCount > 0 and backCount > 0): print "Skipping line %s: uneven counts: %s '('s and %s ')'s." % (lineCount, frontCount, backCount) elif re.search("%s\(" % frontString, i, re.IGNORECASE) and not ( re.search("\)%s" % backString, i, re.IGNORECASE) ): print "Line %s has %s '('s and %s ')'s. We have removed the starting '(' but you may want to check this comment." % ( lineCount, frontCount, backCount, ) i = re.sub("%s\(" % frontString, x, i, flags=re.IGNORECASE) elif not (re.search("%s\(" % frontString, i, re.IGNORECASE)) and re.search( "\)%s" % backString, i, re.IGNORECASE ): print "Line %s has %s '('s and %s ')'s. We have removed the ending ')' but you may want to check this comment." % ( lineCount, frontCount, backCount, ) i = re.sub("\)%s" % backString, y, i, flags=re.IGNORECASE) # C-Checks for and adds the starting "(" and ending ")" if it doesn't exist if args.addParenthesis and nonBlank: hasPeriod = False frontCount = MCOM.frontPar(i, frontString) backCount = MCOM.backPar(i, backString) x = re.search(frontString, i, re.IGNORECASE).group(0) y = re.search(backString, i, re.IGNORECASE).group(0) if re.search("\)\s*\.%s" % backString, i, re.IGNORECASE): y = re.search("\)\s*\.%s" % backString, i, re.IGNORECASE).group(0) backString = "\s*\." + backString hasPeriod = True if frontCount == backCount and (frontCount > 0 and backCount > 0): if re.search("[^\)\s]%s" % backString, i, re.IGNORECASE) or re.search( "%s[^\(\s]" % frontString, i, re.IGNORECASE ): print "Line %s Note: This comment has %s '('s and %s ')'s. These do not encapsulate all of the text in this tag." % ( lineCount, frontCount, backCount, ) elif re.search("%s[^\(\s]" % frontString, i, re.IGNORECASE) and re.search( "[^\)\s]%s" % backString, i, re.IGNORECASE ): i = re.sub("%s" % frontString, "%s(" % x, i, flags=re.IGNORECASE) i = re.sub("%s" % backString, ")%s" % y, i, flags=re.IGNORECASE) elif not (frontCount == backCount) and (frontCount > 0 and backCount > 0): print "Skipping line %s: uneven counts: %s '('s and %s ')'s." % (lineCount, frontCount, backCount) elif re.search("%s[^\(\s]" % frontString, i, re.IGNORECASE) and not ( re.search("[^\)\s]%s" % backString, i, re.IGNORECASE) ): print "Line %s has %s '('s and %s ')'s. We have added the starting '(' but you may want to check this comment." % ( lineCount, frontCount, backCount, ) i = re.sub("%s" % frontString, "%s(" % x, i, flags=re.IGNORECASE) elif not (re.search("%s[^\(\s]" % frontString, i, re.IGNORECASE)) and re.search( "[^\)\s]%s" % backString, i, re.IGNORECASE ): print "Line %s has %s '('s and %s ')'s. We have added the ending ')' but you may want to check this comment." % ( lineCount, frontCount, backCount, ) if hasPeriod: i = re.sub("%s" % backString, ".)%s" % y, i, flags=re.IGNORECASE) else: i = re.sub("%s" % backString, ")%s" % y, i, flags=re.IGNORECASE) backString = MCOM.getBack(i) # C-Adds a period to the end of every comment that doesn't already end in one. This checks for "." preceeding a ")" or any "<" tags. if args.add and nonBlank: x = re.search(backString, i, re.IGNORECASE).group() loopVar = True while loopVar: if re.search("['\")]%s" % backString, i, re.IGNORECASE): x = re.search("['\")]%s" % backString, i, re.IGNORECASE).group() backString = "['\")]" + backString else: loopVar = False if re.search("\.%s" % backString, i, re.IGNORECASE): pass elif re.search("[^.]%s" % backString, i, re.IGNORECASE): i = re.sub(backString, ".%s" % x, i, flags=re.IGNORECASE) tree1.write(mes + i) # C-Removes a period from the end of every comment that already ends in one. This checks for "." preceeding a ")" or any "<" tags. elif args.remove: x = re.search(backString, i, re.IGNORECASE).group() if re.search("\.%s" % backString, i, re.IGNORECASE): i = re.sub("\.%s" % backString, x, i, flags=re.IGNORECASE) elif re.search("\.\)%s" % backString, i, re.IGNORECASE): i = re.sub("\.\)%s" % backString, ")%s" % x, i, flags=re.IGNORECASE) tree1.write(mes + i) else: tree1.write(mes + i)