summaryrefslogtreecommitdiffstats
path: root/command-stubs/list-harddrives-stub
blob: cd53689f730a1b0cb1c97e8977e85843a86a5783 (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
#!/usr/bin/python
#
# scan system for harddrives and output device name/size
#

import parted
import partedUtils
import isys
import os

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