Package platformids :: Package custom :: Module minix

Source Code for Module platformids.custom.minix

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