Просмотр исходного кода

Improved Debian and Ubuntu OS detection

Alessandro Pilotti 10 лет назад
Родитель
Сommit
5f91fc8f90
2 измененных файлов с 11 добавлено и 16 удалено
  1. 6 6
      coriolis/osmorphing/debian.py
  2. 5 10
      coriolis/osmorphing/ubuntu.py

+ 6 - 6
coriolis/osmorphing/debian.py

@@ -1,5 +1,4 @@
 import os
-import re
 
 from coriolis import constants
 from coriolis.osmorphing import base
@@ -16,13 +15,14 @@ class DebianMorphingTools(base.BaseLinuxOSMorphingTools):
         lsb_release_path = "etc/lsb-release"
         debian_version_path = "etc/debian_version"
         if self._test_path(lsb_release_path):
-            out = self._read_file(lsb_release_path).decode()
-            dist_id = re.findall('^DISTRIB_ID=(.*)$', out, re.MULTILINE)
-            release = re.findall('^DISTRIB_RELEASE=(.*)$', out, re.MULTILINE)
-            if 'Debian' in dist_id:
+            config = self._read_config_file("etc/lsb-release")
+            dist_id = config.get('DISTRIB_ID')
+            if dist_id == 'Debian':
+                release = config.get('DISTRIB_RELEASE')
                 return (dist_id, release)
         elif self._test_path(debian_version_path):
-            release = self._read_file(debian_version_path).decode()
+            release = self._read_file(
+                debian_version_path).decode().split('\n')[0]
             return ('Debian', release)
 
     def set_net_config(self, nics_info, dhcp):

+ 5 - 10
coriolis/osmorphing/ubuntu.py

@@ -1,5 +1,3 @@
-import re
-
 from coriolis import constants
 from coriolis.osmorphing import debian
 
@@ -15,11 +13,8 @@ class UbuntuMorphingTools(debian.DebianMorphingTools):
     }
 
     def _check_os(self):
-        lsb_release_path = "etc/lsb-release"
-        if self._test_path(lsb_release_path):
-            out = self._read_file(lsb_release_path).decode()
-
-            dist_id = re.findall('^DISTRIB_ID=(.*)$', out, re.MULTILINE)
-            release = re.findall('^DISTRIB_RELEASE=(.*)$', out, re.MULTILINE)
-            if 'Ubuntu' in dist_id:
-                return (dist_id, release)
+        config = self._read_config_file("etc/lsb-release", check_exists=True)
+        dist_id = config.get('DISTRIB_ID')
+        if dist_id == 'Ubuntu':
+            release = config.get('DISTRIB_RELEASE')
+            return (dist_id, release)