Package platformids :: Package dist :: Module opensuse

Source Code for Module platformids.dist.opensuse

  1  # -*- coding: utf-8 -*- 
  2  """OpenSUSE releases. 
  3  """ 
  4  from __future__ import absolute_import 
  5   
  6  from platformids import rte2num, num2rte, num2pretty, decode_version_str_to_segments, RTE_LINUX, \ 
  7      DSKORG_ID, DSKORG_VERSION, PlatformIDsFileCheck 
  8   
  9   
 10  __author__ = 'Arno-Can Uestuensoez' 
 11  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 12  __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \ 
 13                  " @Ingenieurbuero Arno-Can Uestuensoez" 
 14  __version__ = '0.1.29' 
 15  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
 16   
 17   
 18   
 19  RTE_OPENSUSE     = RTE_LINUX        + 0x000a0000     #: SuSE 
 20  RTE_SLES         = RTE_LINUX        + 0x000b0000     #: SLES 
 21   
 22   
 23  RTE_OPENSUSE10   = RTE_OPENSUSE     + 0x00002800  #: OpenSUSE-10 
 24  RTE_OPENSUSE11   = RTE_OPENSUSE     + 0x00002c00  #: OpenSUSE-11 
 25  RTE_OPENSUSE12   = RTE_OPENSUSE     + 0x00003000  #: OpenSUSE-12 
 26  RTE_OPENSUSE13   = RTE_OPENSUSE     + 0x00003400  #: OpenSUSE-13 
 27  RTE_OPENSUSE14   = RTE_OPENSUSE     + 0x00003800  #: OpenSUSE-14 
 28  RTE_OPENSUSE15   = RTE_OPENSUSE     + 0x00003c00  #: OpenSUSE-15 
 29  RTE_OPENSUSE151  = RTE_OPENSUSE     + 0x00003c20  #: OpenSUSE-15.1 
 30  RTE_OPENSUSE16   = RTE_OPENSUSE     + 0x00003000  #: OpenSUSE-16 
 31  RTE_OPENSUSE17   = RTE_OPENSUSE     + 0x00003400  #: OpenSUSE-17 
 32       
 33  RTE_OPENSUSE423  = RTE_OPENSUSE     + 0x0000a860  #: OpenSUSE-42.3 
 34       
 35  #: mapping of the rte string and numeric representation to the numeric value 
 36  rte2num.update( 
 37      { 
 38          'opensuse': RTE_OPENSUSE, 
 39          'opensuse10': RTE_OPENSUSE10, 
 40          'opensuse11': RTE_OPENSUSE11, 
 41          'opensuse12': RTE_OPENSUSE12, 
 42          'opensuse13': RTE_OPENSUSE13, 
 43          'opensuse14': RTE_OPENSUSE14, 
 44          'opensuse15': RTE_OPENSUSE15, 
 45          'opensuse151': RTE_OPENSUSE151, 
 46          'opensuse16': RTE_OPENSUSE16, 
 47          'opensuse17': RTE_OPENSUSE17, 
 48          'opensuse423': RTE_OPENSUSE423, 
 49          RTE_OPENSUSE10: RTE_OPENSUSE10, 
 50          RTE_OPENSUSE11: RTE_OPENSUSE11, 
 51          RTE_OPENSUSE12: RTE_OPENSUSE12, 
 52          RTE_OPENSUSE13: RTE_OPENSUSE13, 
 53          RTE_OPENSUSE14: RTE_OPENSUSE14, 
 54          RTE_OPENSUSE151: RTE_OPENSUSE151, 
 55          RTE_OPENSUSE15: RTE_OPENSUSE15, 
 56          RTE_OPENSUSE16: RTE_OPENSUSE16, 
 57          RTE_OPENSUSE17: RTE_OPENSUSE17, 
 58          RTE_OPENSUSE423: RTE_OPENSUSE423, 
 59          RTE_OPENSUSE: RTE_OPENSUSE, 
 60      } 
 61  ) 
 62   
 63   
 64  #: mapping of the rte numeric representation to the string value 
 65  num2rte.update( 
 66      { 
 67          RTE_OPENSUSE: 'opensuse', 
 68          RTE_OPENSUSE10: 'opensuse10', 
 69          RTE_OPENSUSE11: 'opensuse11', 
 70          RTE_OPENSUSE12: 'opensuse12', 
 71          RTE_OPENSUSE13: 'opensuse13', 
 72          RTE_OPENSUSE14: 'opensuse14', 
 73          RTE_OPENSUSE15: 'opensuse15', 
 74          RTE_OPENSUSE151: 'opensuse151', 
 75          RTE_OPENSUSE16: 'opensuse16', 
 76          RTE_OPENSUSE17: 'opensuse17', 
 77          RTE_OPENSUSE423: 'opensuse423', 
 78      } 
 79  ) 
 80   
 81   
 82  num2pretty.update( 
 83      { 
 84      } 
 85  ) 
 86   
 87   
 88  dist = ['', '', '', 'openSUSE', '', ''] 
 89   
 90  try: 
 91   
 92      with open("/etc/os-release", 'r') as f: 
 93          for l in f: 
 94              if l.startswith('ID='): 
 95                  dist[5] = DSKORG_ID.sub(r'\1', l) 
 96   
 97              elif l.startswith('VERSION='):  # priority though more widespread 
 98                  dist[1] = DSKORG_VERSION.sub(r'\1', l)  
 99               
100              elif l.startswith('NAME='): 
101                  dist[3] = DSKORG_ID.sub(r'\1', l) 
102   
103      if dist[5] == 'opensuse': 
104          dist[4] = decode_version_str_to_segments(dist[1]) 
105          dist[0] = '%s%d%d' % (dist[5], dist[4][0], dist[4][1],)    
106          dist[2] = '%s-%d.%d.%d' % (dist[3], dist[4][0], dist[4][1], dist[4][2],)    
107   
108           
109  except PlatformIDsFileCheck: 
110      # not on OpenSUSE platform, so scan will fail 
111      pass     
112   
113   
114  if dist[5] != 'opensuse': 
115      # does not actually match OpenSUSE 
116      dist = ['opensuse', '0.0.0', 'openSUSE-0.0.0', 'openSUSE', (0, 0, 0,), 'opensuse'] 
117