summaryrefslogtreecommitdiffstats
path: root/command-stubs/list-harddrives-stub
blob: ac215a9ffeacf0c97f1a869c02b157641864d6a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
#
# scan system for harddrives and output device name/size
#

import os
import sys

# for testing
if (os.path.exists('isys')):
    sys.path.append('isys')

sys.path.append('/usr/lib/anaconda')

import anaconda_log
import parted
import partedUtils
import isys

drives = isys.hardDriveDict()

driveList = drives.keys()
driveList.sort()
for drive in driveList:

    if isys.driveIsRemovable(drive):
	continue

    # try to open and get size
    skip = 0
    deviceFile =  "/tmp/%s" % (drive,)
    isys.makeDevInode(drive, deviceFile)
    try:
	dev = parted.PedDevice.get(deviceFile)
    except:
	skip = 1
    os.remove(deviceFile)

    if skip:
	continue

    sizeMB = (float(dev.heads * dev.cylinders * dev.sectors) / (1024 * 1024)
		            * dev.sector_size)
	
    print drive, sizeMB