Package imaker :: Module api |
[hide private]
[frames] | no frames]

# Source Code for Module imaker.api

     1  #============================================================================
     2  #Name        : api.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 is an helper to interface iMaker. """
    21  import os
    22  import re
    23  import pathaddition.match
    24  import fileutils
    25  import tempfile
    26  import subprocess
    27
    28 -class IMakerConfigScanner(fileutils.AbstractScanner):
    29      """ Specialize the abstract filescanner to support detection of the configuration. """
    30 -    def scan(self):
    31          """ Implement scanning of relevant configuration. """
    32          handle = subprocess.Popen("imaker help-config", shell=True, stdout=subprocess.PIPE).stdout
    33          for line in handle.read().splitlines():
    34              line = line.strip()
    35              if line.startswith('/') and self.is_included(line) \
    36                  and not self.is_excluded(line):
    37                  yield line
    38          handle.close()
    39
    40 -def scan_configs(includes, excludes):
    41      """ Use iMaker to scan the available buildable configurations. """
    42      scanner = IMakerConfigScanner()
    43      for inc in includes:
    44          scanner.add_include(inc)
    45      for exc in excludes:
    46          scanner.add_exclude(exc)
    47      return [r for r in scanner.scan()]
    48
    49 -def targets_for_config(config):
    50      """ Return the list of target supported by the provided configuration of iMaker. """
    51      cmd = "imaker -f %s help-target-*-list" % config
    52      (_, handle, child_stderr) = os.popen3(cmd)
    53      result = []
    54      print child_stderr.read()
    55      for line in handle.read().splitlines():
    56          line = line.strip()
    57          if line == "" or line.startswith("Total duration"):
    58              continue
    59          result.append(line)
    60      handle.close()
    61      return result
    62
    63
    64 -def get_product_dir(product):
    65      """ Return the PRODUCT_DIR variable from iMaker. """
    66      return get_variable("PRODUCT_DIR", product=product)
    67
    68
    69 -def get_variable(variable, target=None, product=None, config=None, default=None):
    70      """ Get variable value from iMaker. """
    71      cmdline = ""
    72      if product != None:
    73          cmdline = "-p%s" % product
    74      if config != None:
    75          cmdline += " -f %s" % config
    76      if target != None:
    77          cmdline += " %s" % target
    78
    79      logdir = tempfile.mkdtemp()
    80      print "imaker %s print-%s WORKDIR=%s" % (cmdline, variable, logdir)
    81      (_, handle, child_stderr) = os.popen3("imaker %s print-%s WORKDIR=%s" % (cmdline, variable, logdir))
    82      print child_stderr.read()
    83      result = []
    84      for line in handle.read().splitlines():
    85          line = line.strip()
    86          if line == "" or line.startswith("Total duration"):
    87              continue
    88          if variable in line:
    89              result.append(line)
    90      handle.close()
    91      result = re.match("%s\s*=\s*`(.*)'" % variable, "\n".join(result), re.DOTALL)
    92      if result != None:
    93          return result.group(1)
    94      assert (result != None)
    95      return default
    96