Package platformids :: Package dist :: Module sles

Source Code for Module platformids.dist.sles

 1  # -*- coding: utf-8 -*- 
 2  """SLES releases. 
 3  """ 
 4  from __future__ import absolute_import 
 5   
 6  from platformids import RTE_SLES, rte2num, num2rte, num2pretty, decode_version_str_to_segments, \ 
 7      DSKORG_ID, DSKORG_VERSION, PlatformIDsFileCheck 
 8   
 9  __author__ = 'Arno-Can Uestuensoez' 
10  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
11  __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \ 
12                  " @Ingenieurbuero Arno-Can Uestuensoez" 
13  __version__ = '0.1.29' 
14  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
15   
16   
17   
18  RTE_SLES15  = RTE_SLES       + 0x00003400  #: RHEL-5 
19  RTE_SLES150 = RTE_SLES       + 0x00003c00  #: RHEL-15.0 
20  RTE_SLES151 = RTE_SLES       + 0x00003c20  #: RHEL-15.1 
21   
22   
23  #: mapping of the rte string and numeric representation to the numeric value 
24  rte2num.update( 
25      { 
26          'sles15': RTE_SLES15, 
27          RTE_SLES15: RTE_SLES15, 
28      } 
29  ) 
30   
31   
32  #: mapping of the rte numeric representation to the string value 
33  num2rte.update( 
34      { 
35          RTE_SLES15: 'sles15', 
36      } 
37  ) 
38   
39  #: mapping of the rte numeric representation to the pretty string value 
40  num2pretty.update( 
41      { 
42          RTE_SLES15: 'SLES15', 
43      } 
44  ) 
45   
46   
47  dist = ['', '', '', 'SLES', '', ''] 
48   
49  try: 
50   
51      with open("/etc/os-release", 'r') as f: 
52          for l in f: 
53              if l.startswith('ID='): 
54                  dist[5] = DSKORG_ID.sub(r'\1', l) 
55   
56              elif l.startswith('VERSION='):  # priority though more widespread 
57                  dist[1] = DSKORG_VERSION.sub(r'\1', l)  
58               
59              elif l.startswith('NAME='): 
60                  dist[3] = DSKORG_ID.sub(r'\1', l) 
61   
62      if dist[5] == 'sles': 
63          dist[4] = decode_version_str_to_segments(dist[1]) 
64          dist[0] = '%s%d%d' % (dist[5], dist[4][0], dist[4][1],)    
65          dist[2] = '%s-%d.%d.%d' % (dist[3], dist[4][0], dist[4][1], dist[4][2],)    
66   
67   
68  except PlatformIDsFileCheck: 
69      # not on SLES platform, so scan will fail 
70      pass     
71   
72   
73  if dist[5] != 'sles': 
74      # does not actually match SLES 
75      dist = ['sles', '0.0.0', 'SLES-0.0.0', 'SLES', (0, 0, 0,), 'sles'] 
76