aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Stenger <christian.stenger@qt.io>2018-12-07 12:08:28 +0100
committerChristian Stenger <christian.stenger@qt.io>2019-01-14 06:36:40 +0000
commit6798b004706c762974bea3e9363aed8f42876a11 (patch)
tree6b8a16dda0a97f79e88e772acd7239dd564352cc
parentfc58cb88c0623a3c0d083b2af9ab826e6bd308ff (diff)
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 <robert.loehning@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rwxr-xr-xtests/system/tools/findUnusedObjects.py46
1 files changed, 34 insertions, 12 deletions
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()