Package platformids :: Package dist :: Module archlinux

Source Code for Module platformids.dist.archlinux

  1  # -*- coding: utf-8 -*- 
  2  """ArchLinux 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, RTE_ARCHLINUX, \ 
 14      RTE_DIST , PlatformIDsUnknownError, \ 
 15      DSKORG_ID, DSKORG_ID_LIKE, DSKORG_NAME_RELEASE, DSKORG_VERSION, PlatformIDsFileCheck 
 16   
 17   
 18   
 19  __author__ = 'Arno-Can Uestuensoez' 
 20  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 21  __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \ 
 22                  " @Ingenieurbuero Arno-Can Uestuensoez" 
 23  __version__ = '0.1.35' 
 24  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
 25   
 26   
 27  RTE_ARCHLINUX20180601 = RTE_ARCHLINUX           + 0x000060c1 #: archlinux - 2018.06.01 
 28  RTE_ARCHLINUX20181001 = RTE_ARCHLINUX           + 0x00006141 #: archlinux - 2018.10.01 
 29  RTE_ARCHLINUX20181101 = RTE_ARCHLINUX           + 0x00006161 #: archlinux - 2018.11.01 
 30  RTE_ARCHLINUX20181201 = RTE_ARCHLINUX           + 0x00006181 #: archlinux - 2018.12.01 
 31  RTE_ARCHLINUX20190401 = RTE_ARCHLINUX           + 0x00006281 #: archlinux - 2019.04.01 
 32   
 33       
 34  #: mapping of the rte string and numeric representation to the numeric value 
 35  rte2num.update( 
 36      { 
 37          'archlinux20180601':          RTE_ARCHLINUX20180601, 
 38          'archlinux20181001':          RTE_ARCHLINUX20181001, 
 39          'archlinux20181101':          RTE_ARCHLINUX20181101, 
 40          'archlinux20181201':          RTE_ARCHLINUX20181201, 
 41          'archlinux20190401':          RTE_ARCHLINUX20190401, 
 42      } 
 43  ) 
 44   
 45   
 46  #: mapping of the rte numeric representation to the string value 
 47  num2rte.update( 
 48      { 
 49          RTE_ARCHLINUX20180601:        'archlinux20180601', 
 50          RTE_ARCHLINUX20181001:        'archlinux20181001', 
 51          RTE_ARCHLINUX20181101:        'archlinux20181101', 
 52          RTE_ARCHLINUX20181201:        'archlinux20181201', 
 53          RTE_ARCHLINUX20190401:        'archlinux20190401', 
 54      } 
 55  ) 
 56   
 57  #: mapping of the rte numeric representation to the string value 
 58  # num2pretty.update( 
 59  #     { 
 60  #     } 
 61  # ) 
 62   
 63   
 64  dist = ['', '', '', 'ArchLinux', '', ''] 
 65   
 66  try: 
 67   
 68      if os.path.exists("/etc/os-release"): 
 69   
 70          # 
 71          # slightly different to others, thus do not want shared code 
 72          # 
 73          with open("/etc/os-release", 'r') as f: 
 74              for l in f: 
 75                  if l.startswith('ID='): 
 76                      dist[0] = dist[5] = DSKORG_ID.sub(r'\1', l) 
 77       
 78                  elif l.startswith('VERSION='): 
 79                      # optional custom value, not defined by ArchLinux 
 80                      dist[1] = _ver = DSKORG_VERSION.split(l) 
 81       
 82                  elif l.startswith('ID_LIKE='): 
 83                      dist[2] = DSKORG_ID_LIKE.sub(r'\1', l) 
 84       
 85                  elif l.startswith('NAME='): 
 86                      dist[3] = _nam = DSKORG_NAME_RELEASE.split(l)[-1] 
 87       
 88          if dist[5] == 'arch': 
 89              _s = os.stat('/va/cache/pacman/pkg') 
 90              _t = time.gmtime(_s.st_mtime) 
 91              dist[4] = (_t.tm_year, _t.tm_mon, _t.tm_mday) 
 92              dist[1] = '%d.%02d.%02d' % (_t.tm_year, _t.tm_mon, _t.tm_mday) 
 93              dist[0] = 'arch%d%d%d' % (_t.tm_year, _t.tm_mon, _t.tm_mday) 
 94              dist[2] = 'ArchLinux-' + dist[1]   
 95   
 96   
 97  except PlatformIDsFileCheck: 
 98      # not on ArchLinux platform, so scan will fail 
 99      pass     
100   
101   
102  if dist[5] != 'arch': 
103      # does not actually match ArchLinux 
104      dist = ['arch', '0.0.0', 'ArchLinux-0.0.0', 'ArchLinux', (0, 0, 0,), 'arch'] 
105