Package platformids :: Package dist :: Module netbsd

Source Code for Module platformids.dist.netbsd

  1  # -*- coding: utf-8 -*- 
  2  """NetBSD releases. 
  3  """ 
  4  from __future__ import absolute_import 
  5   
  6  import sys 
  7  import os 
  8  import re 
  9  import platform 
 10   
 11  from pythonids import PYV35Plus 
 12  from platformids import RTE_BSD, rte2num, num2rte, num2pretty, decode_version_str_to_segments, \ 
 13      PlatformIDsFileCheck 
 14   
 15   
 16  __author__ = 'Arno-Can Uestuensoez' 
 17  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 18  __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \ 
 19                  " @Ingenieurbuero Arno-Can Uestuensoez" 
 20  __version__ = '0.1.29' 
 21  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
 22   
 23   
 24   
 25  RTE_NETBSD = RTE_BSD        + 0x00060000  #: NetBSD 
 26  RTE_NETBSD60 = RTE_NETBSD   + 0x00001800  #: NETBSD-6.0 
 27  RTE_NETBSD70 = RTE_NETBSD   + 0x00001c00  #: NETBSD-7.0 
 28  RTE_NETBSD71 = RTE_NETBSD   + 0x00001c20  #: NETBSD-7.1 
 29  RTE_NETBSD80 = RTE_NETBSD   + 0x00002000  #: NETBSD-8.0 
 30  RTE_NETBSD90 = RTE_NETBSD   + 0x00002400  #: NETBSD-9.0 
 31  RTE_NETBSD100 = RTE_NETBSD  + 0x00002800  #: NETBSD-10.0 
 32       
 33  #: mapping of the rte string and numeric representation to the numeric value 
 34  rte2num.update( 
 35      { 
 36          'netbsd': RTE_NETBSD, 
 37          'netbsd60': RTE_NETBSD60, 
 38          'netbsd71': RTE_NETBSD71, 
 39          'netbsd70': RTE_NETBSD70, 
 40          'netbsd80': RTE_NETBSD80, 
 41          'netbsd90': RTE_NETBSD90, 
 42          RTE_NETBSD: RTE_NETBSD, 
 43          RTE_NETBSD60: RTE_NETBSD60, 
 44          RTE_NETBSD70: RTE_NETBSD70, 
 45          RTE_NETBSD71: RTE_NETBSD71, 
 46          RTE_NETBSD80: RTE_NETBSD80, 
 47          RTE_NETBSD90: RTE_NETBSD90, 
 48      } 
 49  ) 
 50   
 51   
 52  #: mapping of the rte numeric representation to the string value 
 53  num2rte.update( 
 54      { 
 55          RTE_NETBSD: 'netbsd', 
 56          RTE_NETBSD60: 'netbsd60', 
 57          RTE_NETBSD70: 'netbsd70', 
 58          RTE_NETBSD71: 'netbsd71', 
 59          RTE_NETBSD80: 'netbsd80', 
 60          RTE_NETBSD90: 'netbsd90', 
 61      } 
 62  ) 
 63   
 64   
 65  #: mapping of the rte numeric representation to the pretty string value 
 66  num2pretty.update( 
 67      { 
 68          RTE_NETBSD: 'NetBSD', 
 69      } 
 70  ) 
 71   
 72   
 73  dist = ['', '', 'NetBSD', 'NetBSD', '', ''] 
 74   
 75  try: 
 76      if sys.platform.lower().startswith('netbsd'): 
 77          # FreeBSD - CPython, PyPy, IPython 
 78          dist[1] = platform.release() 
 79          dist[5] = 'netbsd'  
 80       
 81      elif os.path.exists('/etc/netbsd-update.conf'): 
 82          # FreeBSD - match on Jython 
 83          x = os.popen("sysctl kern.ostype kern.osrelease", mode='r') 
 84          if x.readline().endswith("NetBSD\n"): 
 85              dist[1] = re.sub(r'[^=]*=([0-9.]*).*$', r'\1', x.readline()) 
 86              dist[5] = 'netbsd'  
 87          x.close() 
 88               
 89       
 90      if dist[5] == 'netbsd': 
 91          dist[4] = decode_version_str_to_segments(dist[1]) 
 92          dist[0] = 'netbsd%d' % (dist[4][0], dist[4][1], )  
 93          dist[2] = 'NetBSD-%d.%d.%d' %(dist[4][0], dist[4][1], dist[4][2], ) 
 94   
 95   
 96  except PlatformIDsFileCheck: 
 97      # not on NetBSD platform, so scan will fail 
 98      pass     
 99   
100   
101  if dist[5] != 'netbsd': 
102      # does not actually match NetBSD 
103      dist = ['netbsd', '0.0.0', 'NetBSD-0.0.0', 'NetBSD', (0, 0, 0,), 'netbsd'] 
104