Package platformids :: Package custom :: Module pentoo

Source Code for Module platformids.custom.pentoo

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