buildframework/helium/sf/python/pythoncore/lib/idoprep.py
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
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        : idoprep.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
""" Modules related to ido-prep """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import re
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import symrec
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import traceback
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import ido
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
logging.basicConfig(level=logging.INFO)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    30
_logger = logging.getLogger("check_latest_release")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
def validate(grace, service, product, release):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
    """ Validate s60 grace server, s60 grace service, s60 grace product and 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
        s60 grace release are set.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
    """    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
    if not grace:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    37
        raise EnvironmentError("Property 's60.grace.server' is not defined.")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
    if not service:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    39
        raise EnvironmentError("Property 's60.grace.service' is not defined.")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
    if not product:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    41
        raise EnvironmentError("Property 's60.grace.product' is not defined.")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
    if not release:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    43
        raise EnvironmentError("Property 's60.grace.release' is not defined.")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
def get_s60_env_details(grace, service, product, release, rev, cachefilename, s60gracecheckmd5, s60graceusetickler):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
    """ Return s60 environ details """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
    validate(grace, service, product, release)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
    revision = r'(_\d{3})?'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
    if rev != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
        revision = rev
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
    if cachefilename:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    53
        _logger.info(str("Using cache file: %s" % cachefilename))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
    checkmd5 = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
    if s60gracecheckmd5 != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
        checkmd5 = str(s60gracecheckmd5).lower()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        checkmd5 = ((checkmd5 == "true") or (checkmd5 == "1") or (checkmd5 == "on"))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
    branch = os.path.join(grace, service, product)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
    if not os.path.exists(branch):
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    62
        raise IOError("Error occurred: Could not find directory %s" % branch)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
    result = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    for rel in os.listdir(branch):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        relpath = os.path.join(branch, rel)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    67
        _logger.info("Checking: %s" % str(relpath))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
        res = re.match(r"%s%s$" % (release, revision), rel, re.I)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        if res != None:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    70
            _logger.info("Found: %s" % str(relpath))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
            result.append(relpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
    result.sort(reverse=True)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
    use_tickler = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
    tickler_validation = str(s60graceusetickler).lower()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
    if tickler_validation != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        use_tickler = ((tickler_validation == "true") or (tickler_validation == "1"))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
    validresults = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
    for rel in result:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
        try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
            metadata_filename = symrec.find_latest_metadata(str(rel))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
            if metadata_filename is not None and os.path.exists(metadata_filename):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    82
                _logger.info(str("Validating: %s" % metadata_filename))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
                if (use_tickler):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
                    validator = symrec.ValidateTicklerReleaseMetadata(metadata_filename, cachefilename)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
                    validator = symrec.ValidateReleaseMetadataCached(metadata_filename, cachefilename)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
                if validator.is_valid(checkmd5):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    88
                    _logger.info(str("%s is valid." % rel))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
                    validresults.append(rel)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
                    break
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
                else:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    92
                    _logger.info(str("%s is not a valid release." % rel))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
            elif metadata_filename is None:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    94
                _logger.info(str("Could not find the release metadata file under %s" % rel))
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    95
        except IOError, exc:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    96
            _logger.warning(str("WARNING: %s: %s" % (rel , exc)))
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    97
            _logger.warning(("%s is not a valid release." % rel))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
            traceback.print_exc()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
    result = validresults
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
    if len(result) == 0:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   102
        raise EnvironmentError("Error finding GRACE release.")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
    print result[0]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
    return result
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
def get_version(buiddrive, resultname):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
    """ Return s60 version """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
    vfile = os.path.join(buiddrive + os.sep, 's60_version.txt')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
    version = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
    if (os.path.exists(vfile)):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   111
        _logger.info("Are we still up-to-date compare to %s" % str(vfile))
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   112
        f_file = open(str(vfile), 'r')
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   113
        version = f_file.readline()
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   114
        _logger.info(str("'%s' == '%s'" % (version, resultname)))
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   115
        f_file.close()
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
    else:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   117
        _logger.info("Version file not found getting new environment...")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
    return version
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
def create_ado_mapping(sysdefconfig, adomappingfile, adoqualitymappingfile, builddrive, adoqualitydirs):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
    """ Creates ado mapping and ado quality mapping files """
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   122
    input_ = open(sysdefconfig, 'r')
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
    output = open(adomappingfile, 'w')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
    outputquality = open(adoqualitymappingfile, 'w')
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   125
    for sysdef in input_.readlines():
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
        sysdef = sysdef.strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
        if len(sysdef) > 0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
            print "Checking %s" % sysdef
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
            os.path.dirname(sysdef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
            location = ido.get_sysdef_location(sysdef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
            if location != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
                if os.sep == '\\':
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
                    sysdef = os.path.dirname(sysdef).replace('\\','/').replace(':','\\:')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
                    component = os.path.normpath(os.path.join(builddrive, os.environ['EPOCROOT'], location)).replace('\\','/').replace(':','\\:')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
                    sysdef = os.path.dirname(sysdef).replace('\\','/')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
                    if location.startswith('/'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
                        component = os.path.normpath(os.path.join(builddrive, location.lstrip('/'))).replace('\\','/')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
                    else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
                        component = os.path.normpath(os.path.join(builddrive, location)).replace('\\','/')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
                print "%s=%s\n" % (sysdef, component)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
                output.write("%s=%s\n" % (sysdef, component))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
                if adoqualitydirs == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
                    outputquality.write("%s=%s\n" % (sysdef, component))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
                else:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   146
                    for dir_ in adoqualitydirs.split(','):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   147
                        if os.path.normpath(dir_) == os.path.normpath(os.path.join(builddrive, os.environ['EPOCROOT'], location)):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
                            outputquality.write("%s=%s\n" % (sysdef, component))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
    outputquality.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
    output.close()
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   153
    input_.close()
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156