/[gli]/trunk/src/GLIStorageDevice.py
Gentoo

Diff of /trunk/src/GLIStorageDevice.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 594 Revision 595
1import commands, string, os, parted 1import commands, string, os, parted
2from GLIException import * 2from GLIException import *
3import GLIUtility
3 4
4MEGABYTE = 1024 * 1024 5MEGABYTE = 1024 * 1024
5 6
6archinfo = { 'sparc': { 'fixedparts': [ { 'minor': 3, 'type': "wholedisk" } ], 'disklabel': 'sun', 'extended': False }, 7archinfo = { 'sparc': { 'fixedparts': [ { 'minor': 3, 'type': "wholedisk" } ], 'disklabel': 'sun', 'extended': False },
7 'hppa': { 'fixedparts': [ { 'minor': 1, 'type': "boot" } ], 'disklabel': 'msdos', 'extended': False }, 8 'hppa': { 'fixedparts': [ { 'minor': 1, 'type': "boot" } ], 'disklabel': 'msdos', 'extended': False },
8 'x86': { 'fixedparts': [], 'disklabel': 'msdos', 'extended': True }, 9 'x86': { 'fixedparts': [], 'disklabel': 'msdos', 'extended': True },
10 'amd64': { 'fixedparts': [], 'disklabel': 'msdos', 'extended': True },
9 'ppc': { 'fixedparts': [ { 'minor': 1, 'type': "metadata" } ], 'disklabel': 'mac', 'extended': False } 11 'ppc': { 'fixedparts': [ { 'minor': 1, 'type': "metadata" } ], 'disklabel': 'mac', 'extended': False }
10 } 12 }
11 13
12## 14##
13# This class provides a partitioning abstraction for the frontends 15# This class provides a partitioning abstraction for the frontends
24 _parted_dev = None 26 _parted_dev = None
25 _parted_disk = None 27 _parted_disk = None
26 _sector_bytes = 0 28 _sector_bytes = 0
27 _total_mb = 0 29 _total_mb = 0
28 _arch = None 30 _arch = None
31 _disklabel = None
29 32
30 ## 33 ##
31 # Initialization function for GLIStorageDevice class 34 # Initialization function for GLIStorageDevice class
32 # @param device Device node (e.g. /dev/hda) of device being represented 35 # @param device Device node (e.g. /dev/hda) of device being represented
33 # @param arch="x86" Architecture that we're partition for (defaults to 'x86' for now) 36 # @param arch="x86" Architecture that we're partition for (defaults to 'x86' for now)
37 self._geometry = {'cylinders': 0, 'heads': 0, 'sectors': 0, 'sectorsize': 512} 40 self._geometry = {'cylinders': 0, 'heads': 0, 'sectors': 0, 'sectorsize': 512}
38 self._total_bytes = 0 41 self._total_bytes = 0
39 self._cylinder_bytes = 0 42 self._cylinder_bytes = 0
40 self._arch = arch 43 self._arch = arch
41 self._parted_dev = parted.PedDevice.get(self._device) 44 self._parted_dev = parted.PedDevice.get(self._device)
45 try:
42 self._parted_disk = parted.PedDisk.new(self._parted_dev) 46 self._parted_disk = parted.PedDisk.new(self._parted_dev)
47 except:
48 self._parted_disk = self._parted_dev.disk_new_fresh(parted.disk_type_get(archinfo[self._arch]['disklabel']))
49 self._disklabel = self._parted_disk.type.name
43 self.set_disk_geometry_from_disk() 50 self.set_disk_geometry_from_disk()
44 51
45 ## 52 ##
46 # Sets disk geometry info from disk. This function is used internally by __init__() 53 # Sets disk geometry info from disk. This function is used internally by __init__()
47 def set_disk_geometry_from_disk(self): 54 def set_disk_geometry_from_disk(self):
768 # that has the same minor and major as our 775 # that has the same minor and major as our
769 # current block device. 776 # current block device.
770 for record in partitions: 777 for record in partitions:
771 if major == record[0] and minor == record[1]: 778 if major == record[0] and minor == record[1]:
772 devices.append(record[2]) 779 devices.append(record[2])
773 780
781 # For testing the partitioning code
782 if GLIUtility.is_file("/tmp/disk.img"):
783 devices.append("/tmp/disk.img")
784
774 # We have assembled the list of devices, so return it 785 # We have assembled the list of devices, so return it
775 return devices 786 return devices

Legend:
Removed from v.594  
changed lines
  Added in v.595

  ViewVC Help
Powered by ViewVC 1.1.20