From 6798b004706c762974bea3e9363aed8f42876a11 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Fri, 7 Dec 2018 12:08:28 +0100 Subject: Tests: Allow shared folders in findUnusedObjects Depending on the directory layout chosen for arranging the squish tests the findUnusedObjects script might not work as expected. This patch enhances the script by adding another option that lets you specify locations of shared folders beside the default assumed (beside/below the location of the objects.map) Change-Id: I52d6bef0fecbbb2959a82ee662a7c7beaf01e00d Reviewed-by: Robert Loehning Reviewed-by: Christian Stenger --- tests/system/tools/findUnusedObjects.py | 46 ++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'tests/system') diff --git a/tests/system/tools/findUnusedObjects.py b/tests/system/tools/findUnusedObjects.py index 8597b04717..43b826f6b8 100755 --- a/tests/system/tools/findUnusedObjects.py +++ b/tests/system/tools/findUnusedObjects.py @@ -26,6 +26,7 @@ ############################################################################ import os +import platform import sys import tokenize from optparse import OptionParser @@ -37,11 +38,14 @@ lastToken = [None, None] stopTokens = ('OP', 'NAME', 'NUMBER', 'ENDMARKER') def parseCommandLine(): - global directory, onlyRemovable + global directory, onlyRemovable, sharedFolders parser = OptionParser("\n%prog [OPTIONS] [DIRECTORY]") parser.add_option("-o", "--only-removable", dest="onlyRemovable", action="store_true", default=False, help="list removable objects only") + parser.add_option("-s", dest="sharedFolders", + action="store", type="string", default="", + help="comma-separated list of shared folders") (options, args) = parser.parse_args() if len(args) == 0: directory = os.path.abspath(".") @@ -52,6 +56,7 @@ def parseCommandLine(): parser.print_help() sys.exit(1) onlyRemovable = options.onlyRemovable + sharedFolders = map(os.path.abspath, options.sharedFolders.split(',')) def collectObjects(): global objMap @@ -97,18 +102,35 @@ def handleDataFiles(openFile, separator): useCounts[stripped] = useCounts[stripped] + 1 def findUsages(): - global directory, objMap + global directory, objMap, sharedFolders suffixes = (".py", ".csv", ".tsv") - for root, dirnames, filenames in os.walk(directory): - for filename in filter(lambda x: x.endswith(suffixes), filenames): - currentFile = open(os.path.join(root, filename)) - if filename.endswith(".py"): - tokenize.tokenize(currentFile.readline, handle_token) - elif filename.endswith(".csv"): - handleDataFiles(currentFile, ",") - elif filename.endswith(".tsv"): - handleDataFiles(currentFile, "\t") - currentFile.close() + directories = [directory] + # avoid folders that will be processed anyhow + for shared in sharedFolders: + skip = False + tmpS = shared + "/" + for folder in directories: + tmpD = folder + "/" + if platform.system() in ('Microsoft', 'Windows'): + tmpS = tmpS.lower() + tmpD = tmpD.lower() + if tmpS.startswith(tmpD): + skip = True + break + if not skip: + directories.append(shared) + + for directory in directories: + for root, dirnames, filenames in os.walk(directory): + for filename in filter(lambda x: x.endswith(suffixes), filenames): + currentFile = open(os.path.join(root, filename)) + if filename.endswith(".py"): + tokenize.tokenize(currentFile.readline, handle_token) + elif filename.endswith(".csv"): + handleDataFiles(currentFile, ",") + elif filename.endswith(".tsv"): + handleDataFiles(currentFile, "\t") + currentFile.close() currentFile = open(objMap) tokenize.tokenize(currentFile.readline, handle_token) currentFile.close() -- cgit v1.2.1