Package platformids :: Package dist :: Module rhel

Source Code for Module platformids.dist.rhel

  1  # -*- coding: utf-8 -*- 
  2  """RHEL releases. 
  3  """ 
  4  from __future__ import absolute_import 
  5   
  6  import re 
  7   
  8   
  9  from pythonids import PYV35Plus 
 10  from platformids import RTE_RHEL, rte2num, num2rte, num2pretty, decode_version_str_to_segments, \ 
 11      PlatformIDsFileCheck 
 12   
 13  __author__ = 'Arno-Can Uestuensoez' 
 14  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 15  __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \ 
 16                  " @Ingenieurbuero Arno-Can Uestuensoez" 
 17  __version__ = '0.1.35' 
 18  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
 19   
 20   
 21   
 22  RTE_RHEL5   = RTE_RHEL      + 0x00001400  #: RHEL-5 
 23  # RTE_RHEL50  = RTE_RHEL      + 0x00001400  #: RHEL-5.0 
 24  # RTE_RHEL51  = RTE_RHEL      + 0x00001420  #: RHEL-5.1 
 25  # RTE_RHEL52  = RTE_RHEL      + 0x00001440  #: RHEL-5.2 
 26  # RTE_RHEL53  = RTE_RHEL      + 0x00001460  #: RHEL-5.3 
 27  # RTE_RHEL54  = RTE_RHEL      + 0x00001480  #: RHEL-5.4 
 28  # RTE_RHEL55  = RTE_RHEL      + 0x000014a0  #: RHEL-5.5 
 29  # RTE_RHEL56  = RTE_RHEL      + 0x000014c0  #: RHEL-5.6 
 30  # RTE_RHEL57  = RTE_RHEL      + 0x000014e0  #: RHEL-5.7 
 31  # RTE_RHEL58  = RTE_RHEL      + 0x00001500  #: RHEL-5.8 
 32  # RTE_RHEL59  = RTE_RHEL      + 0x00001520  #: RHEL-5.9 
 33  # RTE_RHEL510 = RTE_RHEL      + 0x00001540  #: RHEL-5.10 
 34  # RTE_RHEL511 = RTE_RHEL      + 0x00001560  #: RHEL-5.11 
 35   
 36  RTE_RHEL6   = RTE_RHEL      + 0x00001800  #: RHEL-6 
 37  RTE_RHEL60  = RTE_RHEL      + 0x00001800  #: RHEL-6.0 
 38  RTE_RHEL61  = RTE_RHEL      + 0x00001820  #: RHEL-6.1 
 39  RTE_RHEL62  = RTE_RHEL      + 0x00001840  #: RHEL-6.2 
 40  RTE_RHEL63  = RTE_RHEL      + 0x00001860  #: RHEL-6.3 
 41  RTE_RHEL64  = RTE_RHEL      + 0x00001880  #: RHEL-6.4 
 42  RTE_RHEL65  = RTE_RHEL      + 0x000018a0  #: RHEL-6.5 
 43  RTE_RHEL66  = RTE_RHEL      + 0x000018c0  #: RHEL-6.6 
 44  RTE_RHEL67  = RTE_RHEL      + 0x000018e0  #: RHEL-6.7 
 45  RTE_RHEL68  = RTE_RHEL      + 0x00001900  #: RHEL-6.8 
 46  RTE_RHEL69  = RTE_RHEL      + 0x00001920  #: RHEL-6.9 
 47  RTE_RHEL610 = RTE_RHEL      + 0x00001940  #: RHEL-6.10 
 48   
 49  RTE_RHEL7 = RTE_RHEL        + 0x00001c00  #: RHEL-7 
 50  RTE_RHEL70 = RTE_RHEL       + 0x00001c00  #: RHEL-7.0 
 51  RTE_RHEL71 = RTE_RHEL       + 0x00001c20  #: RHEL-7.1 
 52  RTE_RHEL72 = RTE_RHEL       + 0x00001c40  #: RHEL-7.2 
 53  RTE_RHEL73 = RTE_RHEL       + 0x00001c60  #: RHEL-7.3 
 54  RTE_RHEL74 = RTE_RHEL       + 0x00001c80  #: RHEL-7.4 
 55  RTE_RHEL75 = RTE_RHEL       + 0x00001ca0  #: RHEL-7.5 
 56  RTE_RHEL76 = RTE_RHEL       + 0x00001cc0  #: RHEL-7.6 
 57  RTE_RHEL77 = RTE_RHEL       + 0x00001ce0  #: RHEL-7.7 
 58  RTE_RHEL78 = RTE_RHEL       + 0x00001d00  #: RHEL-7.8 
 59  RTE_RHEL79 = RTE_RHEL       + 0x00001d20  #: RHEL-7.9 
 60  RTE_RHEL710 = RTE_RHEL      + 0x00001d40  #: RHEL-7.10 
 61   
 62  RTE_RHEL8 = RTE_RHEL        + 0x00002000  #: RHEL-8 
 63  RTE_RHEL80 = RTE_RHEL       + 0x00002000  #: RHEL-8.0 
 64  RTE_RHEL81 = RTE_RHEL       + 0x00002020  #: RHEL-8.1 
 65  RTE_RHEL82 = RTE_RHEL       + 0x00002040  #: RHEL-8.2 
 66  RTE_RHEL83 = RTE_RHEL       + 0x00002060  #: RHEL-8.3 
 67  RTE_RHEL84 = RTE_RHEL       + 0x00002080  #: RHEL-8.4 
 68  RTE_RHEL85 = RTE_RHEL       + 0x000020a0  #: RHEL-8.5 
 69   
 70  RTE_RHEL9 = RTE_RHEL       + 0x000002200  #: RHEL-9 
 71  RTE_RHEL90 = RTE_RHEL      + 0x000002200  #: RHEL-9.0 
 72   
 73   
 74  #: mapping of the rte string and numeric representation to the numeric value 
 75  rte2num.update( 
 76      { 
 77          'Maipo': RTE_RHEL7, 
 78          'Ootpa': RTE_RHEL8, 
 79          'RHEL9': RTE_RHEL9, 
 80          'Santiago': RTE_RHEL6, 
 81          'Tikanga': RTE_RHEL5, 
 82          'rhel5': RTE_RHEL5, 
 83          'rhel6': RTE_RHEL6, 
 84          'rhel7': RTE_RHEL7, 
 85          'rhel8': RTE_RHEL8, 
 86          'rhel9': RTE_RHEL9, 
 87          RTE_RHEL5: RTE_RHEL5, 
 88          RTE_RHEL6: RTE_RHEL6, 
 89          RTE_RHEL7: RTE_RHEL7, 
 90          RTE_RHEL8: RTE_RHEL8, 
 91          RTE_RHEL9: RTE_RHEL9, 
 92      } 
 93  ) 
 94   
 95   
 96  #: mapping of the rte numeric representation to the string value 
 97  num2rte.update( 
 98      { 
 99          RTE_RHEL5: 'rhel5', 
100          RTE_RHEL6: 'rhel6', 
101          RTE_RHEL7: 'rhel7', 
102          RTE_RHEL8: 'rhel8', 
103          RTE_RHEL9: 'rhel9', 
104      } 
105  ) 
106   
107  #: mapping of the rte numeric representation to the pretty string value 
108  num2pretty.update( 
109      { 
110          RTE_RHEL5: 'Tikanga', 
111          RTE_RHEL6: 'Santiago', 
112          RTE_RHEL7: 'Maipo', 
113          RTE_RHEL8: 'Ootpa', 
114          RTE_RHEL9: 'RHEL9', 
115      } 
116  ) 
117   
118   
119  dist = ['', '', '', 'RHEL', '', ''] 
120   
121  try: 
122   
123      with open("/etc/redhat-release", 'r') as f: 
124          for l in f: 
125              _d = re.split(r'(?s)^([^0-9]*) release *([0-9.]*[^ ]*) [^(]*[(]([^)]*)[)][\n\t ]*$', l) 
126       
127   
128      if _d[1].startswith('Red Hat'): 
129          dist[1] = _d[2] 
130          dist[4] = decode_version_str_to_segments(_d[2]) 
131          dist[0] = 'rhel%d%d' % (dist[4][0], dist[4][1]) 
132          dist[2] = "RHEL-" + _d[2] 
133          dist[5] = 'rhel' 
134   
135   
136  except PlatformIDsFileCheck: 
137      # not on RHEL platform, so scan will fail 
138      pass     
139   
140   
141  if dist[5] != 'rhel': 
142      # does not actually match RHEL 
143      dist = ['rhel', '0.0.0', 'RHEL-0.0.0', 'RHEL', (0, 0, 0,), 'rhel'] 
144