Package platformids :: Package dist :: Module gentoo

Source Code for Module platformids.dist.gentoo

  1  # -*- coding: utf-8 -*- 
  2  """Gentoo releases. 
  3  """ 
  4  from __future__ import absolute_import 
  5   
  6  import os 
  7  import time 
  8   
  9   
 10  # from platformids import _debug, _verbose 
 11  from pythonids import PYV35Plus 
 12  from platformids import RTE, rte2num, num2rte, num2pretty, custom_rte_distrel2tuple, \ 
 13      RTE_LINUX, RTE_DISTEXT, \ 
 14      RTE_DIST , PlatformIDsUnknownError, PlatformIDsFileCheck 
 15   
 16   
 17  __author__ = 'Arno-Can Uestuensoez' 
 18  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 19  __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \ 
 20                  " @Ingenieurbuero Arno-Can Uestuensoez" 
 21  __version__ = '0.1.1' 
 22  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
 23   
 24   
 25   
 26  RTE_GENTOO          = RTE_LINUX + RTE_DISTEXT + 0x00030000    #: Gentoo    - rolling dist since 2008 
 27  RTE_GENTOO121 =       RTE_GENTOO              + 0x00000001    #: Gentoo-12.1 - April 1, 2012[64] (With an April Fool's joke named "Install Wizard")  
 28  RTE_GENTOO20181202  = RTE_GENTOO              + 0x00000082    #: autobuild Gentoo-2018.12.02  
 29  RTE_GENTOO20181204  = RTE_GENTOO              + 0x00000084    #: autobuild Gentoo-2018.12.04  
 30   
 31   
 32       
 33  #: mapping of the rte string and numeric representation to the numeric value 
 34  rte2num.update( 
 35      { 
 36   
 37          'gentoo': RTE_GENTOO, 
 38          'gentoo121': RTE_GENTOO121, 
 39          'gentoo20181202': RTE_GENTOO20181202, 
 40          'gentoo20181204': RTE_GENTOO20181204, 
 41          RTE_GENTOO121: RTE_GENTOO121, 
 42          RTE_GENTOO20181202: RTE_GENTOO20181202, 
 43          RTE_GENTOO20181204: RTE_GENTOO20181204, 
 44          RTE_GENTOO: RTE_GENTOO, 
 45      } 
 46  ) 
 47   
 48  #: mapping of the rte numeric representation to the string value 
 49  num2rte.update( 
 50      { 
 51          RTE_GENTOO: 'gentoo', 
 52          RTE_GENTOO121: 'gentoo121', 
 53          RTE_GENTOO20181202: 'gentoo20181202', 
 54          RTE_GENTOO20181204: 'gentoo20181204', 
 55      } 
 56  ) 
 57   
 58   
 59  #: mapping of the rte numeric representation to the pretty string value 
 60  num2pretty.update( 
 61      { 
 62          RTE_GENTOO: 'Gentoo', 
 63      } 
 64  ) 
 65   
 66   
 67   
 68   
 69  dist = ['', '', '', 'GentooLinux', '', 'gentoo'] 
 70   
 71  try: 
 72   
 73      if os.path.exists("/etc/gentoo-release"): 
 74          __s = os.stat('/va/cache/edb/mtimedb') 
 75          __t = time.gmtime(__s.st_mtime) 
 76          dist[4] = (__t.tm_year, __t.tm_mon, __t.tm_mday) 
 77          dist[1] = '%d%02d%02d' % (__t.tm_year, __t.tm_mon, __t.tm_mday) 
 78          dist[0] =  'gentoo%d%d%d' % (__t.tm_year, __t.tm_mon, __t.tm_mday) 
 79          dist[2] = 'GentooLinux-' + str(dist[1])   
 80   
 81   
 82  except PlatformIDsFileCheck: 
 83      # not on OpenWRT platform, so scan will fail 
 84      pass     
 85   
 86   
 87  if dist[5] != 'gentoo': 
 88      # does not actually match pfSense 
 89      dist = ['gentoo', '0.0.0', 'GentooLinux-0.0.0', 'GentooLinux', (0, 0, 0,), 'gentoo'] 
 90   
 91   
92 -def my_distrel2tuple(rte=RTE):
93 """Callback for special version layout of Armbian, see manuals. 94 95 A callback to be used by the function: 96 97 platformids.decode_rte_distrel_to_segments(rte=RTE) 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 GENTOO-2018.0 126 => (2019, 0, 0) # on GENTOO-2019.0 127 128 """ 129 if rte & RTE_DIST != RTE_GENTOO: 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 153 #: registered callbacks for special handling of custom layout 154 custom_rte_distrel2tuple.update( 155 { 156 RTE_GENTOO: my_distrel2tuple, #: the callback to be registered 157 } 158 ) 159