Package platformids :: Package custom :: Module minix2

Source Code for Module platformids.custom.minix2

  1  # -*- coding: utf-8 -*- 
  2  """Example for a dynamic added custom platform. 
  3   
  4  Here Minix2 as a new distribution is added. 
  5   
  6  """ 
  7  from __future__ import absolute_import 
  8   
  9  from platformids import RTE, rte2num, num2rte, num2pretty, custom_rte_distrel2tuple, custom_dist, \ 
 10      PlatformIDsUnknownError, \ 
 11      RTE_OSTYPE, RTE_DIST 
 12   
 13  from platformids.custom.minix import RTE_MINIX 
 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_MINIX2        = RTE_MINIX   + custom_dist.add_enum()   #: Minix2 as distrel 
 24   
 25       
 26  #: mapping of the rte string and numeric representation to the numeric value 
 27  rte2num.update( 
 28      { 
 29          'minix2':        RTE_MINIX2,   # dist 
 30          RTE_MINIX2:      RTE_MINIX2,   # dist 
 31      } 
 32  ) 
 33   
 34   
 35  #: mapping of the rte numeric representation to the string value 
 36  num2rte.update( 
 37      { 
 38          RTE_MINIX2:    'minix2', 
 39      } 
 40  ) 
 41   
 42  #: mapping of the rte numeric representation to the string value 
 43  num2pretty.update( 
 44      { 
 45          RTE_MINIX2:    'Minix2', 
 46      } 
 47  ) 
 48   
 49   
 50  #-----------------------------------------------# 
 51  #                                               # 
 52  # optional constants for convenience            # 
 53  #                                               # 
 54  #-----------------------------------------------# 
 55   
 56   
 57  RTE_MINIX200      = RTE_MINIX2  + 0x00000400                            #: Minix-2.0.0 
 58   
 59       
 60  #: mapping of the rte string and numeric representation to the numeric value 
 61  rte2num.update( 
 62      { 
 63          'minix200':      RTE_MINIX200, # distrel 
 64          RTE_MINIX200:    RTE_MINIX200, # distrel 
 65      } 
 66  ) 
 67   
 68   
 69  #: mapping of the rte numeric representation to the string value 
 70  num2rte.update( 
 71      { 
 72          RTE_MINIX200:  'minix200', 
 73      } 
 74  ) 
 75   
 76  #: mapping of the rte numeric representation to the string value 
 77  num2pretty.update( 
 78      { 
 79          RTE_MINIX200:  'Minix-2.0.0', 
 80      } 
 81  ) 
 82   
 83   
84 -def my_distrel2tuple(rte=RTE):
85 """ 86 A custom example only - standard encoding is default layout. 87 88 Convert the *Minix* specific *distrel* version layout 89 to a tuple. 90 91 A callback to be used by the function: 92 93 platformids.decode_rte_distrel_to_segments(rte=RTE) 94 95 Decodes the compressed *distrel* from the 32bit integer 96 bitmask *rte* into the corresponding tuple of integer 97 segments. 98 99 Args: 100 rte: 101 The comppressed runtime environment identifier bitmask. 102 103 default := RTE 104 105 Returns: 106 Tuple of Integer values of the encoded segments, either 107 as defined by the default layout, or any known as defined 108 by additional extended and/or custom criteria. 109 110 Raises: 111 pass-through 112 113 Examples: 114 :: 115 116 decode_rte_distrel_to_segments() 117 => (2, 0, 0) # on Minix-2.0.0 118 119 """ 120 if rte & RTE_OSTYPE != RTE_MINIX: 121 raise PlatformIDsUnknownError("Not Minix: rte = " + str(rte)) 122 123 if rte & RTE_DIST != RTE_MINIX2: 124 raise PlatformIDsUnknownError("Not Minix3: 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 Minix3 release rte = " + str(rte)) 137 138 # here same as the default handler 139 return ( 140 _rte & 0xfc00, 141 _rte & 0x03e0, 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_MINIX3: parrot.platformids.my_distrel2tuple, 150 151 RTE_MINIX2: my_distrel2tuple, #: the callback to be registered 152 } 153 ) 154