Module ant |
[hide private]
[frames] | no frames]

# Source Code for Module ant

     1  #============================================================================
     2  #Name        : ant.py
     3  #Part of     : Helium
     4
     5  #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     6  #All rights reserved.
     7  #This component and the accompanying materials are made available
     8  #under the terms of the License "Eclipse Public License v1.0"
     9  #which accompanies this distribution, and is available
    10  #at the URL "http://www.eclipse.org/legal/epl-v10.html".
    11  #
    12  #Initial Contributors:
    13  #Nokia Corporation - initial contribution.
    14  #
    15  #Contributors:
    16  #
    17  #Description:
    18  #===============================================================================
    19
    20  """ This module defines helper functions to be used in python Ant tasks. """
    21
    22
    23  import logging
    24  import re
    25  import os.path
    26
    27
    28 -def get_property(property_name):
    29      """ This function return None if a property has not been replaced by Ant. """
    30      if len(property_name) > 0 and property_name.startswith('${'):
    31          return None
    32      return property_name
    33
    34
    35 -def get_previous_build_number(build_number):
    36      """ Determines the previous build number if possible. """
    37      match = re.match(r'(?P<bn_txt>\w[a-zA-Z0-9_.]*\.)?(?P<bn_num>\d+)', build_number)
    38      if match != None:
    39          bn_txt = match.group('bn_txt')
    40          bn_num = match.group('bn_num')
    41          try:
    42              bn_num_int = int(bn_num)
    43              if bn_num_int > 1:
    44                  previous_bn_num_int = bn_num_int - 1
    45                  previous_bn_num = str(previous_bn_num_int).rjust(len(bn_num), '0')
    46                  previous_bn = previous_bn_num
    47                  if bn_txt != None:
    48                      previous_bn = '%s%s' % (bn_txt, previous_bn_num)
    49                  return previous_bn
    50          except ValueError:
    51              logging.warning('Parsing of Ant build number failed.')
    52      return ''
    53
    54
    55 -def get_next_build_number(build_number):
    56      """ Determines the next build number if possible. """
    57      match = re.match(r'(?P<bn_txt>\w[a-zA-Z0-9_.]*\.)?(?P<bn_num>\d+)', build_number)
    58      if match != None:
    59          bn_txt = match.group('bn_txt')
    60          bn_num = match.group('bn_num')
    61          try:
    62              bn_num_int = int(bn_num)
    63              previous_bn_num_int = bn_num_int + 1
    64              previous_bn_num = str(previous_bn_num_int).rjust(len(bn_num), '0')
    65              previous_bn = previous_bn_num
    66              if bn_txt != None:
    67                  previous_bn = '%s%s' % (bn_txt, previous_bn_num)
    68              return previous_bn
    69          except ValueError:
    70              logging.warning('Parsing of Ant build number failed.')
    71      return ''
    72
    73 -def get_filesets_content(project, task, elements):
    74      """ Extract all files selected by the filesets in a script's elements. """
    75      for eid in range(elements.get("fileset").size()):
    76          dirscanner = elements.get("fileset").get(int(eid)).getDirectoryScanner(project)
    77          dirscanner.scan()
    78          for jfilename in dirscanner.getIncludedFiles():
    79              filename = str(jfilename)
    80              task.log("Parsing %s" % filename)
    81              filename = os.path.join(str(dirscanner.getBasedir()), filename)
    82
    83
    84 -class AntHandler(logging.Handler):
    85      """ Implement a logger hanlder that prints error message using an Ant object.
    86          See Python documentation on how to use it.
    87          e.g:
    88          logging.getLogger("").addHandler(AntHandler(anttask))
    89          This line will redirect messages to Ant logging system.
    90      """
    91 -    def __init__(self, task, level=logging.NOTSET):
    92          logging.Handler.__init__(self, level)
    93          self._task = task
    94
    95 -    def emit(self, record):
    96          """ Handle the recordusing Ant. """
    97          self._task.log(str(record.getMessage()))
    98