# This Python file uses the following encoding: utf-8 import glob import os ''' Fetch all the directories, and display all the unused properties. Check java, ftl and xml files. ''' dirToScan = '/home/quentin/dev/sources' propertiesDir = '/home/quentin/dev/sources/src/main/resources/messages' files = os.listdir(propertiesDir) #Rajouter ici les fichier à ignorer specific_files = ['.svn'] properties = [] for file in files: if file not in specific_files: cursor = open(propertiesDir+'/'+file,'r') #read the file and get the properties lines = cursor.readlines() back = False for line in lines: #at least a ligne with a character. if len(line)>1 : #if the last line is a \, we skip this line (it's a multi-line property), otherwise we append the property when we find a "=" . if line.find("=") != -1 and not back: #dynamic error messages: prop = line[:line.index("=")] message = line[line.index("="):len(line)-1] if line.find("error.") != -1 and (line.find(".description=") != -1 or line.find(".title=") != -1 or line.find(".back=") != -1) : #we delete the last term (dynamicly generated so we can't find it) value = prop[:prop.rfind(".")] #print(prop+" => "+value) else : value = prop properties.append({"value" : value, "file" : file, "prop": prop, "message": message}) #we find the last letter of the message (different than " ") lastLetter = " " for i in range(len(line),0,-1): if line[i-2:i-1] != " ": lastLetter = line[i-2:i-1] break #if the lastLetter is \, means we don't care about the next line if lastLetter == "\\" : back = True else : back = False def scanFolder(dir): files = glob.glob(dir+'/*') for file in files: if os.path.isdir(file): scanFolder(file) elif file.find(".java") != -1 or file.find(".ftl") != -1 or file.find(".xml") != -1 : cursor = open(file,'r') lines = cursor.readlines() i=0 for line in lines: i=i+1 for prop in properties: if line.find(prop['value']) != -1: print("removed "+prop['value']+" in "+file+" line "+str(i)) properties.remove(prop) scanFolder(dirToScan) old_file = "" for prop in properties: if prop['file'] != old_file: print("----------------------------------") print(prop['file']) print("----------------------------------") old_file = prop['file'] if prop['value'] != prop['prop'] : print(prop['value']+" ("+prop['message']+") (real property:"+prop['prop']+")") else: print(prop['value']+" ("+prop['message']+")")