build/buildutils/checkdistpolicyfiles.py
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 #!/usr/bin/python
       
     2 #
       
     3 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 # All rights reserved.
       
     5 # This component and the accompanying materials are made available
       
     6 # under the terms of "Eclipse Public License v1.0"
       
     7 # which accompanies this distribution, and is available
       
     8 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 #
       
    10 # Initial Contributors:
       
    11 # Nokia Corporation - initial contribution.
       
    12 #
       
    13 # Contributors:
       
    14 #
       
    15 # Description:
       
    16 #   Searches all the distribution.file.s60 files recursively starting from 
       
    17 #   a directory given as parameter, reports about missing files, generates
       
    18 #   usage report per distribution policy ID and generates a summary.
       
    19 
       
    20 import os, sys
       
    21 
       
    22 def main():
       
    23 
       
    24     missingList = []    # List containing directories without policy file
       
    25     idLists = {}        # Set containing lists of directories for each distribution policy ID
       
    26 
       
    27     findFiles(sys.argv[1], missingList, idLists)
       
    28     
       
    29     missingList.sort();
       
    30     
       
    31     for id in idLists:
       
    32         idLists[id].sort
       
    33     
       
    34     ids = idLists.keys()
       
    35     ids.sort()
       
    36     
       
    37     print "Analysis started from directory: " + sys.argv[1]
       
    38     print ""
       
    39     
       
    40     print "Directories without distribution policy file:"
       
    41     for dir in missingList:
       
    42         print "    " + dir
       
    43     print ""
       
    44     
       
    45     for id in ids:
       
    46         print "Directories with distribution policy ID " + id + ":"
       
    47         list = idLists[id]
       
    48         for dir in list:
       
    49             print "    " + dir
       
    50         print ""
       
    51         
       
    52     
       
    53 # Go through the directories recursively
       
    54 #   If some directory doesn't contain policy file, add that directory to the list of "directories without policy file"
       
    55 #   Else read the policy ID from the file and add the directory to the list corresponding to the found ID
       
    56 
       
    57 
       
    58 def findFiles(startDir, missingList, idLists):
       
    59 
       
    60     def visitFun(arg, dirname, names):
       
    61         try:
       
    62             f = open(dirname + "\\distribution.policy.s60")
       
    63             id = f.readline()
       
    64             if id[len(id)-1] == '\n':
       
    65                 id = id[0:len(id)-1]
       
    66             f.close()
       
    67             
       
    68             idList = idLists.get(id);
       
    69             if idList == None:
       
    70                 idLists[id] = [ dirname ]
       
    71             else:
       
    72                 idList.append(dirname)
       
    73                 
       
    74         except IOError:
       
    75             # file was not found
       
    76             missingList.append(dirname)            
       
    77             
       
    78             
       
    79     os.path.walk(startDir, visitFun, None)
       
    80 
       
    81 
       
    82 if __name__ == "__main__":
       
    83     main()