Package platformids :: Package dist :: Module cygwin

Source Code for Module platformids.dist.cygwin

  1  # -*- coding: utf-8 -*- 
  2  """Cygwin releases. 
  3  """ 
  4  from __future__ import absolute_import 
  5   
  6  import os 
  7  import sys 
  8  import re 
  9   
 10  from pythonids import PYV35Plus 
 11  # from platformids import RTE_CYGWINNT, rte2num, num2rte, num2pretty, decode_version_str_to_segments, \ 
 12  #     PlatformIDsFileCheck 
 13   
 14  import platformids  
 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  RTE_CYGWIN        = platformids.RTE_CYGWINNT + 0x00010000     #: Cygwin running within PWEMU on WindowsNT 
 25  RTE_CYGWIN1       = platformids.RTE_CYGWINNT + 0x00020000     #: Cygwin-2.* - contains the major version number 
 26  RTE_CYGWIN2       = platformids.RTE_CYGWINNT + 0x00040000     #: Cygwin-2.* - contains the major version number 
 27  RTE_CYGWIN3       = platformids.RTE_CYGWINNT + 0x00080000     #: Cygwin-3.* - contains the major version number 
 28   
 29  RTE_CYGWIN290     = RTE_CYGWIN2  + 0x00000520  #: Cygwin-2.9.0 
 30   
 31   
 32    
 33  #: mapping of the rte string and numeric representation to the numeric value 
 34  platformids.rte2num.update( 
 35      { 
 36          'cygwin': RTE_CYGWIN, 
 37          'cygwin1': RTE_CYGWIN1, 
 38          'cygwin2': RTE_CYGWIN2, 
 39          'cygwin290': RTE_CYGWIN290, 
 40          'cygwin3': RTE_CYGWIN3, 
 41          'cygwinnt': platformids.RTE_CYGWINNT, 
 42          RTE_CYGWIN1: RTE_CYGWIN1, 
 43          RTE_CYGWIN290: RTE_CYGWIN290, 
 44          RTE_CYGWIN2: RTE_CYGWIN2, 
 45          RTE_CYGWIN3: RTE_CYGWIN3, 
 46          RTE_CYGWIN: RTE_CYGWIN, 
 47          platformids.RTE_CYGWINNT: platformids.RTE_CYGWINNT, 
 48      } 
 49  ) 
 50   
 51   
 52  #: mapping of the rte numeric representation to the string value 
 53  platformids.num2rte.update( 
 54      { 
 55          RTE_CYGWIN: 'cygwin', 
 56          RTE_CYGWIN1: 'cygwin1', 
 57          RTE_CYGWIN2: 'cygwin2', 
 58          RTE_CYGWIN290: 'cygwin290', 
 59          RTE_CYGWIN3: 'cygwin3', 
 60          platformids.RTE_CYGWINNT: 'cygwinnt', 
 61      } 
 62  ) 
 63   
 64  #: mapping of the rte numeric representation to the pretty string value 
 65  platformids.num2pretty.update( 
 66      { 
 67          RTE_CYGWIN: 'Cygwin', 
 68          RTE_CYGWIN1: 'Cygwin-1', 
 69          RTE_CYGWIN2: 'Cygwin-2', 
 70          RTE_CYGWIN290: 'Cygwin-2.9.0', 
 71          RTE_CYGWIN3: 'Cygwin-3', 
 72          platformids.RTE_CYGWINNT: 'CygwinNT', 
 73      } 
 74  ) 
 75   
 76   
 77  dist = ['', '', '', 'Cygwin', '', 'cygwin'] 
 78   
 79  try: 
 80       
 81   
 82      if ( 
 83              sys.platform.startswith('cygwin') 
 84              or 
 85              os.path.exists('/cygdrive')  # rely on standard path only for now 
 86          ): 
 87   
 88          with open("/proc/version", 'r') as f: 
 89              for l in f: 
 90                  dist[1] = re.sub(r'.* version ([0-9.]*).*', '\1', l)  # for all implementations including Jython 
 91       
 92          dist[4] = platformids.decode_version_str_to_segments(dist[1]) 
 93          dist[0] = 'cygwin%d%d%d' % (dist[4][0], dist[4][1], dist[4][2]) 
 94          dist[2] = 'Cygwin-' + dist[1] 
 95   
 96   
 97  except platformids.PlatformIDsFileCheck: 
 98      # not on Cygwin platform, so scan will fail 
 99      pass     
100   
101   
102  if dist[5] != 'cygwin': 
103      # does not actually match Cygwin 
104      dist = ['cygwin', '0.0.0', 'Cygwin-0.0.0', 'Cygwin', (0, 0, 0,), 'cygwin'] 
105