buildframework/helium/sf/python/pythoncore/lib/CreateZipInput.py
author lorewang
Wed, 01 Dec 2010 16:05:36 +0800
changeset 715 e0739b8406dd
parent 587 85df38eb4012
permissions -rw-r--r--
Specify extenal tool with path
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : CreateZipInput.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
""" Script that generate makefile for single archiving configuration. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import tempfile
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
# setting the egg cache directory to a pid specific location.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
# this should prevent issues with concurrent threads.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
if not os.environ.has_key('PYTHON_EGG_CACHE') or os.environ['PYTHON_EGG_CACHE'] == None: 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
    os.environ['PYTHON_EGG_CACHE'] = tempfile.gettempdir() + "/" + str(os.getpid())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import configuration
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import archive
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import sys
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
from optparse import OptionParser
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
_logger = logging.getLogger('CreateZipInput')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
_logger.setLevel(logging.INFO)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
def main():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
    """ The application main. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
    cli = OptionParser(usage="%prog [options]")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
    cli.add_option("--filename", help="Configuration file") 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
    cli.add_option("--config", help="Config to load (spec name).")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
    cli.add_option("--id", help="Config number to execute", type="int")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
    cli.add_option("--output", help="Output file")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
    cli.add_option("--writertype", help="Writer Type")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
                   
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
    opts, dummy_args = cli.parse_args()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
    if not opts.filename:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        cli.print_help()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        sys.exit(-1)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
    if not opts.config:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        cli.print_help()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        sys.exit(-2)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
    if opts.id == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        cli.print_help()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        sys.exit(-3)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
    if not opts.output:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
        cli.print_help()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        sys.exit(-4)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
    if not opts.writertype:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        cli.print_help()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        sys.exit(-5)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
    _logger.info("Loading %s..." % opts.filename) 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
    builder = configuration.NestedConfigurationBuilder(open(opts.filename, 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    configset = builder.getConfiguration()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
    _logger.info("Getting %s..." % opts.config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    configs = configset.getConfigurations(opts.config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    if len(configs) > 0 and int(opts.id) >= 0 and int(opts.id) < len(configs):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        _logger.info("Generating %s.%s as %s..." % (opts.config, opts.id, opts.output))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        prebuilder = archive.ArchivePreBuilder(configuration.ConfigurationSet(configs), opts.config, opts.writertype, int(opts.id))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
        prebuilder.write(opts.output)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
if __name__ == "__main__":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
    main()