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

Diff of /trunk/src/GLIStorageDevice.py

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

Revision 596 Revision 631
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 if tmppart['origminor'] and not tmppart['format']: 98 if tmppart['origminor'] and not tmppart['format']:
99 existing = True 99 existing = True
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']) 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=tmppart['mountopts'])
101 101
102 ## 102 ##
103 # Returns name of device (e.g. /dev/hda) being represented 103 # Returns name of device (e.g. /dev/hda) being represented
104 def get_device(self): 104 def get_device(self):
105 return self._device 105 return self._device
126 del self._partitions[part_log] 126 del self._partitions[part_log]
127 else: 127 else:
128 if not last_log_free: 128 if not last_log_free:
129 last_log_free = last_log_minor + 0.9 129 last_log_free = last_log_minor + 0.9
130 else: 130 else:
131 lost_log_free = part_log 131 last_log_free = part_log
132 tmppart_log.set_minor(last_log_free) 132 tmppart_log.set_minor(last_log_free)
133 self._partitions[last_log_free] = tmppart_log 133 self._partitions[last_log_free] = tmppart_log
134 if part_log != last_log_free: del self._partitions[part_log] 134 if part_log != last_log_free: del self._partitions[part_log]
135 continue
136 else: 135 else:
137 if part_log > (last_log_minor + 1): 136 if part_log > (last_log_minor + 1):
138 tmppart_log.set_minor(last_log_minor + 1) 137 tmppart_log.set_minor(last_log_minor + 1)
139 last_log_minor = last_log_minor + 1 138 last_log_minor = last_log_minor + 1
140 self._partitions[last_log_minor] = tmppart_log 139 self._partitions[last_log_minor] = tmppart_log
141 del self._partitions[part_log] 140 del self._partitions[part_log]
142 continue
143 else: 141 else:
144 last_log_minor = part_log 142 last_log_minor = part_log
145 if tmppart.get_type() == "free": 143 elif tmppart.get_type() == "free":
146 if last_minor < last_free: 144 if last_minor < last_free:
147 self._partitions[last_free].set_mb(self._partitions[last_free].get_mb()+tmppart.get_mb()) 145 self._partitions[last_free].set_mb(self._partitions[last_free].get_mb()+tmppart.get_mb())
148 del self._partitions[part] 146 del self._partitions[part]
149 else: 147 else:
150 if not last_free: 148 if not last_free:
152 else: 150 else:
153 last_free = part 151 last_free = part
154 tmppart.set_minor(last_free) 152 tmppart.set_minor(last_free)
155 self._partitions[last_free] = tmppart 153 self._partitions[last_free] = tmppart
156 if part != last_free: del self._partitions[part] 154 if part != last_free: del self._partitions[part]
157 continue
158 else: 155 else:
159 if part > (last_minor + 1): 156 if part > (last_minor + 1):
160 tmppart.set_minor(last_minor + 1) 157 tmppart.set_minor(last_minor + 1)
161 last_minor = last_minor + 1 158 last_minor = last_minor + 1
162 self._partitions[last_minor] = tmppart 159 self._partitions[last_minor] = tmppart
163 del self._partitions[part] 160 del self._partitions[part]
164 continue
165 else: 161 else:
166 last_minor = part 162 last_minor = part
167 163
168 ## 164 ##
169 # Adds a new partition to the partition info 165 # Adds a new partition to the partition info
173 # @param end End sector (only used for existing partitions) 169 # @param end End sector (only used for existing partitions)
174 # @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.)
175 # @param mountpoint='' Partition mountpoint 171 # @param mountpoint='' Partition mountpoint
176 # @param mountopts='' Partition mount options 172 # @param mountopts='' Partition mount options
177 def add_partition(self, free_minor, mb, start, end, type, mountpoint='', mountopts=''): 173 def add_partition(self, free_minor, mb, start, end, type, mountpoint='', mountopts=''):
178 free_minor = free_minor
179 new_minor = int(free_minor) + 1 174 new_minor = int(free_minor) + 1
180# print "add_partition(): free_minor=" + str(free_minor) + ", new_minor=" + str(new_minor)
181 if self._partitions.has_key(new_minor): 175 if self._partitions.has_key(new_minor):
182 parts = self._partitions.keys() 176 parts = self._partitions.keys()
183 parts.sort() 177 parts.sort()
184 parts.reverse() 178 parts.reverse()
185 hole_at = 0 179 hole_at = 0
313 return minor 307 return minor
314 308
315 ## 309 ##
316 # Returns an ordered list (disk order) of partition minors 310 # Returns an ordered list (disk order) of partition minors
317 def get_ordered_partition_list(self): 311 def get_ordered_partition_list(self):
318 parts = self._partitions.keys() 312 parts = self._partitions.keys()
319 parts.sort() 313 parts.sort()
320 partlist = [] 314 partlist = []
321 tmppart = None 315 tmppart = None
322 for part in parts: 316 for part in parts:
323 if archinfo[self._arch]['extended'] and part > 4.1: break 317 if archinfo[self._arch]['extended'] and part > 4.1: break
324 tmppart = self._partitions[part] 318 tmppart = self._partitions[part]
325 partlist.append(part) 319 partlist.append(part)
333 # Returns partition info in a format suitable for passing to install_profile.set_partition_tables() 327 # Returns partition info in a format suitable for passing to install_profile.set_partition_tables()
334 def get_install_profile_structure(self): 328 def get_install_profile_structure(self):
335 devdic = {} 329 devdic = {}
336 for part in self._partitions: 330 for part in self._partitions:
337 tmppart = self._partitions[part] 331 tmppart = self._partitions[part]
338 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() } 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() }
339 return devdic 333 return devdic
340 334
341 ## 335 ##
342 # Returns the minor of the extended partition, if any 336 # Returns the minor of the extended partition, if any
343 def get_extended_partition(self): 337 def get_extended_partition(self):
344 for part in self._partitions: 338 for part in self._partitions:
345 tmppart = self._partitions[part] 339 tmppart = self._partitions[part]
346 if tmppart.is_extended(): 340 if tmppart.is_extended():
347 return part 341 return part
348 return 0 342 return 0
343
344 ##
345 # Returns the drive model
346 def get_model(self):
347 return self._parted_dev.model
349 348
350 ## 349 ##
351 # Sets the disklabel type 350 # Sets the disklabel type
352 def set_disklabel(self, disklabel): 351 def set_disklabel(self, disklabel):
353 self._disklabel = disklabel 352 self._disklabel = disklabel
438 _mountopts = None 437 _mountopts = None
439 _format = None 438 _format = None
440 _resizeable = None 439 _resizeable = None
441 _min_mb_for_resize = 0 440 _min_mb_for_resize = 0
442 _mb = 0 441 _mb = 0
442 _mkfsopts = None
443 443
444 ## 444 ##
445 # Initialization function for the Partition class 445 # Initialization function for the Partition class
446 # @param device Parent GLIStorageDevice object 446 # @param device Parent GLIStorageDevice object
447 # @param minor Minor of partition 447 # @param minor Minor of partition
451 # @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.)
452 # @param mountpoint='' Mountpoint of partition 452 # @param mountpoint='' Mountpoint of partition
453 # @param mountopts='' Mount options of partition 453 # @param mountopts='' Mount options of partition
454 # @param format=True Format partition 454 # @param format=True Format partition
455 # @param existing=False This partition exists on disk 455 # @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): 456 def __init__(self, device, minor, mb, start, end, type, mountpoint='', mountopts='', format=True, existing=False, origminor=0, mkfsopts=''):
457 self._device = device 457 self._device = device
458 self._minor = float(minor) 458 self._minor = float(minor)
459 self._start = int(start) 459 self._start = int(start)
460 self._end = int(end) 460 self._end = int(end)
461 self._type = type or "unknown" 461 self._type = type or "unknown"
462 self._mountpoint = mountpoint 462 self._mountpoint = mountpoint
463 self._mountopts = mountopts 463 self._mountopts = mountopts
464 self._format = format 464 self._format = format
465 self._mb = mb 465 self._mb = mb
466 self._orig_minor = origminor 466 self._orig_minor = origminor
467 self._mkfsopts = mkfsopts
467 if type != "free": 468 if type != "free":
468 if existing and not origminor: 469 if existing and not origminor:
469 self._orig_minor = self._minor 470 self._orig_minor = self._minor
470 self._minor = int(self._minor) 471 self._minor = int(self._minor)
471 self._orig_minor = int(self._orig_minor) 472 self._orig_minor = int(self._orig_minor)
474 label_type = device._parted_disk.type.name 475 label_type = device._parted_disk.type.name
475 if label_type == "loop": 476 if label_type == "loop":
476 dev_node = device._device 477 dev_node = device._device
477 else: 478 else:
478 dev_node = device._device + str(self._orig_minor) 479 dev_node = device._device + str(self._orig_minor)
479 print "dev_node = " + dev_node 480# print "dev_node = " + dev_node
480 if type == "ntfs": 481 if type == "ntfs":
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 .\+//'")) 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 .\+//'"))
482 self._min_mb_for_resize = int(min_bytes / MEGABYTE) + 1 483 self._min_mb_for_resize = int(min_bytes / MEGABYTE) + 1
483 self._resizeable = True 484 self._resizeable = True
484 elif type == "ext2" or type == "ext3": 485 elif type == "ext2" or type == "ext3":
540 def get_extended_parent(self): 541 def get_extended_parent(self):
541 if not self.is_logical(): 542 if not self.is_logical():
542 return None 543 return None
543 else: 544 else:
544 return self._device.get_partition_at(self._start, ignore_extended=0) 545 return self._device.get_partition_at(self._start, ignore_extended=0)
546
547 ##
548 # Sets the options passed to mkfs
549 # @param mkfsopts Options passed to mkfs
550 def set_mkfsopts(self, mkfsopts):
551 self._mkfsopts = mkfsopts
552
553 ##
554 # Returns the options passes to mkfs
555 def get_mkfsopts(self):
556 return self._mkfsopts
545 557
546 ## 558 ##
547 # Sets the start sector for the partition 559 # Sets the start sector for the partition
548 # @param start Start sector 560 # @param start Start sector
549 def set_start(self, start): 561 def set_start(self, start):

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

  ViewVC Help
Powered by ViewVC 1.1.20