Package platformids :: Package dist :: Module alpinelinux

Source Code for Module platformids.dist.alpinelinux

 1  # -*- coding: utf-8 -*- 
 2  """AlpineLinux releases. 
 3  """ 
 4  from __future__ import absolute_import 
 5   
 6  import os 
 7   
 8   
 9  from pythonids import PYV35Plus 
10  from platformids import rte2num, num2rte, num2pretty, decode_version_str_to_segments, RTE_LINUX, \ 
11      DSKORG_ID, DSKORG_VERSION, VERSION_ID, PlatformIDsFileCheck 
12   
13   
14  __author__ = 'Arno-Can Uestuensoez' 
15  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
16  __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \ 
17                  " @Ingenieurbuero Arno-Can Uestuensoez" 
18  __version__ = '0.1.35' 
19  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
20   
21   
22  RTE_ALPINELIN         = RTE_LINUX              + 0x00090000     #: Alpine Linux 
23  RTE_ALPINELIN381      = RTE_ALPINELIN          + 0x0000d01      #: AlpieLinux-3.8.1 
24  RTE_ALPINELIN39       = RTE_ALPINELIN          + 0x0000d20      #: AlpieLinux-3.9 
25  RTE_ALPINELIN310      = RTE_ALPINELIN          + 0x0000d40      #: AlpieLinux-3.10 
26   
27       
28  #: mapping of the rte string and numeric representation to the numeric value 
29  rte2num.update( 
30      { 
31          'alpinelinux':             RTE_ALPINELIN, 
32          'alpinelinux381':          RTE_ALPINELIN381, 
33          RTE_ALPINELIN381:          RTE_ALPINELIN381, 
34          RTE_ALPINELIN:             RTE_ALPINELIN, 
35          'alpinelinux39':          RTE_ALPINELIN39, 
36          RTE_ALPINELIN39:          RTE_ALPINELIN39, 
37          'alpinelinux310':          RTE_ALPINELIN310, 
38          RTE_ALPINELIN310:          RTE_ALPINELIN310, 
39      } 
40  ) 
41   
42   
43  #: mapping of the rte numeric representation to the string value 
44  num2rte.update( 
45      { 
46          RTE_ALPINELIN:        'alpinelinux', 
47          RTE_ALPINELIN381:     'alpinelinux381', 
48          RTE_ALPINELIN39:      'alpinelinux39', 
49          RTE_ALPINELIN310:     'alpinelinux310', 
50      } 
51  ) 
52   
53  #: mapping of the rte numeric representation to the pretty string value 
54  num2pretty.update( 
55      { 
56          RTE_ALPINELIN:        'AlpineLinux', 
57      } 
58  ) 
59   
60  dist = ['', '', '', '', '', ''] 
61   
62  try: 
63      if os.path.exists("/etc/os-release"): 
64          # 
65          # slightly different to others, thus do not want shared code 
66          # 
67          with open("/etc/os-release", 'r') as f: 
68              for l in f: 
69                  if l.startswith('ID='): 
70                      dist[0] = dist[5] = DSKORG_ID.sub(r'\1', l) 
71       
72                  #  = re.compile(r'(?s)^VERSION_ID=["\']*([^"\']*)["\']*.*') 
73                  elif l.startswith('VERSION_ID='): 
74                      # optional custom value, not defined by ArchLinux 
75                      dist[1] = VERSION_ID.sub(r'\1', l) 
76   
77                  elif l.startswith('VERSION='): 
78                      # optional custom value, not defined by ArchLinux 
79                      dist[1] = DSKORG_VERSION.split(l) 
80   
81      if dist[0] == 'alpine': 
82          dist[2] += '-' + dist[1]   
83          dist[4] = decode_version_str_to_segments(dist[1]) 
84          dist[0] +=  '%d%d%d' % (dist[4][0], dist[4][1], dist[4][2],) 
85   
86   
87  except PlatformIDsFileCheck: 
88      # not on AlpineLinux platform, so scan will fail 
89      pass     
90   
91   
92  if dist[5] != 'alpine': 
93      # does not actually match AlpineLinux 
94      dist = ['alpine', '0.0.0', 'AlpineLinux-0.0.0', 'AlpineLinux', (0, 0, 0,), 'alpine'] 
95