# This Python file uses the following encoding: utf-8 import glob import os ''' Fetch all the directories, and display all the unused images. Check css, java, ftl, xml and .properties files. !!! Make sure you also scan sogenactif images ! !!! ''' dirToScan = '/home/quentin/dev/sources' imagesDir = '/home/quentin/dev/sources/src/main/webapp/images' #Rajouter ici les fichier à ignorer specific_files = ['.svn'] imageExts = ['.jpg', '.gif', '.png'] images = [] def findImages(dir): files = glob.glob(dir + '/*') for file in files: if file not in specific_files: if os.path.isdir(file): findImages(file) else: fileLower = file.lower() for imageExt in imageExts: if fileLower.find(imageExt) != -1 : name = file[file.rfind("/")+1:] images.append({"file" : file, "ext" : imageExt, "name": name}) break findImages(imagesDir) print(images) def scanFolder(dir): files = glob.glob(dir + '/*') for file in files: if os.path.isdir(file): scanFolder(file) elif file.find(".css") != -1 or file.find(".java") != -1 or file.find(".ftl") != -1 or file.find(".xml") != -1 or file.find(".properties") != -1 : cursor = open(file, 'r') lines = cursor.readlines() i = 0 for line in lines: i = i + 1 for image in images: if line.find(image['name']) != -1: print("removed " + image['name'] + " in " + file + " line " + str(i)) images.remove(image) scanFolder(dirToScan) old_file = "" for image in images: print(image['name'] + " (" + image['file'] + ")")