Package platformids :: Package custom :: Module slackware

Source Code for Module platformids.custom.slackware

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