github.com/hwaf/hwaf@v0.0.0-20140814122253-5465f73b20f1/py-hwaftools/orch/ups.py (about)

     1  #!/usr/bin/env python
     2  '''
     3  A ten foot pole
     4  '''
     5  
     6  import os
     7  import time
     8  from .util import check_output, CalledProcessError
     9  
    10  def flavor():
    11      '''
    12      Ow, my balls.
    13      '''
    14      try:
    15          flav = check_output(['ups','flavor'])
    16          #print 'UPS FLAVOR from ups: "%s"' % flav
    17          return flav.strip()
    18      except OSError:
    19          #print 'UPS failed to run, calculate flavor manually'
    20          pass
    21  
    22      kern, host, rel, vend, mach = os.uname()
    23      if mach in ['x86_64','sun','ppc64']:
    24          mach = '64bit'
    25      else:
    26          mach = ''
    27      rel = '.'.join(rel.split('.')[:2])
    28      if 'darwin' in kern.lower():
    29          libc = rel # FIXME: is there something better on mac ?
    30      else:
    31          libc = check_output(['ldd','--version']).split(b'\n')[0].split()[-1]
    32      return '%s%s+%s-%s' % (kern, mach, rel, libc)
    33  
    34  
    35  def worch_export_to_ups_command(wk, wv):
    36      var = wk[len('export_'):]
    37  
    38      if wv.startswith('prepend:'):
    39          val = wv[len('prepend:'):]
    40          return 'pathPrepend(%s, %s)' % (var, val)
    41  
    42      if wv.startswith('append:'):        
    43          val = wv[len('append:'):]
    44          return 'pathAppend(%s, %s)' % (var, val)
    45  
    46      if wv.startswith('set:'):
    47          val = wv[len('set:'):]
    48          return 'envSet(%s, %s)' % (var, val)
    49  
    50      val = wv
    51      return 'envSet(%s, %s)' % (var, val)
    52      
    53  
    54  def simple_setup_table_file(**cfg):
    55      '''
    56      Return the contents of a UPS table file to set up the package via
    57      UPS.
    58  
    59      The table file is "simple" in the sense that it applies only for
    60      the given package configuration items.
    61      '''
    62  
    63      commands = []
    64      for k,v in cfg.items():
    65          if k.startswith('export_'):
    66              commands.append(worch_export_to_ups_command(k,v))
    67  
    68      stf = '''\
    69  File = Table
    70  Product = {package}
    71  
    72  Group:
    73    Flavor = {ups_flavor}
    74    Qualifiers = "{ups_qualifiers}"
    75  Common:
    76    Action = SETUP
    77      setupEnv()
    78      prodDir()
    79      {commands}
    80  End:
    81  '''.format(commands = '    \n'.join(commands), **cfg)
    82      return stf
    83  
    84  def simple_setup_version_file(**cfg):
    85      '''
    86      Return the contents of a UPS version file
    87  
    88      FIXME: it makes some assumptions as to UPS directory structure.
    89      '''
    90      content = '''\
    91  FILE = version
    92  PRODUCT = {package}
    93  VERSION = {ups_version_string}
    94  
    95  #*************************************************
    96  #
    97  FLAVOR = {ups_flavor}
    98  QUALIFIERS = "{ups_qualifiers}"
    99    DECLARER = {user}
   100    DECLARED = {date}
   101    MODIFIER = {user}
   102    MODIFIER = {date}
   103    PROD_DIR = {ups_prod_subdir}
   104    UPS_DIR = ups
   105    TABLE_FILE = {package}.table
   106  '''.format(user = os.environ.get('USER','unknown'),
   107             date = time.strftime('%Y-%m-%d %H.%M.%S GMT', time.gmtime(time.time())),
   108             **cfg)
   109      return content
   110  
   111  def simple_setup_chain_file(**cfg):
   112      '''
   113      Return the contents of a UPS chain file
   114  
   115      FIXME: it only make "current chain".
   116      '''
   117      content = '''\
   118  FILE = chain
   119  PRODUCT = {package}
   120  CHAIN = current
   121  
   122  #*************************************************
   123  #
   124  FLAVOR = {ups_flavor}
   125  VERSION = {ups_version_string}
   126  QUALIFIERS = "{ups_qualifiers}"
   127    DECLARER = {user}
   128    DECLARED = {date}
   129    MODIFIER = {user}
   130    MODIFIER = {date}
   131  '''.format(user = os.environ.get('USER','unknown'),
   132             date = time.strftime('%Y-%m-%d %H.%M.%S GMT', time.gmtime(time.time())),
   133             **cfg)
   134      return content