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

Diff of /trunk/src/GLIStorageDevice.py

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

Revision 595 Revision 596
32 32
33 ## 33 ##
34 # Initialization function for GLIStorageDevice class 34 # Initialization function for GLIStorageDevice class
35 # @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
36 # @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 def __init__(self, device, arch="x86"): 37 def __init__(self, device, arch="x86", set_geometry=True):
38 self._device = device 38 self._device = device
39 self._partitions = {} 39 self._partitions = {}
40 self._geometry = {'cylinders': 0, 'heads': 0, 'sectors': 0, 'sectorsize': 512} 40 self._geometry = {'cylinders': 0, 'heads': 0, 'sectors': 0, 'sectorsize': 512}
41 self._total_bytes = 0 41 self._total_bytes = 0
42 self._cylinder_bytes = 0 42 self._cylinder_bytes = 0
45 try: 45 try:
46 self._parted_disk = parted.PedDisk.new(self._parted_dev) 46 self._parted_disk = parted.PedDisk.new(self._parted_dev)
47 except: 47 except:
48 self._parted_disk = self._parted_dev.disk_new_fresh(parted.disk_type_get(archinfo[self._arch]['disklabel'])) 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 49 self._disklabel = self._parted_disk.type.name
50 if set_geometry:
50 self.set_disk_geometry_from_disk() 51 self.set_disk_geometry_from_disk()
51 52
52 ## 53 ##
53 # Sets disk geometry info from disk. This function is used internally by __init__() 54 # Sets disk geometry info from disk. This function is used internally by __init__()
54 def set_disk_geometry_from_disk(self): 55 def set_disk_geometry_from_disk(self):
55 self._total_bytes = self._parted_dev.length * self._parted_dev.sector_size 56 self._total_bytes = self._parted_dev.length * self._parted_dev.sector_size
89 90
90 ## 91 ##
91 # Imports partition info from the install profile partition structure (currently does nothing) 92 # Imports partition info from the install profile partition structure (currently does nothing)
92 # @param ips Parameter structure returned from install_profile.get_partition_tables() 93 # @param ips Parameter structure returned from install_profile.get_partition_tables()
93 def set_partitions_from_install_profile_structure(self, ips): 94 def set_partitions_from_install_profile_structure(self, ips):
94 pass
95# for part in ips: 95 for part in ips:
96# tmppart = ips[part] 96 tmppart = ips[part]
97# existing = False 97 existing = False
98# parted_part = self._parted_disk.get_partition(part) 98 if tmppart['origminor'] and not tmppart['format']:
99# if parted_part != None:
100# start = parted_part.geom.start / self._sectors_in_cylinder
101# end = parted_part.geom.end / self._sectors_in_cylinder
102# fs_type = ""
103# if parted_part.fs_type != None: fs_type = parted_part.fs_type.name
104# if parted_part.type == 2: fs_type = "extended"
105# if int(tmppart['start']) == int(start) and int(tmppart['end']) == int(end) and tmppart['type'] == fs_type and tmppart['format'] == False:
106# existing = True 99 existing = True
107# self._partitions[int(part)] = Partition(self, part, '', tmppart['start'], tmppart['end'], 0, tmppart['type'], mountopts=tmppart['mountopts'], mountpoint=tmppart['mountpoint'], format=tmppart['format'], existing=(not tmppart['format'])) 100 self._partitions[tmppart['minor']] = Partition(self, tmppart['minor'], tmppart['mb'], tmppart['start'], tmppart['end'], tmppart['type'], format=tmppart['format'], origminor=tmppart['origminor'], existing=existing, mountpoint=tmppart['mountpoint'], mountopts=['mountopts'])
108 101
109 ## 102 ##
110 # Returns name of device (e.g. /dev/hda) being represented 103 # Returns name of device (e.g. /dev/hda) being represented
111 def get_device(self): 104 def get_device(self):
112 return self._device 105 return self._device
353 if tmppart.is_extended(): 346 if tmppart.is_extended():
354 return part 347 return part
355 return 0 348 return 0
356 349
357 ## 350 ##
351 # Sets the disklabel type
352 def set_disklabel(self, disklabel):
353 self._disklabel = disklabel
354
355 ##
356 # Returns the disklabel type
357 def get_disklabel(self):
358 return self._disklabel
359
360 ##
358 # Returns the number of sectors on the device 361 # Returns the number of sectors on the device
359 def get_num_sectors(self): 362 def get_num_sectors(self):
360 return int(self._total_sectors) 363 return int(self._total_sectors)
361 364
362 ## 365 ##
448 # @param type Parameter Type of partition (ext2, ext3, fat32, linux-swap, free, extended, etc.) 451 # @param type Parameter Type of partition (ext2, ext3, fat32, linux-swap, free, extended, etc.)
449 # @param mountpoint='' Mountpoint of partition 452 # @param mountpoint='' Mountpoint of partition
450 # @param mountopts='' Mount options of partition 453 # @param mountopts='' Mount options of partition
451 # @param format=True Format partition 454 # @param format=True Format partition
452 # @param existing=False This partition exists on disk 455 # @param existing=False This partition exists on disk
453 def __init__(self, device, minor, mb, start, end, type, mountpoint='', mountopts='', format=True, existing=False): 456 def __init__(self, device, minor, mb, start, end, type, mountpoint='', mountopts='', format=True, existing=False, origminor=0):
454 self._device = device 457 self._device = device
455 self._minor = float(minor) 458 self._minor = float(minor)
456 if existing: self._orig_minor = int(minor)
457 self._start = int(start) 459 self._start = int(start)
458 self._end = int(end) 460 self._end = int(end)
459 self._type = type or "unknown" 461 self._type = type or "unknown"
460 self._mountpoint = mountpoint 462 self._mountpoint = mountpoint
461 self._mountopts = mountopts 463 self._mountopts = mountopts
462 self._format = format 464 self._format = format
463 self._mb = mb 465 self._mb = mb
466 self._orig_minor = origminor
467 if type != "free":
468 if existing and not origminor:
469 self._orig_minor = self._minor
470 self._minor = int(self._minor)
471 self._orig_minor = int(self._orig_minor)
464 if existing: 472 if existing:
465 self._orig_minor = self._minor
466 parted_part = device._parted_disk.get_partition(minor) 473 parted_part = device._parted_disk.get_partition(self._orig_minor)
467 label_type = device._parted_disk.type.name 474 label_type = device._parted_disk.type.name
468 if label_type == "loop": 475 if label_type == "loop":
469 dev_node = device._device 476 dev_node = device._device
470 else: 477 else:
471 dev_node = device._device + str(minor) 478 dev_node = device._device + str(self._orig_minor)
479 print "dev_node = " + dev_node
472 if type == "ntfs": 480 if type == "ntfs":
473 min_bytes = int(commands.getoutput("ntfsresize -f --info " + dev_node + " | grep -e '^You might resize' | sed -e 's/You might resize at //' -e 's/ bytes or .\+//'")) 481 min_bytes = int(commands.getoutput("ntfsresize -f --info " + dev_node + " | grep -e '^You might resize' | sed -e 's/You might resize at //' -e 's/ bytes or .\+//'"))
474 self._min_mb_for_resize = int(min_bytes / MEGABYTE) + 1 482 self._min_mb_for_resize = int(min_bytes / MEGABYTE) + 1
475 self._resizeable = True 483 self._resizeable = True
476 elif type == "ext2" or type == "ext3": 484 elif type == "ext2" or type == "ext3":
479 free_bytes = int(block_size * free_blocks) 487 free_bytes = int(block_size * free_blocks)
480 # can't hurt to pad (the +50) it a bit since this is really just a guess 488 # can't hurt to pad (the +50) it a bit since this is really just a guess
481 self._min_mb_for_resize = self._mb - int(free_bytes / MEGABYTE) + 50 489 self._min_mb_for_resize = self._mb - int(free_bytes / MEGABYTE) + 50
482 self._resizeable = True 490 self._resizeable = True
483 else: 491 else:
484 parted_part = self._device._parted_disk.get_partition(int(self._minor)) 492 parted_part = self._device._parted_disk.get_partition(int(self._orig_minor))
485 try: 493 try:
486 parted_fs = parted_part.geom.file_system_open() 494 parted_fs = parted_part.geom.file_system_open()
487 except: 495 except:
488 self._resizeable = False 496 self._resizeable = False
489 return 497 return

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

  ViewVC Help
Powered by ViewVC 1.1.20