/[gli]/branches/overhaul/src/Partitioning.py
Gentoo

Diff of /branches/overhaul/src/Partitioning.py

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

Revision 1542 Revision 1543
129 return self._device 129 return self._device
130 130
131 ## 131 ##
132 # Uses magic to apply the recommended partition layout 132 # Uses magic to apply the recommended partition layout
133 def do_recommended(self): 133 def do_recommended(self):
134 free_minor = 0 134 freeidx = -1
135 free_part = None
135 recommended_parts = [ { 'type': "ext2", 'size': 100, 'mountpoint': "/boot" }, 136 recommended_parts = [ { 'type': "ext2", 'size': 100, 'mountpoint': "/boot" },
136 { 'type': "linux-swap", 'size': 512, 'mountpoint': "" }, 137 { 'type': "linux-swap", 'size': 512, 'mountpoint': "" },
137 { 'type': "ext3", 'size': "*", 'mountpoint': "/" } ] 138 { 'type': "ext3", 'size': "*", 'mountpoint': "/" } ]
138 to_create = [] 139 to_create = []
139 physical_memory = int(GLIUtility.spawn(r"free -m | egrep '^Mem:' | sed -e 's/^Mem: \+//' -e 's/ \+.\+$//'", return_output=True)[1].strip()) 140 physical_memory = int(GLIUtility.spawn(r"free -m | egrep '^Mem:' | sed -e 's/^Mem: \+//' -e 's/ \+.\+$//'", return_output=True)[1].strip())
140# parts = self.get_ordered_partition_list() 141# parts = self.get_ordered_partition_list()
141 # Search for concurrent unallocated space >=4GB 142 # Search for concurrent unallocated space >=4GB
142 for part in self._partitions: 143 for idx, part in self._partitions:
143 if part.get_type() == "free" and part.get_mb() >= 4096: 144 if part['type'] == "free" and part['mb'] >= 4096:
144 free_minor = part.get_minor() 145 freeidx = idx
146 free_part = part
145 break 147 break
146 if not free_minor: 148 else:
147 raise GLIException("RecommendedPartitionLayoutError", "notice", "do_recommended", "You do not have atleast 4GB of concurrent unallocated space. Please remove some partitions and try again.") 149 raise GLIException("RecommendedPartitionLayoutError", "notice", "do_recommended", "You do not have atleast 4GB of concurrent unallocated space. Please remove some partitions and try again.")
148 remaining_free = self.get_partition(free_minor).get_mb() 150 remaining_free = free_part['mb']
151 # XXX: I left off here
149 for newpart in recommended_parts: 152 for newpart in recommended_parts:
150 # extended/logical partitions suck like a hoover 153 # extended/logical partitions suck like a hoover
151 if self._labelinfo['extended'] and free_minor == (3 + FREE_MINOR_FRAC_PRI) and not newpart == recommended_parts[-1]: 154 if self._labelinfo['extended'] and free_minor == (3 + FREE_MINOR_FRAC_PRI) and not newpart == recommended_parts[-1]:
152 if self.get_extended_partition(): 155 if self.get_extended_partition():
153 raise GLIException("RecommendedPartitionLayoutError", "notice", "do_recommended", "This code is not yet robust enough to handle automatic partitioning with your current layout.") 156 raise GLIException("RecommendedPartitionLayoutError", "notice", "do_recommended", "This code is not yet robust enough to handle automatic partitioning with your current layout.")
154 to_create.append({ 'type': "extended", 'size': remaining_free, 'mountpoint': "", 'free_minor': free_minor }) 157 to_create.append({ 'type': "extended", 'size': remaining_free, 'mountpoint': "", 'free_minor': free_minor })
155 free_minor = 4 + FREE_MINOR_FRAC_LOG 158 free_minor = 4 + FREE_MINOR_FRAC_LOG
156 newpart['free_minor'] = free_minor 159 newpart['free_minor'] = free_minor
157 # Small hack to calculate optimal swap partition size 160 # Small hack to calculate optimal swap partition size
158 if newpart['type'] == "linux-swap" and physical_memory and physical_memory < 1024: 161 if newpart['type'] == "linux-swap" and physical_memory:
159 newpart['size'] = physical_memory * 2 162 newpart['size'] = physical_memory * 2
163 if newpart['size'] > 1024:
164 newpart['size'] = 1024
160 to_create.append(newpart) 165 to_create.append(newpart)
161 free_minor = free_minor + 1 166 free_minor = free_minor + 1
162 if not newpart['size'] == "*": 167 if not newpart['size'] == "*":
163 remaining_free = remaining_free - newpart['size'] 168 remaining_free = remaining_free - newpart['size']
164 for newpart in to_create: 169 for newpart in to_create:
256 self._parted_disk.commit() 261 self._parted_disk.commit()
257 self.set_partitions_from_disk() 262 self.set_partitions_from_disk()
258 263
259 ## 264 ##
260 # This function clears the partition table 265 # This function clears the partition table
261 def clear_partitions(self): 266 def clear_partitions(self, disklabel=None):
262 self._parted_disk = self._parted_dev.disk_new_fresh(parted.disk_type_get(archinfo[self._arch])) 267 if not disklabel:
263 self._disklabel = archinfo[self._arch] 268 disklabel = archinfo[self._arch]
269 self._parted_disk = self._parted_dev.disk_new_fresh(parted.disk_type_get(disklabel))
270 self._disklabel = disklabel
264 self._parted_disk.commit() 271 self._parted_disk.commit()
265 self.set_partitions_from_disk() 272 self.set_partitions_from_disk()
266 273
267 ## 274 ##
268 # Returns an ordered list (disk order) of partition minors 275 # Returns an ordered list (disk order) of partition minors
282 289
283 ## 290 ##
284 # Returns the drive model 291 # Returns the drive model
285 def get_model(self): 292 def get_model(self):
286 return self._parted_dev.model 293 return self._parted_dev.model
287
288 ##
289 # Sets the disklabel type
290 def set_disklabel(self, disklabel):
291 self._disklabel = disklabel
292 294
293 ## 295 ##
294 # Returns the disklabel type 296 # Returns the disklabel type
295 def get_disklabel(self): 297 def get_disklabel(self):
296 return self._disklabel 298 return self._disklabel
318 # @param parted_part parted.Partition object 320 # @param parted_part parted.Partition object
319 def __init__(self, device, parted_part): 321 def __init__(self, device, parted_part):
320 self._device = device 322 self._device = device
321 self._start = parted_part.geom.start 323 self._start = parted_part.geom.start
322 self._end = parted_part.geom.end 324 self._end = parted_part.geom.end
323 self._fs_type = "" 325 self._type = ""
324 self._minor = parted_part.minor 326 self._minor = parted_part.minor
325 self._part_mb = float((self._end - self._start + 1) * device._geometry['sector_bytes'] / MEGABYTE) 327 self._part_mb = float((self._end - self._start + 1) * device._geometry['sector_bytes'] / MEGABYTE)
326 self._part_name = "" 328 self._part_name = ""
327 self._resizeable = False 329 self._resizeable = False
328 330
334 elif device[-1] in "0123456789": 336 elif device[-1] in "0123456789":
335 self._devnode = tmpdevice + "p" + str(self._minor) 337 self._devnode = tmpdevice + "p" + str(self._minor)
336 else: 338 else:
337 self._devnode = tmpdevice + str(self._minor) 339 self._devnode = tmpdevice + str(self._minor)
338 340
339 if not parted_part.type_name in ("free", "extended"): 341 if not parted_part.type_name == "free":
340 if parted_part.fs_type: 342 if parted_part.fs_type:
341 self._fs_type = parted_part.fs_type.name 343 self._type = parted_part.fs_type.name
342 if self._fs_type == "hfs" and parted_part.is_flag_available(1) and parted_part.get_flag(1): 344 if self._type == "hfs" and parted_part.is_flag_available(1) and parted_part.get_flag(1):
343 self._fs_type = "apple_bootstrap" 345 self._type = "apple_bootstrap"
344 else: 346 else:
345 # Add additional partition identification code here 347 # Add additional partition identification code here
346 pass 348 pass
347 if parted_part.type == 2: self._fs_type = "extended" 349 if parted_part.type == 2: self._type = "extended"
348 if device._parted_disk.type.check_feature(parted.DISK_TYPE_PARTITION_NAME): 350 if device._parted_disk.type.check_feature(parted.DISK_TYPE_PARTITION_NAME):
349 self._part_name = parted_part.get_name() 351 self._part_name = parted_part.get_name()
350 elif parted_part.type_name == "extended":
351 self._fs_type = "extended"
352 352
353 # The 10 is completely arbitrary. If flags seem to be missed, this number should be increased 353 # The 10 is completely arbitrary. If flags seem to be missed, this number should be increased
354 for flag in range(0, 10): 354 for flag in range(0, 10):
355 if parted_part.is_flag_available(flag) and parted_part.get_flag(flag): 355 if parted_part.is_flag_available(flag) and parted_part.get_flag(flag):
356 self._flags.append(flag) 356 self._flags.append(flag)
407 return self._devnode 407 return self._devnode
408 408
409 ## 409 ##
410 # Returns whether or not the partition is extended 410 # Returns whether or not the partition is extended
411 def is_extended(self): 411 def is_extended(self):
412 if self._fs_type == "extended": 412 if self._type == "extended":
413 return True 413 return True
414 else: 414 else:
415 return False 415 return False
416 416
417 ## 417 ##
418 # Returns whether or not the partition is logical 418 # Returns whether or not the partition is logical
419 def is_logical(self): 419 def is_logical(self):
420 if self._fs_type == "free": 420 if self._type == "free":
421 if int(self._minor) + FREE_MINOR_FRAC_LOG == self._minor: 421 if int(self._minor) + FREE_MINOR_FRAC_LOG == self._minor:
422 return True 422 return True
423 else: 423 else:
424 return False 424 return False
425 elif self._device._labelinfo['extended'] and self._minor > 4: 425 elif self._device._labelinfo['extended'] and self._minor > 4:
454 return self._mb 454 return self._mb
455 455
456 ## 456 ##
457 # Returns type of partition 457 # Returns type of partition
458 def get_type(self): 458 def get_type(self):
459 return self._fs_type 459 return self._type
460 460
461 ## 461 ##
462 # Returns parent GLIStorageDevice object 462 # Returns parent GLIStorageDevice object
463 def get_device(self): 463 def get_device(self):
464 return self._device 464 return self._device

Legend:
Removed from v.1542  
changed lines
  Added in v.1543

  ViewVC Help
Powered by ViewVC 1.1.20