Browse code

Removing dparted from the installer.

* Removing the dependency of the dparted in the installer.
* Unblocking installation on bare-metal.

Mahmoud Bassiouny authored on 2015/07/23 09:29:56
Showing 6 changed files
... ...
@@ -12,7 +12,7 @@
12 12
                 "Linux-PAM", "attr", "libcap", "systemd", "dbus",
13 13
                 "elfutils-libelf", "sqlite-autoconf", "nspr", "nss", "popt", "lua", "rpm",
14 14
                 "gptfdisk", "tar", "gzip", "openssl", "python2", "python2-libs", "python-requests",
15
-                "pcre", "glib", "parted", "libsigc++", "XML-Parser", "glibmm", "dparted",
15
+                "pcre",
16 16
                 "libgsystem", "ostree","device-mapper","device-mapper-libs","libsepol","libselinux", 
17 17
                 "db", "libsolv", "hawkey", "python-hawkey"]
18 18
 }
... ...
@@ -4,33 +4,30 @@
4 4
 #
5 5
 #    Author: Mahmoud Bassiouny <mbassiouny@vmware.com>
6 6
 
7
-import curses
8 7
 import subprocess
9 8
 import os
10
-import json
11
-from partition import Partition
12 9
 
13 10
 class Device(object):
14
-    def __init__(self, model, path, size, partitions):
11
+    def __init__(self, model, path, size):
15 12
         self.model = model
16 13
         self.path = path
17 14
         self.size = size
18
-        self.partitions = partitions
19 15
 
20 16
     @staticmethod
21 17
     def refresh_devices():
22
-        devices_json = subprocess.check_output(['gpartedbin', 'getdevices'], stderr=open(os.devnull, 'w'))
23
-        devices = Device.wrap_devices_from_dict(json.loads(devices_json))
24
-        return devices
18
+        devices_list = subprocess.check_output(['lsblk', '-S', '-I', '8', '-n', '--output', 'NAME,SIZE,MODEL'], stderr=open(os.devnull, 'w'))
19
+        return Device.wrap_devices_from_list(devices_list)
25 20
 
26 21
     @staticmethod
27
-    def wrap_devices_from_dict(dct):
28
-        if dct['success'] == False:
29
-            return [];
30
-
22
+    def wrap_devices_from_list(list):
31 23
         devices = []
32
-        for device in dct['devices']:
24
+        deviceslines = list.splitlines()
25
+        for deviceline in deviceslines:
26
+            cols = deviceline.split(None, 2)
33 27
             devices.append(
34
-                    Device(device['model'], device['path'], device['size'], Partition.wrap_partitions_from_dict_arr(device['partitions'])))
28
+                    Device(cols[2] #Model
29
+                        , '/dev/' + cols[0] #Path
30
+                        , cols[1] #size
31
+                        ))
35 32
 
36 33
         return devices
37 34
\ No newline at end of file
... ...
@@ -1,8 +1,43 @@
1
+import os
2
+import subprocess
1 3
 import re
2 4
 
3 5
 PRE_INSTALL = "pre-install"
4 6
 POST_INSTALL = "post-install"
5 7
 
8
+def partition_disk(disk):
9
+    partitions_data = {}
10
+    partitions_data['disk'] = disk
11
+    partitions_data['root'] = disk + '2'
12
+
13
+    output = open(os.devnull, 'w')
14
+
15
+    # Clear the disk
16
+    process = subprocess.Popen(['sgdisk', '-o', '-g', partitions_data['disk']], stdout = output)
17
+    retval = process.wait()
18
+    if retval != 0:
19
+    	return None
20
+
21
+    # 1: grub, 2: filesystem
22
+    process = subprocess.Popen(['sgdisk', '-n', '1::+2M', '-n', '2:', '-p', partitions_data['disk']], stdout = output)
23
+    retval = process.wait()
24
+    if retval != 0:
25
+    	return None
26
+
27
+    # Add the grub flags
28
+    process = subprocess.Popen(['sgdisk', '-t1:ef02', partitions_data['disk']], stdout = output)
29
+    retval = process.wait()
30
+    if retval != 0:
31
+    	return None
32
+
33
+    # format the file system
34
+    process = subprocess.Popen(['mkfs', '-t', 'ext4', partitions_data['root']], stdout = output)
35
+    retval = process.wait()
36
+    if retval != 0:
37
+    	return None
38
+    	
39
+    return partitions_data
40
+
6 41
 def replace_string_in_file(filename,  search_string,  replace_string):
7 42
     with open(filename, "r") as source:
8 43
         lines=source.readlines()
... ...
@@ -5,31 +5,7 @@ import commons
5 5
 install_phase = commons.PRE_INSTALL
6 6
 enabled = True
7 7
 
8
-def partition_disk(disk):
9
-    partitions_data = {}
10
-    partitions_data['disk'] = disk
11
-    partitions_data['root'] = disk + '2'
12
-
13
-    output = open(os.devnull, 'w')
14
-
15
-    # Clear the disk
16
-    process = subprocess.Popen(['sgdisk', '-o', '-g', partitions_data['disk']], stdout = output)
17
-    retval = process.wait()
18
-
19
-    # 1: grub, 2: filesystem
20
-    process = subprocess.Popen(['sgdisk', '-n', '1::+2M', '-n', '2:', '-p', partitions_data['disk']], stdout = output)
21
-    retval = process.wait()
22
-
23
-    # Add the grub flags
24
-    process = subprocess.Popen(['sgdisk', '-t1:ef02', partitions_data['disk']], stdout = output)
25
-    retval = process.wait()
26
-
27
-    # format the file system
28
-    process = subprocess.Popen(['mkfs', '-t', 'ext4', partitions_data['root']], stdout = output)
29
-    retval = process.wait()
30
-    return partitions_data
31
-
32 8
 def execute(name, ks_config, config, root):
33 9
 
34 10
 	if ks_config:
35
-		config['disk'] = partition_disk(ks_config['disk'])
11
+		config['disk'] = commons.partition_disk(ks_config['disk'])
36 12
deleted file mode 100644
... ...
@@ -1,21 +0,0 @@
1
-#! /usr/bin/python2
2
-#
3
-#    Copyright (C) 2015 vmware inc.
4
-#
5
-#    Author: Mahmoud Bassiouny <mbassiouny@vmware.com>
6
-
7
-class Partition(object):
8
-    def __init__(self, path, size, filesystem):
9
-        self.path = path
10
-        self.size = size
11
-        self.filesystem = filesystem
12
-        self.unallocated = (path == 'unallocated')
13
-
14
-    @staticmethod
15
-    def wrap_partitions_from_dict_arr(arr):
16
-    	partitions = []
17
-        for partition in arr:
18
-            partitions.append(Partition(partition['path'], partition['size'], partition['filesystem']))
19
-
20
-        return partitions
21
-
... ...
@@ -4,14 +4,12 @@
4 4
 #
5 5
 #    Author: Mahmoud Bassiouny <mbassiouny@vmware.com>
6 6
 
7
-import subprocess
8
-import os
9
-import json
10 7
 from device import Device
11 8
 from window import Window
12 9
 from actionresult import ActionResult
13 10
 from menu import Menu
14 11
 from confirmwindow import ConfirmWindow
12
+import modules.commons
15 13
 
16 14
 class SelectDisk(object):
17 15
     def __init__(self,  maxy, maxx, install_config):
... ...
@@ -42,18 +40,15 @@ class SelectDisk(object):
42 42
         if not confirmed:
43 43
             return ActionResult(confirmed, None)
44 44
         
45
-        #self.install_config['disk'] = self.devices[device_index].path
46
-        #return ActionResult(True, None)
47
-        
48 45
         # Do the partitioning
49 46
         self.window.clearerror()
50
-        json_ret = subprocess.check_output(['gpartedbin', 'defaultpartitions', self.devices[device_index].path], stderr=open(os.devnull, 'w'))
51
-        json_dct = json.loads(json_ret)
52
-        if json_dct['success']:
53
-            self.install_config['disk'] = json_dct['data']
54
-        else:
47
+        partitions_data = modules.commons.partition_disk(self.devices[device_index].path)
48
+        if partitions_data == None:
55 49
             self.window.adderror('Partitioning failed, you may try again')
56
-        return ActionResult(json_dct['success'], None)
50
+        else:
51
+            self.install_config['disk'] = partitions_data
52
+
53
+        return ActionResult(partitions_data != None, None)
57 54
 
58 55
     def display(self, params):
59 56
         self.window.addstr(0, 0, 'First, we will setup your disks.\n\nWe have detected {0} disks, choose disk to be auto-partitioned:'.format(len(self.devices)))
... ...
@@ -65,7 +60,7 @@ class SelectDisk(object):
65 65
             #if index > 0:
66 66
                 self.disk_menu_items.append(
67 67
                         (
68
-                            '{2} - {1} MB @ {0}'.format(device.path, device.size, device.model), 
68
+                            '{2} - {1} @ {0}'.format(device.path, device.size, device.model), 
69 69
                             self.guided_partitions, 
70 70
                             index
71 71
                         )