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

Diff of /trunk/src/GLIStorageDevice.py

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

Revision 514 Revision 523
27 _total_mb = 0 27 _total_mb = 0
28 _arch = None 28 _arch = None
29 29
30 ## 30 ##
31 # Initialization function for GLIStorageDevice class 31 # Initialization function for GLIStorageDevice class
32 # @param self Parameter description
33 # @param device Device node (e.g. /dev/hda) of device being represented 32 # @param device Device node (e.g. /dev/hda) of device being represented
34 # @param arch="x86" Architecture that we're partition for (defaults to 'x86' for now) 33 # @param arch="x86" Architecture that we're partition for (defaults to 'x86' for now)
35 def __init__(self, device, arch="x86"): 34 def __init__(self, device, arch="x86"):
36 self._device = device 35 self._device = device
37 self._partitions = {} 36 self._partitions = {}
43 self._parted_disk = parted.PedDisk.new(self._parted_dev) 42 self._parted_disk = parted.PedDisk.new(self._parted_dev)
44 self.set_disk_geometry_from_disk() 43 self.set_disk_geometry_from_disk()
45 44
46 ## 45 ##
47 # Sets disk geometry info from disk. This function is used internally by __init__() 46 # Sets disk geometry info from disk. This function is used internally by __init__()
48 # @param self Parameter description
49 def set_disk_geometry_from_disk(self): 47 def set_disk_geometry_from_disk(self):
50 self._total_bytes = self._parted_dev.length * self._parted_dev.sector_size 48 self._total_bytes = self._parted_dev.length * self._parted_dev.sector_size
51 self._geometry['heads'], self._geometry['sectors'], self._geometry['cylinders'] = self._parted_dev.heads, self._parted_dev.sectors, self._parted_dev.cylinders 49 self._geometry['heads'], self._geometry['sectors'], self._geometry['cylinders'] = self._parted_dev.heads, self._parted_dev.sectors, self._parted_dev.cylinders
52 self._sector_bytes = self._parted_dev.sector_size 50 self._sector_bytes = self._parted_dev.sector_size
53 self._cylinder_bytes = self._geometry['heads'] * self._geometry['sectors'] * self._sector_bytes 51 self._cylinder_bytes = self._geometry['heads'] * self._geometry['sectors'] * self._sector_bytes
55 self._sectors_in_cylinder = self._geometry['heads'] * self._geometry['sectors'] 53 self._sectors_in_cylinder = self._geometry['heads'] * self._geometry['sectors']
56 self._total_mb = int(self._total_bytes / MEGABYTE) 54 self._total_mb = int(self._total_bytes / MEGABYTE)
57 55
58 ## 56 ##
59 # Sets partition info from disk. 57 # Sets partition info from disk.
60 # @param self Parameter description
61 def set_partitions_from_disk(self): 58 def set_partitions_from_disk(self):
62 last_part = 0 59 last_part = 0
63 last_log_part = 4 60 last_log_part = 4
64 parted_part = self._parted_disk.next_partition() 61 parted_part = self._parted_disk.next_partition()
65 while parted_part: 62 while parted_part:
83 last_part += 1 80 last_part += 1
84 parted_part = self._parted_disk.next_partition(parted_part) 81 parted_part = self._parted_disk.next_partition(parted_part)
85 82
86 ## 83 ##
87 # Imports partition info from the install profile partition structure (currently does nothing) 84 # Imports partition info from the install profile partition structure (currently does nothing)
88 # @param self Parameter description
89 # @param ips Parameter structure returned from install_profile.get_partition_tables() 85 # @param ips Parameter structure returned from install_profile.get_partition_tables()
90 def set_partitions_from_install_profile_structure(self, ips): 86 def set_partitions_from_install_profile_structure(self, ips):
91 pass 87 pass
92# for part in ips: 88# for part in ips:
93# tmppart = ips[part] 89# tmppart = ips[part]
103# existing = True 99# existing = True
104# 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[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']))
105 101
106 ## 102 ##
107 # Returns name of device (e.g. /dev/hda) being represented 103 # Returns name of device (e.g. /dev/hda) being represented
108 # @param self Parameter description
109 def get_device(self): 104 def get_device(self):
110 return self._device 105 return self._device
111 106
112 ## 107 ##
113 # Combines free space and closes gaps in minor numbers. This is used internally 108 # Combines free space and closes gaps in minor numbers. This is used internally
114 # @param self Parameter description
115 def tidy_partitions(self): 109 def tidy_partitions(self):
116 last_minor = 0 110 last_minor = 0
117 last_log_minor = 4 111 last_log_minor = 4
118 last_free = 0 112 last_free = 0
119 last_log_free = 0 113 last_log_free = 0
167 continue 161 continue
168 last_minor = part 162 last_minor = part
169 163
170 ## 164 ##
171 # Adds a new partition to the partition info 165 # Adds a new partition to the partition info
172 # @param self Parameter description
173 # @param free_minor minor of unallocated space partition is being created in 166 # @param free_minor minor of unallocated space partition is being created in
174 # @param mb size of partition in MB 167 # @param mb size of partition in MB
175 # @param start Start sector (only used for existing partitions) 168 # @param start Start sector (only used for existing partitions)
176 # @param end End sector (only used for existing partitions) 169 # @param end End sector (only used for existing partitions)
177 # @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.)
215 self._partitions[Decimal("4.9")] = Partition(self, Decimal("4.9"), mb, 0, 0, "free") 208 self._partitions[Decimal("4.9")] = Partition(self, Decimal("4.9"), mb, 0, 0, "free")
216 self.tidy_partitions() 209 self.tidy_partitions()
217 210
218 ## 211 ##
219 # Removes partition from partition info 212 # Removes partition from partition info
220 # @param self Parameter description
221 # @param minor Minor of partition to remove 213 # @param minor Minor of partition to remove
222 def remove_partition(self, minor): 214 def remove_partition(self, minor):
223 tmppart = self._partitions[int(minor)] 215 tmppart = self._partitions[int(minor)]
224 free_minor = 0 216 free_minor = 0
225 if tmppart.is_logical(): 217 if tmppart.is_logical():
230 del self._partitions[int(minor)] 222 del self._partitions[int(minor)]
231 self.tidy_partitions() 223 self.tidy_partitions()
232 224
233 ## 225 ##
234 # Returns free space (no longer used) 226 # Returns free space (no longer used)
235 # @param self Parameter description
236 # @param start Start sector for search 227 # @param start Start sector for search
237 def get_free_space(self, start): 228 def get_free_space(self, start):
238 GAP_SIZE = 100 229 GAP_SIZE = 100
239 parts = self._partitions.keys() 230 parts = self._partitions.keys()
240 parts.sort() 231 parts.sort()
270 free_end = self._total_sectors 261 free_end = self._total_sectors
271 return (free_start, free_end) 262 return (free_start, free_end)
272 263
273 ## 264 ##
274 # Gets partition containing a certain sector (no longer used) 265 # Gets partition containing a certain sector (no longer used)
275 # @param self Parameter description
276 # @param sector Sector to look at 266 # @param sector Sector to look at
277 # @param ignore_extended=1 Ignore extended partitions 267 # @param ignore_extended=1 Ignore extended partitions
278 def get_partition_at(self, sector, ignore_extended=1): 268 def get_partition_at(self, sector, ignore_extended=1):
279 parts = self._partitions.keys() 269 parts = self._partitions.keys()
280 parts.sort() 270 parts.sort()
285 return part 275 return part
286 return 0 276 return 0
287 277
288 ## 278 ##
289 # Returns free minor (no longer used) 279 # Returns free minor (no longer used)
290 # @param self Parameter description
291 # @param start Parameter description 280 # @param start Parameter description
292 # @param end Parameter description 281 # @param end Parameter description
293 def get_free_minor_at(self, start, end): 282 def get_free_minor_at(self, start, end):
294 parts = self._partitions.keys() 283 parts = self._partitions.keys()
295 parts.sort() 284 parts.sort()
319 lastpart = part 308 lastpart = part
320 return minor 309 return minor
321 310
322 ## 311 ##
323 # Returns an ordered list (disk order) of partition minors 312 # Returns an ordered list (disk order) of partition minors
324 # @param self Parameter description
325 def get_ordered_partition_list(self): 313 def get_ordered_partition_list(self):
326 parts = self._partitions.keys() 314 parts = self._partitions.keys()
327 parts.sort() 315 parts.sort()
328 partlist = [] 316 partlist = []
329 tmppart = None 317 tmppart = None
339 partlist.append(part_log) 327 partlist.append(part_log)
340 return partlist 328 return partlist
341 329
342 ## 330 ##
343 # Returns partition info in a format suitable for passing to install_profile.set_partition_tables() 331 # Returns partition info in a format suitable for passing to install_profile.set_partition_tables()
344 # @param self Parameter description
345 def get_install_profile_structure(self): 332 def get_install_profile_structure(self):
346 devdic = {} 333 devdic = {}
347 for part in self._partitions: 334 for part in self._partitions:
348 tmppart = self._partitions[part] 335 tmppart = self._partitions[part]
349 devdic[part] = { 'mb': tmppart.get_mb(), 'minor': float(part), 'origminor': tmppart.get_orig_minor(), 'start': tmppart.get_start(), 'end': tmppart.get_end(), 'type': tmppart.get_type(), 'mountpoint': tmppart.get_mountpoint(), 'mountopts': tmppart.get_mountopts(), 'format': tmppart.get_format() } 336 devdic[part] = { 'mb': tmppart.get_mb(), 'minor': float(part), 'origminor': tmppart.get_orig_minor(), 'start': tmppart.get_start(), 'end': tmppart.get_end(), 'type': tmppart.get_type(), 'mountpoint': tmppart.get_mountpoint(), 'mountopts': tmppart.get_mountopts(), 'format': tmppart.get_format() }
350 return devdic 337 return devdic
351 338
352 ## 339 ##
353 # Returns the minor of the extended partition, if any 340 # Returns the minor of the extended partition, if any
354 # @param self Parameter description
355 def get_extended_partition(self): 341 def get_extended_partition(self):
356 for part in self._partitions: 342 for part in self._partitions:
357 tmppart = self._partitions[part] 343 tmppart = self._partitions[part]
358 if tmppart.is_extended(): 344 if tmppart.is_extended():
359 return part 345 return part
360 return 0 346 return 0
361 347
362 ## 348 ##
363 # Returns the number of sectors on the device 349 # Returns the number of sectors on the device
364 # @param self Parameter description
365 def get_num_sectors(self): 350 def get_num_sectors(self):
366 return int(self._total_sectors) 351 return int(self._total_sectors)
367 352
368 ## 353 ##
369 # Returns the size of a cylinder in bytes 354 # Returns the size of a cylinder in bytes
370 # @param self Parameter description
371 def get_cylinder_size(self): 355 def get_cylinder_size(self):
372 return int(self._cylinder_bytes) 356 return int(self._cylinder_bytes)
373 357
374 ## 358 ##
375 # Returns the size of a sector in bytes 359 # Returns the size of a sector in bytes
376 # @param self Parameter description
377 def get_sector_size(self): 360 def get_sector_size(self):
378 return int(self._sector_bytes) 361 return int(self._sector_bytes)
379 362
380 ## 363 ##
381 # Returns the number of cylinders 364 # Returns the number of cylinders
382 # @param self Parameter description
383 def get_num_cylinders(self): 365 def get_num_cylinders(self):
384 return int(self._geometry['cylinders']) 366 return int(self._geometry['cylinders'])
385 367
386 ## 368 ##
387 # Returns the total number of bytes on the device 369 # Returns the total number of bytes on the device
388 # @param self Parameter description
389 def get_drive_bytes(self): 370 def get_drive_bytes(self):
390 return int(self._total_bytes) 371 return int(self._total_bytes)
391 372
392 ## 373 ##
393 # Returns the total number of MB on the device 374 # Returns the total number of MB on the device
394 # @param self Parameter description
395 def get_total_mb(self): 375 def get_total_mb(self):
396 return self._total_mb 376 return self._total_mb
397 377
398 ## 378 ##
399 # Returns partition info dictionary 379 # Returns partition info dictionary
400 # @param self Parameter description
401 def get_partitions(self): 380 def get_partitions(self):
402 return self._partitions 381 return self._partitions
403 382
404 ## 383 ##
405 # Prints disk geometry to STDOUT (no longer used) 384 # Prints disk geometry to STDOUT (no longer used)
406 # @param self Parameter description
407 def print_geometry(self): 385 def print_geometry(self):
408 print self._total_bytes, self._geometry 386 print self._total_bytes, self._geometry
409 387
410 ## 388 ##
411 # Utility function for raising an exception 389 # Utility function for raising an exception
412 # @param self Parameter description
413 # @param message Error message 390 # @param message Error message
414 def _error(self, message): 391 def _error(self, message):
415 "Raises an exception" 392 "Raises an exception"
416 raise "DeviceObjectError", message 393 raise "DeviceObjectError", message
417 394
418 ## 395 ##
419 # Utility function for running a command and returning it's output as a list 396 # Utility function for running a command and returning it's output as a list
420 # @param self Parameter description
421 # @param cmd Command to run 397 # @param cmd Command to run
422 def _run(self, cmd): 398 def _run(self, cmd):
423 "Runs a command and returns the output" 399 "Runs a command and returns the output"
424 400
425 # Run command 401 # Run command
455 _type = None 431 _type = None
456 _mountpoint = None 432 _mountpoint = None
457 _mountopts = None 433 _mountopts = None
458 _format = None 434 _format = None
459 _resizeable = None 435 _resizeable = None
460 _min_sectors_for_resize = 0 436 _min_mb_for_resize = 0
461 _mb = 0 437 _mb = 0
462 438
463 ## 439 ##
464 # Initialization function for the Partition class 440 # Initialization function for the Partition class
465 # @param self Parameter description
466 # @param device Parent GLIStorageDevice object 441 # @param device Parent GLIStorageDevice object
467 # @param minor Minor of partition 442 # @param minor Minor of partition
468 # @param mb Parameter Size of partition in MB 443 # @param mb Parameter Size of partition in MB
469 # @param start Parameter Start sector of partition 444 # @param start Parameter Start sector of partition
470 # @param end Parameter Start sector of partition 445 # @param end Parameter Start sector of partition
492 dev_node = device._device 467 dev_node = device._device
493 else: 468 else:
494 dev_node = device._device + str(minor) 469 dev_node = device._device + str(minor)
495 if type == "ntfs": 470 if type == "ntfs":
496 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 .\+//'")) 471 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 .\+//'"))
497 self._min_cylinders_for_resize = int(min_bytes / self._device._cylinder_bytes) + 1 472 self._min_mb_for_resize = int(min_bytes / MEGABYTE) + 1
498 self._resizeable == True 473 self._resizeable == True
499 elif type == "ext2" or type == "ext3": 474 elif type == "ext2" or type == "ext3":
500 block_size = string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'")) 475 block_size = string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'"))
501 free_blocks = string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'")) 476 free_blocks = string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'"))
502 free_sec = int(int(block_size) * int(free_blocks) / self._device._sector_bytes) 477 free_bytes = int(block_size * free_blocks)
503 free_sec = free_sec - 2000 # just to be safe 478 # can't hurt to pad (the +50) it a bit since this is really just a guess
504 self._min_sectors_for_resize = (self._end - self._start + 1) - free_sec 479 self._min_mb_for_resize = self._mb - int(free_bytes / MEGABYTE) + 50
505 self._resizeable == True 480 self._resizeable == True
506 else: 481 else:
507 parted_part = self._device._parted_disk.get_partition(int(self._minor)) 482 parted_part = self._device._parted_disk.get_partition(int(self._minor))
508 try: 483 try:
509 parted_fs = parted_part.geom.file_system_open() 484 parted_fs = parted_part.geom.file_system_open()
510 except: 485 except:
511 self._resizeable = False 486 self._resizeable = False
512 return 487 return
513 resize_constraint = parted_fs.get_resize_constraint() 488 resize_constraint = parted_fs.get_resize_constraint()
514 min_size = resize_constraint.min_size 489 min_bytes = resize_constraint.min_size * self._device._sector_bytes
515 if int(min_size) != min_size: min_size = int(min_size) + 1 490 self._min_mb_for_resize = int(min_bytes / MEGABYTE) + 1
516 self._min_sectors_for_resize = min_size
517 self._resizeable = True 491 self._resizeable = True
518 492
519 ## 493 ##
520 # Returns whether or not the partition is extended 494 # Returns whether or not the partition is extended
521 # @param self Parameter description
522 def is_extended(self): 495 def is_extended(self):
523 if self._type == "extended": 496 if self._type == "extended":
524 return True 497 return True
525 else: 498 else:
526 return False 499 return False
527 500
528 ## 501 ##
529 # Returns whether or not the partition is logical 502 # Returns whether or not the partition is logical
530 # @param self Parameter description
531 def is_logical(self): 503 def is_logical(self):
532 if self._type == "free": 504 if self._type == "free":
533 if int(self._minor) + Decimal("0.9") == Decimal(str(self._minor)): 505 if int(self._minor) + Decimal("0.9") == Decimal(str(self._minor)):
534 return True 506 return True
535 else: 507 else:
539 else: 511 else:
540 return False 512 return False
541 513
542 ## 514 ##
543 # Returns a list of logical partitions if this is an extended partition 515 # Returns a list of logical partitions if this is an extended partition
544 # @param self Parameter description
545 def get_logicals(self): 516 def get_logicals(self):
546 if not self.is_extended(): 517 if not self.is_extended():
547 return None 518 return None
548 logicals = [] 519 logicals = []
549 start = self._start 520 start = self._start
555 logicals.sort() 526 logicals.sort()
556 return logicals 527 return logicals
557 528
558 ## 529 ##
559 # Returns the extened parent partition if this is a logical partition (no longer used) 530 # Returns the extened parent partition if this is a logical partition (no longer used)
560 # @param self Parameter description
561 def get_extended_parent(self): 531 def get_extended_parent(self):
562 if not self.is_logical(): 532 if not self.is_logical():
563 return None 533 return None
564 else: 534 else:
565 return self._device.get_partition_at(self._start, ignore_extended=0) 535 return self._device.get_partition_at(self._start, ignore_extended=0)
566 536
567 ## 537 ##
568 # Sets the start sector for the partition 538 # Sets the start sector for the partition
569 # @param self Parameter description
570 # @param start Start sector 539 # @param start Start sector
571 def set_start(self, start): 540 def set_start(self, start):
572 self._start = int(start) 541 self._start = int(start)
573 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512
574 542
575 ## 543 ##
576 # Returns the start sector for the partition 544 # Returns the start sector for the partition
577 # @param self Parameter description
578 def get_start(self): 545 def get_start(self):
579 return int(self._start) 546 return int(self._start)
580 547
581 ## 548 ##
582 # Sets the end sector of the partition 549 # Sets the end sector of the partition
583 # @param self Parameter description
584 # @param end End sector 550 # @param end End sector
585 def set_end(self, end): 551 def set_end(self, end):
586 self._end = int(end) 552 self._end = int(end)
587 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512
588 553
589 ## 554 ##
590 # Returns end sector for the partition 555 # Returns end sector for the partition
591 # @param self Parameter description
592 def get_end(self): 556 def get_end(self):
593 return int(self._end) 557 return int(self._end)
594 558
595 ## 559 ##
596 # Returns size of partition in MB 560 # Returns size of partition in MB
597 # @param self Parameter description
598 def get_mb(self): 561 def get_mb(self):
599 return int(self._mb) 562 return int(self._mb)
600 563
601 ## 564 ##
602 # Sets size of partition in MB 565 # Sets size of partition in MB
603 # @param self Parameter description
604 # @param mb Parameter description 566 # @param mb Parameter description
605 def set_mb(self, mb): 567 def set_mb(self, mb):
606 self._mb = int(mb) 568 self._mb = int(mb)
607 569
608 ## 570 ##
609 # Sets type of partition 571 # Sets type of partition
610 # @param self Parameter description
611 # @param type Parameter description 572 # @param type Parameter description
612 def set_type(self, type): 573 def set_type(self, type):
613 self._type = type 574 self._type = type
614 575
615 ## 576 ##
616 # Returns type of partition 577 # Returns type of partition
617 # @param self Parameter description
618 def get_type(self): 578 def get_type(self):
619 return self._type 579 return self._type
620 580
621 ## 581 ##
622 # Returns parent GLIStorageDevice object 582 # Returns parent GLIStorageDevice object
623 # @param self Parameter description
624 def get_device(self): 583 def get_device(self):
625 return self._device 584 return self._device
626 585
627 ## 586 ##
628 # Sets minor of partition 587 # Sets minor of partition
629 # @param self Parameter description
630 # @param minor New minor 588 # @param minor New minor
631 def set_minor(self, minor): 589 def set_minor(self, minor):
632 self._minor = float(minor) 590 self._minor = float(minor)
633 591
634 ## 592 ##
635 # Returns minor of partition 593 # Returns minor of partition
636 # @param self Parameter description
637 def get_minor(self): 594 def get_minor(self):
638 return float(self._minor) 595 return float(self._minor)
639 596
640 ## 597 ##
641 # Sets the original minor of the partition 598 # Sets the original minor of the partition
642 # @param self Parameter description
643 # @param orig_minor Parameter description 599 # @param orig_minor Parameter description
644 def set_orig_minor(self, orig_minor): 600 def set_orig_minor(self, orig_minor):
645 self._orig_minor = int(orig_minor) 601 self._orig_minor = int(orig_minor)
646 602
647 ## 603 ##
648 # Returns the original minor of the partition 604 # Returns the original minor of the partition
649 # @param self Parameter description
650 def get_orig_minor(self): 605 def get_orig_minor(self):
651 return self._orig_minor 606 return self._orig_minor
652 607
653 ## 608 ##
654 # Sets the mountpoint for the partition 609 # Sets the mountpoint for the partition
655 # @param self Parameter description
656 # @param mountpoint Mountpoint 610 # @param mountpoint Mountpoint
657 def set_mountpoint(self, mountpoint): 611 def set_mountpoint(self, mountpoint):
658 self._mountpoint = mountpoint 612 self._mountpoint = mountpoint
659 613
660 ## 614 ##
661 # Returns the mountpoint for the partition 615 # Returns the mountpoint for the partition
662 # @param self Parameter description
663 def get_mountpoint(self): 616 def get_mountpoint(self):
664 return self._mountpoint 617 return self._mountpoint
665 618
666 ## 619 ##
667 # Sets the mount options for the partition 620 # Sets the mount options for the partition
668 # @param self Parameter description
669 # @param mountopts Mount options 621 # @param mountopts Mount options
670 def set_mountopts(self, mountopts): 622 def set_mountopts(self, mountopts):
671 self._mountopts = mountopts 623 self._mountopts = mountopts
672 624
673 ## 625 ##
674 # Returns the mount options for the partition 626 # Returns the mount options for the partition
675 # @param self Parameter description
676 def get_mountopts(self): 627 def get_mountopts(self):
677 return self._mountopts 628 return self._mountopts
678 629
679 ## 630 ##
680 # Set whether to format the partition 631 # Set whether to format the partition
681 # @param self Parameter description 632 # @param format Format this partition (True/False)
682 # @param format Parameter description
683 def set_format(self, format): 633 def set_format(self, format):
684 self._format = format 634 self._format = format
685 635
686 ## 636 ##
687 # Returns whether to format the partition 637 # Returns whether to format the partition
688 # @param self Parameter description
689 def get_format(self): 638 def get_format(self):
690 return self._format 639 return self._format
691 640
692 ## 641 ##
642 # Returns whether the partition is resizeable
643 def is_resizeable(self):
644 return self._resizeable
645
646 ##
693 # Returns minimum sectors for resize 647 # Returns minimum MB for resize
694 # @param self Parameter description
695 def get_min_sectors_for_resize(self): 648 def get_min_mb_for_resize(self):
696 if self.is_extended(): 649# if self.is_extended():
697 min_size = self._start 650# min_size = self._start
698 for part in self._device._partitions: 651# for part in self._device._partitions:
699 if part < 5: continue 652# if part < 5: continue
700 if part.get_end > min_size: min_size = part.get_end() 653# if part.get_end > min_size: min_size = part.get_end()
701 return min_size 654# return min_size
655# else:
656 if self._resizeable:
657 return self._min_mb_for_resize
702 else: 658 else:
703 return self._min_sectors_for_resize 659 return -1
704 660
705 ## 661 ##
706 # Returns maximum sectors for resize 662 # Returns maximum MB for resize
707 # @param self Parameter description
708 def get_max_sectors_for_resize(self): 663 def get_max_mb_for_resize(self):
709 free_start, free_end = self._device.get_free_space(self._end) 664 free_minor = 0
710 if free_end == -1: return self._end
711 if free_start - 1 == self._end:
712 if self.is_logical(): 665 if self.is_logical():
713 if free_end <= self._device._partitions[self.get_extended_parent()]._end: 666 free_minor = Decimal(str(self._minor + 0.9))
714 return free_end - self._start
715 else:
716 return self._end - self._start
717 else: 667 else:
718 return free_end - self._start 668 free_minor = Decimal(str(self._minor + 0.1))
669 if free_minor in self._device._partitions:
670 return self._mb + self._device._partitions[free_minor]._mb
671 else:
672 return self._mb
719 673
720 ## 674 ##
721 # Resizes the partition 675 # Resizes the partition (ignore)
722 # @param self Parameter description
723 # @param start New start sector 676 # @param start New start sector
724 # @param end New end sector 677 # @param end New end sector
725 def resize(self, start, end): 678 def resize(self, start, end):
726 part_at_start = self._device.get_partition_at(int(start)) 679 part_at_start = self._device.get_partition_at(int(start))
727 part_at_end = self._device.get_partition_at(int(end)) 680 part_at_end = self._device.get_partition_at(int(end))
745 self.set_end(end) 698 self.set_end(end)
746 return 1 699 return 1
747 700
748 ## 701 ##
749 # Utility function to raise an exception 702 # Utility function to raise an exception
750 # @param self Parameter description
751 # @param message Error message 703 # @param message Error message
752 def _error(self, message): 704 def _error(self, message):
753 "Raises an exception"
754 raise "PartitionObjectError", message 705 raise "PartitionObjectError", message
755 706
756## 707##
757# Returns a list of detected partitionable devices 708# Returns a list of detected partitionable devices
758def detect_devices(): 709def detect_devices():
759 "Returns a list of partitionable devices on the system"
760
761 devices = [] 710 devices = []
762 711
763 # Make sure sysfs exists 712 # Make sure sysfs exists
764 if not os.path.exists("/sys/bus"): 713 if not os.path.exists("/sys/bus"):
765 raise Exception, "no sysfs found (you MUST use a kernel >2.6)" 714 raise Exception, "no sysfs found (you MUST use a kernel >2.6)"

Legend:
Removed from v.514  
changed lines
  Added in v.523

  ViewVC Help
Powered by ViewVC 1.1.20