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

Diff of /trunk/src/GLIStorageDevice.py

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

Revision 634 Revision 635
57 self._geometry['heads'], self._geometry['sectors'], self._geometry['cylinders'] = self._parted_dev.heads, self._parted_dev.sectors, self._parted_dev.cylinders 57 self._geometry['heads'], self._geometry['sectors'], self._geometry['cylinders'] = self._parted_dev.heads, self._parted_dev.sectors, self._parted_dev.cylinders
58 self._sector_bytes = self._parted_dev.sector_size 58 self._sector_bytes = self._parted_dev.sector_size
59 self._cylinder_bytes = self._geometry['heads'] * self._geometry['sectors'] * self._sector_bytes 59 self._cylinder_bytes = self._geometry['heads'] * self._geometry['sectors'] * self._sector_bytes
60 self._total_sectors = self._parted_dev.length 60 self._total_sectors = self._parted_dev.length
61 self._sectors_in_cylinder = self._geometry['heads'] * self._geometry['sectors'] 61 self._sectors_in_cylinder = self._geometry['heads'] * self._geometry['sectors']
62 self._total_mb = int(self._total_bytes / MEGABYTE) 62 self._total_mb = long(self._total_bytes / MEGABYTE)
63 63
64 ## 64 ##
65 # Sets partition info from disk. 65 # Sets partition info from disk.
66 def set_partitions_from_disk(self): 66 def set_partitions_from_disk(self):
67 last_part = 0 67 last_part = 0
68 last_log_part = 4 68 last_log_part = 4
69 parted_part = self._parted_disk.next_partition() 69 parted_part = self._parted_disk.next_partition()
70 while parted_part: 70 while parted_part:
71 part_mb = int((parted_part.geom.end - parted_part.geom.start + 1) * self._sector_bytes / MEGABYTE) 71 part_mb = long((parted_part.geom.end - parted_part.geom.start + 1) * self._sector_bytes / MEGABYTE)
72 if parted_part.num >= 1: 72 if parted_part.num >= 1:
73 fs_type = "" 73 fs_type = ""
74 if parted_part.fs_type != None: fs_type = parted_part.fs_type.name 74 if parted_part.fs_type != None: fs_type = parted_part.fs_type.name
75 if parted_part.type == 2: fs_type = "extended" 75 if parted_part.type == 2: fs_type = "extended"
76 if archinfo[self._arch]['extended'] and parted_part.num > 4: 76 if archinfo[self._arch]['extended'] and parted_part.num > 4:
168 # @param start Start sector (only used for existing partitions) 168 # @param start Start sector (only used for existing partitions)
169 # @param end End sector (only used for existing partitions) 169 # @param end End sector (only used for existing partitions)
170 # @param type Partition type (ext2, ext3, fat32, linux-swap, free, extended, etc.) 170 # @param type Partition type (ext2, ext3, fat32, linux-swap, free, extended, etc.)
171 # @param mountpoint='' Partition mountpoint 171 # @param mountpoint='' Partition mountpoint
172 # @param mountopts='' Partition mount options 172 # @param mountopts='' Partition mount options
173 # @param mkfsopts='' Additional mkfs options
173 def add_partition(self, free_minor, mb, start, end, type, mountpoint='', mountopts=''): 174 def add_partition(self, free_minor, mb, start, end, type, mountpoint='', mountopts='',mkfsopts=''):
174 new_minor = int(free_minor) + 1 175 new_minor = int(free_minor) + 1
175 if self._partitions.has_key(new_minor): 176 if self._partitions.has_key(new_minor):
176 parts = self._partitions.keys() 177 parts = self._partitions.keys()
177 parts.sort() 178 parts.sort()
178 parts.reverse() 179 parts.reverse()
199 free_minor = new_minor + 0.1 200 free_minor = new_minor + 0.1
200 self._partitions[free_minor] = Partition(self, free_minor, old_free_mb-mb, 0, 0, "free") 201 self._partitions[free_minor] = Partition(self, free_minor, old_free_mb-mb, 0, 0, "free")
201# print "add_partition(): new part doesn't use all freespace. new free part is: minor=" + str(free_minor) 202# print "add_partition(): new part doesn't use all freespace. new free part is: minor=" + str(free_minor)
202 else: 203 else:
203 del self._partitions[free_minor] 204 del self._partitions[free_minor]
204 self._partitions[new_minor] = Partition(self, new_minor, mb, start, end, type, mountpoint=mountpoint, mountopts=mountopts) 205 self._partitions[new_minor] = Partition(self, new_minor, mb, start, end, type, mountpoint=mountpoint, mountopts=mountopts,mkfsopts=mkfsopts)
205 if type == "extended": 206 if type == "extended":
206 self._partitions[4.9] = Partition(self, 4.9, mb, 0, 0, "free") 207 self._partitions[4.9] = Partition(self, 4.9, mb, 0, 0, "free")
207 self.tidy_partitions() 208 self.tidy_partitions()
208 209
209 ## 210 ##
327 # Returns partition info in a format suitable for passing to install_profile.set_partition_tables() 328 # Returns partition info in a format suitable for passing to install_profile.set_partition_tables()
328 def get_install_profile_structure(self): 329 def get_install_profile_structure(self):
329 devdic = {} 330 devdic = {}
330 for part in self._partitions: 331 for part in self._partitions:
331 tmppart = self._partitions[part] 332 tmppart = self._partitions[part]
332 devdic[part] = { 'mb': tmppart.get_mb(), 'minor': float(part), 'origminor': tmppart.get_orig_minor(), 'type': tmppart.get_type(), 'mountpoint': tmppart.get_mountpoint(), 'mountopts': tmppart.get_mountopts(), 'format': tmppart.get_format(), 'mkfsopts': tmppart.get_mkfsopts() } 333 devdic[part] = { 'mb': tmppart.get_mb(), 'minor': float(part), 'origminor': tmppart.get_orig_minor(), 'type': tmppart.get_type(), 'mountpoint': tmppart.get_mountpoint(), 'mountopts': tmppart.get_mountopts(), 'format': tmppart.get_format(), 'mkfsopts': tmppart.get_mkfsopts(), 'start': 0, 'end': 0 }
333 return devdic 334 return devdic
334 335
335 ## 336 ##
336 # Returns the minor of the extended partition, if any 337 # Returns the minor of the extended partition, if any
337 def get_extended_partition(self): 338 def get_extended_partition(self):
357 return self._disklabel 358 return self._disklabel
358 359
359 ## 360 ##
360 # Returns the number of sectors on the device 361 # Returns the number of sectors on the device
361 def get_num_sectors(self): 362 def get_num_sectors(self):
362 return int(self._total_sectors) 363 return long(self._total_sectors)
363 364
364 ## 365 ##
365 # Returns the size of a cylinder in bytes 366 # Returns the size of a cylinder in bytes
366 def get_cylinder_size(self): 367 def get_cylinder_size(self):
367 return int(self._cylinder_bytes) 368 return long(self._cylinder_bytes)
368 369
369 ## 370 ##
370 # Returns the size of a sector in bytes 371 # Returns the size of a sector in bytes
371 def get_sector_size(self): 372 def get_sector_size(self):
372 return int(self._sector_bytes) 373 return long(self._sector_bytes)
373 374
374 ## 375 ##
375 # Returns the number of cylinders 376 # Returns the number of cylinders
376 def get_num_cylinders(self): 377 def get_num_cylinders(self):
377 return int(self._geometry['cylinders']) 378 return long(self._geometry['cylinders'])
378 379
379 ## 380 ##
380 # Returns the total number of bytes on the device 381 # Returns the total number of bytes on the device
381 def get_drive_bytes(self): 382 def get_drive_bytes(self):
382 return int(self._total_bytes) 383 return long(self._total_bytes)
383 384
384 ## 385 ##
385 # Returns the total number of MB on the device 386 # Returns the total number of MB on the device
386 def get_total_mb(self): 387 def get_total_mb(self):
387 return self._total_mb 388 return self._total_mb
449 # @param start Parameter Start sector of partition 450 # @param start Parameter Start sector of partition
450 # @param end Parameter Start sector of partition 451 # @param end Parameter Start sector of partition
451 # @param type Parameter Type of partition (ext2, ext3, fat32, linux-swap, free, extended, etc.) 452 # @param type Parameter Type of partition (ext2, ext3, fat32, linux-swap, free, extended, etc.)
452 # @param mountpoint='' Mountpoint of partition 453 # @param mountpoint='' Mountpoint of partition
453 # @param mountopts='' Mount options of partition 454 # @param mountopts='' Mount options of partition
455 # @param mkfsopts='' Additional mkfs options
454 # @param format=True Format partition 456 # @param format=True Format partition
455 # @param existing=False This partition exists on disk 457 # @param existing=False This partition exists on disk
456 def __init__(self, device, minor, mb, start, end, type, mountpoint='', mountopts='', format=True, existing=False, origminor=0, mkfsopts=''): 458 def __init__(self, device, minor, mb, start, end, type, mountpoint='', mountopts='', format=True, existing=False, origminor=0, mkfsopts=''):
457 self._device = device 459 self._device = device
458 self._minor = float(minor) 460 self._minor = float(minor)
459 self._start = int(start) 461 self._start = long(start)
460 self._end = int(end) 462 self._end = long(end)
461 self._type = type or "unknown" 463 self._type = type or "unknown"
462 self._mountpoint = mountpoint 464 self._mountpoint = mountpoint
463 self._mountopts = mountopts 465 self._mountopts = mountopts
464 self._format = format 466 self._format = format
465 self._mb = mb 467 self._mb = mb
477 dev_node = device._device 479 dev_node = device._device
478 else: 480 else:
479 dev_node = device._device + str(self._orig_minor) 481 dev_node = device._device + str(self._orig_minor)
480# print "dev_node = " + dev_node 482# print "dev_node = " + dev_node
481 if type == "ntfs": 483 if type == "ntfs":
482 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 .\+//'")) 484 min_bytes = long(commands.getoutput("ntfsresize -f --info " + dev_node + " | grep -e '^You might resize' | sed -e 's/You might resize at //' -e 's/ bytes or .\+//'"))
483 self._min_mb_for_resize = int(min_bytes / MEGABYTE) + 1 485 self._min_mb_for_resize = long(min_bytes / MEGABYTE) + 1
484 self._resizeable = True 486 self._resizeable = True
485 elif type == "ext2" or type == "ext3": 487 elif type == "ext2" or type == "ext3":
486 block_size = int(string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'"))) 488 block_size = long(string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'")))
487 free_blocks = int(string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'"))) 489 free_blocks = long(string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'")))
488 free_bytes = int(block_size * free_blocks) 490 free_bytes = long(block_size * free_blocks)
489 # can't hurt to pad (the +50) it a bit since this is really just a guess 491 # can't hurt to pad (the +50) it a bit since this is really just a guess
490 self._min_mb_for_resize = self._mb - int(free_bytes / MEGABYTE) + 50 492 self._min_mb_for_resize = self._mb - long(free_bytes / MEGABYTE) + 50
491 self._resizeable = True 493 self._resizeable = True
492 else: 494 else:
493 parted_part = self._device._parted_disk.get_partition(int(self._orig_minor)) 495 parted_part = self._device._parted_disk.get_partition(int(self._orig_minor))
494 try: 496 try:
495 parted_fs = parted_part.geom.file_system_open() 497 parted_fs = parted_part.geom.file_system_open()
496 except: 498 except:
497 self._resizeable = False 499 self._resizeable = False
498 return 500 return
499 resize_constraint = parted_fs.get_resize_constraint() 501 resize_constraint = parted_fs.get_resize_constraint()
500 min_bytes = resize_constraint.min_size * self._device._sector_bytes 502 min_bytes = resize_constraint.min_size * self._device._sector_bytes
501 self._min_mb_for_resize = int(min_bytes / MEGABYTE) + 1 503 self._min_mb_for_resize = long(min_bytes / MEGABYTE) + 1
502 self._resizeable = True 504 self._resizeable = True
503 505
504 ## 506 ##
505 # Returns whether or not the partition is extended 507 # Returns whether or not the partition is extended
506 def is_extended(self): 508 def is_extended(self):
557 559
558 ## 560 ##
559 # Sets the start sector for the partition 561 # Sets the start sector for the partition
560 # @param start Start sector 562 # @param start Start sector
561 def set_start(self, start): 563 def set_start(self, start):
562 self._start = int(start) 564 self._start = long(start)
563 565
564 ## 566 ##
565 # Returns the start sector for the partition 567 # Returns the start sector for the partition
566 def get_start(self): 568 def get_start(self):
567 return int(self._start) 569 return long(self._start)
568 570
569 ## 571 ##
570 # Sets the end sector of the partition 572 # Sets the end sector of the partition
571 # @param end End sector 573 # @param end End sector
572 def set_end(self, end): 574 def set_end(self, end):
573 self._end = int(end) 575 self._end = long(end)
574 576
575 ## 577 ##
576 # Returns end sector for the partition 578 # Returns end sector for the partition
577 def get_end(self): 579 def get_end(self):
578 return int(self._end) 580 return long(self._end)
579 581
580 ## 582 ##
581 # Returns size of partition in MB 583 # Returns size of partition in MB
582 def get_mb(self): 584 def get_mb(self):
583 return int(self._mb) 585 return long(self._mb)
584 586
585 ## 587 ##
586 # Sets size of partition in MB 588 # Sets size of partition in MB
587 # @param mb Parameter description 589 # @param mb Parameter description
588 def set_mb(self, mb): 590 def set_mb(self, mb):
589 self._mb = int(mb) 591 self._mb = long(mb)
590 592
591 ## 593 ##
592 # Sets type of partition 594 # Sets type of partition
593 # @param type Parameter description 595 # @param type Parameter description
594 def set_type(self, type): 596 def set_type(self, type):

Legend:
Removed from v.634  
changed lines
  Added in v.635

  ViewVC Help
Powered by ViewVC 1.1.20