#!/usr/bin/env python
# -*- coding: utf-8; Mode: Python; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Copyright (C) 2010 Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import parted

devicelist = parted.getAllDevices()
for device in devicelist:
  print "Dev: %s" % (device.path)
  dev = device
  try:
    disk = parted.Disk(dev)
  except:
    continue
  print "Disk: type=%s" % (disk.type)
  for partition in disk.getPrimaryPartitions():
    print "Pri: %s %s %d(%d) %d(%d)" % (partition.path, partition.fileSystem.type, partition.geometry.start, dev.startCylinderToSector(dev.startSectorToCylinder(partition.geometry.start)), partition.geometry.end, dev.endCylinderToSector(dev.endSectorToCylinder(partition.geometry.end)) )
  extPartition = disk.getExtendedPartition() 
  if (extPartition != None):
    print "Ext: %s" % (extPartition.path)
  for partition in disk.getLogicalPartitions():
    print "Log: %s %s %d(%d) %d(%d)" % (partition.path, partition.fileSystem.type, partition.geometry.start, dev.startCylinderToSector(dev.startSectorToCylinder(partition.geometry.start)), partition.geometry.end, dev.endCylinderToSector(dev.endSectorToCylinder(partition.geometry.end)) )
  for freeSpace in disk.getFreeSpaceRegions():
    print "Free: %d MB" % (freeSpace.getSize())
