Package platformids :: Package embed :: Module armbian

Source Code for Module platformids.embed.armbian

  1  # -*- coding: utf-8 -*- 
  2  """Armbian releases. 
  3   
  4  The *Armbian* Linux is implemented as a module  
  5  based on custom numbering scheme due to the specific value ranges,  
  6  which are required for this distribution only. 
  7   
  8  The *Armbian* distribution represents a *shrinked multi-role PC-Platform* as an 
  9  embedded system with integrated low-level HW interfaces for a wide range of *ARM* 
 10  based boards.  
 11  """ 
 12  from __future__ import absolute_import 
 13   
 14  # from platformids import _debug, _verbose 
 15  from pythonids import PYV35Plus 
 16  from platformids import RTE, rte2num, num2rte, num2pretty, custom_rte_distrel2tuple, custom_dist, \ 
 17      decode_version_str_to_segments, \ 
 18      PlatformIDsUnknownError, \ 
 19      RTE_LINUX, RTE_DIST, \ 
 20      DSKORG_ID, DSKORG_RELEASE, DSKORG_VERSION, PlatformIDsFileCheck 
 21   
 22   
 23  __author__ = 'Arno-Can Uestuensoez' 
 24  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 25  __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \ 
 26                  " @Ingenieurbuero Arno-Can Uestuensoez" 
 27  __version__ = '0.1.1' 
 28  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
 29   
 30   
 31  # 
 32  # *** special modifications *** 
 33  # 
 34  RTE_ARMBIAN = RTE_LINUX          + custom_dist.add_enum()    #: Armbian - re-grouped version sub-ranges  
 35   
 36       
 37  #: mapping of the rte string and numeric representation to the numeric value 
 38  rte2num.update( 
 39      { 
 40          'armbian':   RTE_ARMBIAN, 
 41          RTE_ARMBIAN: RTE_ARMBIAN, 
 42      } 
 43  ) 
 44   
 45   
 46  #: mapping of the rte numeric representation to the string value 
 47  num2rte.update( 
 48      { 
 49          RTE_ARMBIAN:        'armbian', 
 50      } 
 51  ) 
 52   
 53  num2pretty.update( 
 54      { 
 55          RTE_ARMBIAN:         'Armbian', 
 56      } 
 57  ) 
 58   
 59   
 60  #-----------------------------------------------# 
 61  #                                               # 
 62  # optional constants for convenience            # 
 63  #                                               # 
 64  #-----------------------------------------------# 
 65   
 66   
 67  RTE_ARMBIAN5 = RTE_ARMBIAN          + 0x00002800 #: ARMBIAN - stretch 
 68  RTE_ARMBIAN550 = RTE_ARMBIAN5       + 0x00000190 #: ARMBIAN - stretch 
 69   
 70       
 71  #: mapping of the rte string and numeric representation to the numeric value 
 72  rte2num.update( 
 73      { 
 74          'armbian5':          RTE_ARMBIAN5, 
 75          'armbian550':        RTE_ARMBIAN550, 
 76          'Armbian-stretch':   RTE_ARMBIAN550, 
 77          RTE_ARMBIAN5:        RTE_ARMBIAN5, 
 78          RTE_ARMBIAN550:      RTE_ARMBIAN550, 
 79      } 
 80  ) 
 81   
 82   
 83  #: mapping of the rte numeric representation to the string value 
 84  num2rte.update( 
 85      { 
 86          RTE_ARMBIAN5:        'armbian5', 
 87          RTE_ARMBIAN550:      'armbian550', 
 88      } 
 89  ) 
 90   
 91   
 92  num2pretty.update( 
 93      { 
 94          RTE_ARMBIAN5:        'Armbian-stretch', 
 95      } 
 96  ) 
 97   
 98   
 99   
100  # armbian 
101  dist = ['', '', 'Armbian-', 'Armbian', '', ''] 
102   
103  try: 
104   
105      with open("/etc/os-release", 'r') as f: 
106          for l in f: 
107              if l.startswith('ID='): 
108                  # id 
109                  dist[0] = dist[5] = DSKORG_ID.sub(r'\1', l) 
110   
111              elif l.startswith('VERSION='): 
112                  # actual pretty name 
113                  _pretty = DSKORG_RELEASE.split(l)[2]  # for now a reminder only  
114   
115      # 
116      # scan dist + distrel 
117      # 
118      with open("/etc/armbian-release", 'r') as f: 
119          # has it's own numbering 
120          for l in f: 
121              if l.startswith('VERSION='): 
122                  dist[1] = DSKORG_VERSION.sub(r'\1', l) 
123                  dist[4] = decode_version_str_to_segments(dist[1]) 
124                  dist[0] += '%d%d' % (dist[4][0], dist[4][1],) 
125                  dist[2] += dist[1] 
126       
127   
128  except PlatformIDsFileCheck: 
129      # not on armbian platform, so scan will fail 
130      pass 
131   
132   
133  if dist[0] != 'armbian': 
134      # not actually armbian 
135      dist = ['armbian', '0.0.0', 'Armbian-0.0.0', 'Armbian', (0, 0, 0,), 'armbian'] 
136   
137   
138 -def my_distrel2tuple(rte=RTE):
139 """Callback for special version layout of Armbian, see manuals. 140 141 A callback to be used by the function: 142 143 platformids.decode_rte_distrel_to_segments(rte=RTE) 144 145 Decodes the compressed *distrel* from the 32bit integer 146 bitmask *rte* into the corresponding tuple of integer 147 segments. 148 149 Args: 150 **rte**: 151 The comppressed runtime environment identifier bitmask. 152 153 default := RTE 154 155 Returns: 156 Tuple of Integer values of the encoded segments, either 157 as defined by the default layout, or any known as defined 158 by additional extended and/or custom criteria. 159 160 Raises: 161 pass-through 162 163 Examples: 164 :: 165 166 decode_rte_distrel_to_segments() 167 => (5, 50, 0) # on Armbian-5.50 168 169 """ 170 if rte & RTE_DIST != RTE_ARMBIAN: 171 raise PlatformIDsUnknownError("Not Armbian: rte = " + str(rte)) 172 173 try: 174 # handle string input 175 _rte = rte2num[rte] 176 177 except KeyError: 178 # non-registered release 179 180 if type(rte) is int: 181 # can split basically any number, let's see... 182 _rte = rte 183 184 else: 185 raise PlatformIDsUnknownError("Unknown Armbian release rte = " + str(rte)) 186 187 # represents the Armbian layout 188 return ( 189 (_rte & 0xf800) >> 11, 190 (_rte & 0x07f8) >> 3, 191 _rte & 0x0003, 192 )
193 194 195 #: registered callbacks for special handling of custom layout 196 custom_rte_distrel2tuple.update( 197 { 198 RTE_ARMBIAN: my_distrel2tuple, #: the callback to be registered 199 } 200 ) 201