Package platformids :: Package custom :: Module parrot

Source Code for Module platformids.custom.parrot

  1  # -*- coding: utf-8 -*- 
  2  """Example for a dynamic added custom platform. 
  3   
  4  Here *Parrot* Linux, which actually has a default  
  5  release version layout, and though could be handled  
  6  by the default handler. 
  7   
  8  """ 
  9  from __future__ import absolute_import 
 10   
 11  from platformids import RTE, rte2num, num2rte, num2pretty, custom_rte_distrel2tuple, custom_dist, \ 
 12      PlatformIDsUnknownError, \ 
 13      RTE_LINUX, RTE_OSTYPE, RTE_DIST 
 14   
 15   
 16  __author__ = 'Arno-Can Uestuensoez' 
 17  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 18  __copyright__ = "Copyright (C) 2019 Arno-Can Uestuensoez" \ 
 19                  " @Ingenieurbuero Arno-Can Uestuensoez" 
 20  __version__ = '0.0.1' 
 21  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
 22   
 23  RTE_PARROT        = RTE_LINUX   + custom_dist.add_enum()     #: Parrot 
 24   
 25       
 26  #: mapping of the rte string and numeric representation to the numeric value 
 27  rte2num.update( 
 28      { 
 29          'parrot':        RTE_PARROT, 
 30          RTE_PARROT:      RTE_PARROT, 
 31      } 
 32  ) 
 33   
 34   
 35  #: mapping of the rte numeric representation to the string value 
 36  num2rte.update( 
 37      { 
 38          RTE_PARROT:          'parrot', 
 39      } 
 40  ) 
 41   
 42  #: mapping of the rte numeric representation to the string value 
 43  num2pretty.update( 
 44      { 
 45          RTE_PARROT:          'Parrot', 
 46      } 
 47  ) 
 48   
 49   
 50  #-----------------------------------------------# 
 51  #                                               # 
 52  # optional constants for convenience            # 
 53  #                                               # 
 54  #-----------------------------------------------# 
 55   
 56   
 57  RTE_PARROT451     = RTE_PARROT  + 0x000010a1                              #: Parrot-4.5.1 
 58   
 59       
 60  #: mapping of the rte string and numeric representation to the numeric value 
 61  rte2num.update( 
 62      { 
 63          'parrot451':     RTE_PARROT451, 
 64          RTE_PARROT451:   RTE_PARROT451, 
 65      } 
 66  ) 
 67   
 68   
 69  #: mapping of the rte numeric representation to the string value 
 70  num2rte.update( 
 71      { 
 72          RTE_PARROT451:       'parrot451', 
 73      } 
 74  ) 
 75   
 76  #: mapping of the rte numeric representation to the string value 
 77  num2pretty.update( 
 78      { 
 79          RTE_PARROT451:       'Parrot-4.5.1', 
 80      } 
 81  ) 
 82   
83 -def my_distrel2tuple(rte=RTE):
84 """ 85 A custom example only - standard encoding is default layout. 86 87 Convert the *Parrot* specific *distrel* version layout 88 to a tuple. 89 90 A callback to be used by the function: 91 92 platformids.decode_rte_distrel_to_segments(rte=RTE) 93 94 Decodes the compressed *distrel* from the 32bit integer 95 bitmask *rte* into the corresponding tuple of integer 96 segments. 97 98 Args: 99 rte: 100 The comppressed runtime environment identifier bitmask. 101 102 default := RTE 103 104 Returns: 105 Tuple of Integer values of the encoded segments, either 106 as defined by the default layout, or any known as defined 107 by additional extended and/or custom criteria. 108 109 Raises: 110 pass-through 111 112 Examples: 113 :: 114 115 decode_rte_distrel_to_segments() 116 => (4, 1, 0) # on Parrot-4.1 117 => (4, 5, 1) # on Parrot-4.5.1 118 119 """ 120 if rte & RTE_OSTYPE != RTE_LINUX: 121 raise PlatformIDsUnknownError("Not Linux: rte = " + str(rte)) 122 123 if rte & RTE_DIST != RTE_PARROT: 124 raise PlatformIDsUnknownError("Not Parrot: rte = " + str(rte)) 125 126 try: 127 _rte = rte2num[rte] 128 except KeyError: 129 # non-registered release 130 131 if type(_rte) is int: 132 # can split basically any number, let's see... 133 _rte = rte 134 135 else: 136 raise PlatformIDsUnknownError("Unknown Parrot release rte = " + str(rte)) 137 138 # here same as the default handler 139 return ( 140 (_rte & 0xfc00) >> 10, 141 (_rte & 0x03e0) >> 5, 142 _rte & 0x001f, 143 )
144 145 146 #: registered callbacks for special handling of custom layout 147 custom_rte_distrel2tuple.update( 148 { 149 # e.g. RTE_PARROT: parrot.platformids.my_distrel2tuple, 150 151 RTE_PARROT: my_distrel2tuple, #: the callback to be registered 152 } 153 ) 154