8.11. platformids.dist.gentoo

Module Gentoo Linux [doc].

8.11.1. Description

8.11.1.1. Rolling Version Identifier

The current version of GentooLinux does not seem to support the current state of the installation, even not the build release of the install medium by the runtime system. Thus the platformids provide as the basic information of the installation state for now the last modification time of the package database mtimedb of the emerge command:

/var/cache/edb/mtimedb

With the values by os.stat:

release-version := (<time.struct_time.tm_year>, <time.struct_time.tm_month>, <time.struct_time.tm_mday>)

or as a formatted string in accordance to the ISO naming convention:

release-version-str := "%d%02d%02d" (<time.struct_time.tm_year>, <time.struct_time.tm_month>, <time.struct_time.tm_mday>)

This information is due to several scenarios not reliable, but to say

  1. better than none

  2. probably not so bad, even though not each mod results from a full upgrade

Warning

Do not mixup this release state information with the release of the actual installation media. And once again, the provided release information by platformids is basically reliable after an upgrade only, e.g.:

emerge –update –deep –with-bdeps=y @world

8.11.2. Source

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# -*- coding: utf-8 -*-
"""Gentoo releases.
"""
from __future__ import absolute_import

import os
import time


# from platformids import _debug, _verbose
from pythonids import PYV35Plus
from platformids import RTE, rte2num, num2rte, num2pretty, custom_rte_distrel2tuple, \
    RTE_LINUX, RTE_DISTEXT, \
    RTE_DIST , PlatformIDsUnknownError, PlatformIDsFileCheck


__author__ = 'Arno-Can Uestuensoez'
__license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints"
__copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \
                " @Ingenieurbuero Arno-Can Uestuensoez"
__version__ = '0.1.1'
__uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9"



RTE_GENTOO          = RTE_LINUX + RTE_DISTEXT + 0x00030000    #: Gentoo    - rolling dist since 2008
RTE_GENTOO121 =       RTE_GENTOO              + 0x00000001    #: Gentoo-12.1 - April 1, 2012[64] (With an April Fool's joke named "Install Wizard") 
RTE_GENTOO20181202  = RTE_GENTOO              + 0x00000082    #: autobuild Gentoo-2018.12.02 
RTE_GENTOO20181204  = RTE_GENTOO              + 0x00000084    #: autobuild Gentoo-2018.12.04 


    
#: mapping of the rte string and numeric representation to the numeric value
rte2num.update(
    {

        'gentoo': RTE_GENTOO,
        'gentoo121': RTE_GENTOO121,
        'gentoo20181202': RTE_GENTOO20181202,
        'gentoo20181204': RTE_GENTOO20181204,
        RTE_GENTOO121: RTE_GENTOO121,
        RTE_GENTOO20181202: RTE_GENTOO20181202,
        RTE_GENTOO20181204: RTE_GENTOO20181204,
        RTE_GENTOO: RTE_GENTOO,
    }
)

#: mapping of the rte numeric representation to the string value
num2rte.update(
    {
        RTE_GENTOO: 'gentoo',
        RTE_GENTOO121: 'gentoo121',
        RTE_GENTOO20181202: 'gentoo20181202',
        RTE_GENTOO20181204: 'gentoo20181204',
    }
)


#: mapping of the rte numeric representation to the pretty string value
num2pretty.update(
    {
        RTE_GENTOO: 'Gentoo',
    }
)




dist = ['', '', '', 'GentooLinux', '', 'gentoo']

try:

    if os.path.exists("/etc/gentoo-release"):
        __s = os.stat('/va/cache/edb/mtimedb')
        __t = time.gmtime(__s.st_mtime)
        dist[4] = (__t.tm_year, __t.tm_mon, __t.tm_mday)
        dist[1] = '%d%02d%02d' % (__t.tm_year, __t.tm_mon, __t.tm_mday)
        dist[0] =  'gentoo%d%d%d' % (__t.tm_year, __t.tm_mon, __t.tm_mday)
        dist[2] = 'GentooLinux-' + str(dist[1])  


except PlatformIDsFileCheck:
    # not on OpenWRT platform, so scan will fail
    pass    


if dist[5] != 'gentoo':
    # does not actually match pfSense
    dist = ['gentoo', '0.0.0', 'GentooLinux-0.0.0', 'GentooLinux', (0, 0, 0,), 'gentoo']


def my_distrel2tuple(rte=RTE):
    """Callback for special version layout of Armbian, see manuals. 
    
    A callback to be used by the function:
    
       platformids.decode_rte_distrel_to_segments(rte=RTE)
    
    A callback to be used by the function:
    
       platformids.decode_rte_distrel_to_segments(rte=RTE)
    
    Decodes the compressed *distrel* from the 32bit integer
    bitmask *rte* into the corresponding tuple of integer
    segments.

    Args:
       **rte**:
           The comppressed runtime environment identifier bitmask.
            
           default := RTE

    Returns:
       Tuple of Integer values of the encoded segments, either
       as defined by the default layout, or any known as defined
       by additional extended and/or custom criteria.
    
    Raises:
       pass-through

    Examples:
      ::

         decode_rte_distrel_to_segments()     
         =>  (2018, 0, 0)  # on GENTOO-2018.0
         =>  (2019, 0, 0)  # on GENTOO-2019.0

    """
    if rte & RTE_DIST != RTE_GENTOO:
        raise PlatformIDsUnknownError("Not Gentoo:  rte = " + str(rte))
        
    try:
        # handle string input
        _rte = rte2num[rte]
    except KeyError:
        # non-registered release
        
        if type(rte) is int:
            # can split basically any number, let's see...
            _rte = rte

        else:
            raise PlatformIDsUnknownError("Unknown Gentoo release rte = " + str(rte))

    # represents the ArchLinux layout for rolling distro
    return (
        (_rte & 0xfe00) >> 9 + 1970, 
        (_rte & 0x01e0) >> 5, 
        _rte & 0x001f, 
        )


#: registered callbacks for special handling of custom layout
custom_rte_distrel2tuple.update(
    {
        RTE_GENTOO: my_distrel2tuple,  #: the callback to be registered
    }
)



8.11.3. Download

gentoo.py