build/buildutils/compressmapfiles.py
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 import re,sys, os.path, subprocess
       
    18 
       
    19 # Pattern for .pkg file descriptions
       
    20 RE_FILE = re.compile('^"([^"]+)"-"([^"]+)"', re.MULTILINE)
       
    21 
       
    22 def main():
       
    23 
       
    24     if len(sys.argv) < 2 or len(sys.argv) > 3:
       
    25         print "Usage: compressmapfiles.py <pkgfile> [<mapfiles.zip>]"
       
    26         return 1
       
    27 
       
    28     pkgfile = sys.argv[1]
       
    29 
       
    30     mapfilezip = os.path.abspath("mapfiles.zip")
       
    31     if len(sys.argv) > 2:
       
    32         mapfilezip = os.path.abspath(sys.argv[2])
       
    33 
       
    34     # Read files in .pkg
       
    35     pkg = open(pkgfile).read()
       
    36 
       
    37     files = [match[0] for match in RE_FILE.findall(pkg)]
       
    38 
       
    39     # Find mapfiles
       
    40     mapfiles = [file + ".map" for file in files]
       
    41     mapfiles = [mapfile for mapfile in mapfiles if os.path.exists(mapfile)]
       
    42 
       
    43     if not mapfiles:
       
    44         return
       
    45 
       
    46     dir = os.path.dirname(mapfiles[0])
       
    47     mapfiles = [os.path.basename(file) for file in mapfiles]
       
    48 
       
    49     # Write mapfiles without path
       
    50     cmd = ["zip", "-@", mapfilezip]
       
    51     process = subprocess.Popen(args = cmd, stdin = subprocess.PIPE, cwd = dir)
       
    52     stdout, stderr = process.communicate(input = "\n".join(mapfiles))
       
    53 
       
    54     if process.returncode == 0 or process.returncode == 12:
       
    55         return 0
       
    56     return process.returncode
       
    57 
       
    58 
       
    59 if __name__ == "__main__":
       
    60     main()
       
    61