buildframework/helium/sf/python/pythoncore/lib/ats3/matti/MattiDrops.py
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 587 85df38eb4012
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
# -*- encoding: latin-1 -*-
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
#Name        : MattiDrops.py
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Part of     : Helium
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
#Description: Script for test drop generation and sending to execution to 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
#ATS3-system
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
""" create the MATTI test drop file for use on the test server """
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    24
# pylint: disable=R0902, R0903, R0912
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import re
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import sys
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import string
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import zipfile
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import logging 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
from optparse import OptionParser
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
from xml.etree import ElementTree as et
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    34
from jinja2 import Environment, PackageLoader # pylint: disable=F0401
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
# Shortcuts
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
E = et.Element
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
SE = et.SubElement
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
_logger = logging.getLogger('matti')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
class Configuration(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
    ATS3 drop generation configuration.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
    def __init__(self, opts):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        Initialize from optparse configuration options.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        self._opts = opts
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
        # Customize some attributes from how optparse leaves them.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        self.build_drive = os.path.normpath(self._opts.build_drive)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        self.file_store = os.path.normpath(self._opts.file_store)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        self.matti_scripts = os.path.normpath(self._opts.matti_scripts)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
        self.template_location = os.path.normpath(self._opts.template_loc)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        if self._opts.flash_images:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
            self.flash_images = self._opts.flash_images.split(',')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
            self.flash_images = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        if not re.search(r'\A\s*?\Z', self._opts.sis_files):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
            self.sis_files = self._opts.sis_files.split(',')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
            self.sis_files = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        self.step_list = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        self.filelist = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
        self.image_list = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        self.sis_list = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        self.device_type = self._opts.device_type
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        self.device_hwid = self._opts.device_hwid
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
        self.drop_file = self._opts.drop_file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        self.minimum_flash_images = self._opts.minimum_flash_images
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        self.plan_name = self._opts.plan_name
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        self.test_timeout = self._opts.test_timeout 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        self.diamonds_build_url = self._opts.diamonds_build_url
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        self.testrun_name = self._opts.testrun_name    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        self.report_email = self._opts.report_email
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
        self.harness = self._opts.harness
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
        self.sis_enabled = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        if self.sis_files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
            if len(self.sis_files) >= 1:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
                self.sis_enabled = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
    def __getattr__(self, attr):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        return getattr(self._opts, attr)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
    def __str__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        dump = "Configuration:\n"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        seen = set()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
        for key, value in vars(self).items():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
            if not key.startswith("_"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
                dump += "\t%s = %s\n" % (key, value)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
                seen.add(key)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
        for key, value in vars(self._opts).items():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
            if key not in seen:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
                dump += "\t%s = %s\n" % (key, value)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
                seen.add(key)                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        return dump
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
class MattiDrop(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
    ATS3 testdrop generation for MATTI tool
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
    def __init__(self, config=None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
        self.configuration = config
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
        self.matti_cases = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
        self.tmp_path = os.getcwd()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
        self.files = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
        self.test_files = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
    def fetch_testfiles(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
        """Needed flash files, sis-files and testscripts from given matti scripts -folder are added to file list."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
        tmp_case_list = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
#        tmp_image_list = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        os.chdir(os.path.normpath(self.configuration.matti_scripts))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
        try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
            for path, _, names in os.walk(os.getcwd()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
                for name in names:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
                    if re.search(r'.*?[.]rb\Z', name):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
                        tmp_case_list.append((os.path.normpath(os.path.join(path, name)), os.path.join("ats3", "matti", "script", name)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
            if tmp_case_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
                for tmp_case in tmp_case_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
                    self.configuration.step_list.append(dict(path=os.path.join("§TEST_RUN_ROOT§", str(tmp_case[1])), name="Test case"))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
            if self.configuration.flash_images:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
                for image in self.configuration.flash_images:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
                    tmp = string.rsplit(image, os.sep)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
                    image_name = tmp[len(tmp)-1] 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
                    self.configuration.image_list.append(os.path.join("ATS3Drop", "images", image_name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
            if self.configuration.sis_files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
                for sis in self.configuration.sis_files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
                    tmp = string.rsplit(sis, os.sep)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
                    sis_name = tmp[len(tmp)-1] 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
                    self.configuration.sis_list.append(dict(path=os.path.join("ATS3Drop", "sis", sis_name), dest=sis_name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
        except KeyError, error:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
            _logger.error("Error in file reading / fetching!")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
            sys.stderr.write(error)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
        if tmp_case_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
            for tmp_case in tmp_case_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
                self.configuration.filelist.append(tmp_case[1])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
            return tmp_case_list
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
            _logger.error("No test cases/files available!")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
            return None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
    def create_testxml(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
        """This method will use Jinja2 template engine for test.xml creation"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
        os.chdir(self.tmp_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
        env = Environment(loader=PackageLoader('ats3.matti', 'template'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
        if os.path.isfile(self.configuration.template_location):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
            template = env.from_string(open(self.configuration.template_location).read())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
            xml_file = open("test.xml", 'w')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
            xml_file.write(template.render(configuration=self.configuration))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
            xml_file.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
            _logger.error("No template file found")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
    def create_testdrop(self, output_file=None, file_list=None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
        """Creates testdrop zip-file to given location."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
        #env = Environment(loader=PackageLoader('MattiDrops', 'template'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
        os.chdir(self.tmp_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
        if output_file and file_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
            zfile = zipfile.ZipFile(output_file, "w", zipfile.ZIP_DEFLATED)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
            try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
                _logger.info("Adding files to testdrop:")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
                for src_file, drop_file in file_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
                    _logger.info("   + Adding: %s" % src_file.strip())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
                    if os.path.isfile(src_file):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
                        zfile.write(str(src_file.strip()), str(drop_file))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
                    else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
                        _logger.error("invalid test file name supplied %s " % drop_file)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
                if self.configuration.flash_images:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
                    for image in self.configuration.flash_images:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
                        tmp = string.rsplit(image, os.sep)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
                        image_name = tmp[len(tmp)-1] 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
                        _logger.info("   + Adding: %s" % image_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
                        if  os.path.isfile(image):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
                            zfile.write(image, os.path.join("ATS3Drop", "images", image_name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
                        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
                            _logger.error("invalid flash file name supplied %s " % image_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
                if self.configuration.sis_enabled:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
                    if self.configuration.sis_files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
                        for sis in self.configuration.sis_files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
                            tmp = string.rsplit(sis, os.sep)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
                            sis_name = tmp[len(tmp)-1] 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
                            _logger.info("   + Adding: %s" % sis_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
                            if os.path.isfile(sis):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
                                zfile.write(sis, os.path.join("ATS3Drop", "sis", sis_name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
                            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
                                _logger.error("invalid sis file name supplied %s " % sis_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
                zfile.write(os.path.normpath(os.path.join(os.getcwd(),"test.xml")), "test.xml")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
            finally:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
                _logger.info("Testdrop created! %s" % output_file)            	   
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
                zfile.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
            return zfile
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
def create_drop(configuration):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
    """Testdrop creation"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
    if configuration:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
        m_drop = MattiDrop(configuration)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
        m_drop.fetch_testfiles()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
        m_drop.create_testxml()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
        return m_drop.create_testdrop(configuration.drop_file, m_drop.fetch_testfiles())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
    else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
        _logger.error("No configuration available for test drop creation")        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
def main():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
    """Main entry point."""    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
    cli = OptionParser(usage="%prog [options] TSRC1 [TSRC2 [TSRC3 ...]]")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
    cli.add_option("--build-drive", help="Build area root drive", default='X:')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
    cli.add_option("--matti-scripts", help="Path to the directory where the MATTI test scripts are saved.", default="")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
    cli.add_option("--flash-images", help="Flash image files as a list",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
                   default="")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
    cli.add_option("--report-email", help="Email notification receivers", 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
                   default="")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
    cli.add_option("--harness", help="Test harness (default: %default)",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
                   default="unknown")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
    cli.add_option("--file-store", help="Destination path for reports.",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
                   default="")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
    cli.add_option("--testrun-name", help="Name of the test run", 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
                   default="run")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
    cli.add_option("--device-type", help="Device type (e.g. 'PRODUCT')", 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
                   default="unknown")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
    cli.add_option("--device-hwid", help="Device hwid", 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   228
                   default="")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
    cli.add_option("--diamonds-build-url", help="Diamonds build url")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
    cli.add_option("--drop-file", help="Name for the final drop zip file",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
                   default="")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
    cli.add_option("--minimum-flash-images", help="Minimum amount of flash images",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
                   default=2)    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
    cli.add_option("--plan-name", help="Name of the test plan", 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
                   default="plan")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   236
    cli.add_option("--sis-files", help="Sis files as a list",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   237
                   default="")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   238
    cli.add_option("--template-loc", help="location of template file",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   239
                   default="..\template")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   240
    cli.add_option("--test-timeout", help="Test execution timeout value (default: %default)",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   241
                   default="60")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   242
    cli.add_option("--verbose", help="Increase output verbosity", 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   243
                   action="store_true", default=True)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
    opts, _ = cli.parse_args()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   245
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   246
    if opts.verbose:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   247
        _logger.setLevel(logging.DEBUG)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   248
        logging.basicConfig(level=logging.DEBUG)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
    config = Configuration(opts)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   250
    create_drop(config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   251
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   252
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   253
if __name__ == "__main__":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
    main()