# Diff of /trunk/src/GLIStorageDevice.py

Revision 231 Revision 313
74 return self._device 74 return self._device
75 75
76 def clear_partitions(self): 76 def clear_partitions(self):
77 self._partitions = {} 77 self._partitions = {}
78 78
79 def add_partition(self, minor, start, end, type): 79 def add_partition(self, minor, start, end, type, mountpoint='', mountopts=''):
80 free_start, free_end = self.get_free_space(start) 80 free_start, free_end = self.get_free_space(start)
81 minor = int(minor) 81 minor = int(minor)
82 if not free_end: 82 if not free_end:
83 return False 83 return False
84 if self._partitions.has_key(minor): 84 if self._partitions.has_key(minor):
97 if (i >= hole_at) and (hole_at): continue 97 if (i >= hole_at) and (hole_at): continue
98 if i >= minor: 98 if i >= minor:
99 self._partitions[i].set_minor(i+1) 99 self._partitions[i].set_minor(i+1)
100 self._partitions[i+1] = self._partitions[i] 100 self._partitions[i+1] = self._partitions[i]
101 if i == minor: stopscooting = 1 101 if i == minor: stopscooting = 1
102 self._partitions[minor] = Partition(self, minor, '', start, end, 0, type) 102 self._partitions[minor] = Partition(self, minor, '', start, end, 0, type, mountpoint=mountpoint, mountopts=mountopts)
103 103
104 def remove_partition(self, minor): 104 def remove_partition(self, minor):
105 del self._partitions[int(minor)] 105 del self._partitions[int(minor)]
106 106
107 def get_free_space(self, start): 107 def get_free_space(self, start):
213 213
214 def get_install_profile_structure(self): 214 def get_install_profile_structure(self):
215 devdic = {} 215 devdic = {}
216 for part in self._partitions: 216 for part in self._partitions:
217 tmppart = self._partitions[part] 217 tmppart = self._partitions[part]
218 devdic[part] = { 'mb': 0, 'start': tmppart.get_start(), 'end': tmppart.get_end(), 'type': tmppart.get_type(), 'mountpoint': tmppart.get_mountpoint(), 'mountopts': tmppart.get_mountopts(), 'format': tmppart.get_format() } 218 devdic[part] = { 'mb': 0, 'minor': int(part), 'start': tmppart.get_start(), 'end': tmppart.get_end(), 'type': tmppart.get_type(), 'mountpoint': tmppart.get_mountpoint(), 'mountopts': tmppart.get_mountopts(), 'format': tmppart.get_format() }
219 return devdic 219 return devdic
220 220
221 def get_extended_partition(self): 221 def get_extended_partition(self):
222 for part in self._partitions: 222 for part in self._partitions:
223 tmppart = self._partitions[part] 223 tmppart = self._partitions[part]
313 if type == "ntfs": 313 if type == "ntfs":
314 min_bytes = int(commands.getoutput("ntfsresize -f --info " + device._device + str(minor) + " | grep -e '^You might resize' | sed -e 's/You might resize at //' -e 's/ bytes or .\+//'")) 314 min_bytes = int(commands.getoutput("ntfsresize -f --info " + device._device + str(minor) + " | grep -e '^You might resize' | sed -e 's/You might resize at //' -e 's/ bytes or .\+//'"))
315 self._min_cylinders_for_resize = int(min_bytes / self._device._cylinder_bytes) + 1 315 self._min_cylinders_for_resize = int(min_bytes / self._device._cylinder_bytes) + 1
316 self._resizeable == True 316 self._resizeable == True
317 elif type == "ext2" or type == "ext3": 317 elif type == "ext2" or type == "ext3":
318 block_size = string.strip(commands.getoutput("dumpe2fs -h " + device._device + str(minor) + " 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'")) 318 block_size = string.strip(commands.getoutput("dumpe2fs -h " + device._device + str(minor) + r" 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'"))
319 free_blocks = string.strip(commands.getoutput("dumpe2fs -h " + device._device + str(minor) + " 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'")) 319 free_blocks = string.strip(commands.getoutput("dumpe2fs -h " + device._device + str(minor) + r" 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'"))
320 free_sec = int(int(block_size) * int(free_blocks) / self._device._sector_bytes) 320 free_sec = int(int(block_size) * int(free_blocks) / self._device._sector_bytes)
321 free_sec = free_sec - 2000 # just to be safe 321 free_sec = free_sec - 2000 # just to be safe
322 self._min_sectors_for_resize = (self._end - self._start + 1) - free_sec 322 self._min_sectors_for_resize = (self._end - self._start + 1) - free_sec
323 self._resizeable == True 323 self._resizeable == True
324 else: 324 else:
325 parted_part = self._device._parted_disk.get_partition(self._minor) 325 parted_part = self._device._parted_disk.get_partition(self._minor)
326 try:
326 parted_fs = parted_part.geom.file_system_open() 327 parted_fs = parted_part.geom.file_system_open()
328 except:
329 self._resizeable = False
330 return
327 resize_constraint = parted_fs.get_resize_constraint() 331 resize_constraint = parted_fs.get_resize_constraint()
328 min_size = resize_constraint.min_size 332 min_size = resize_constraint.min_size
329 if int(min_size) != min_size: min_size = int(min_size) + 1 333 if int(min_size) != min_size: min_size = int(min_size) + 1
330 self._min_sectors_for_resize = min_size 334 self._min_sectors_for_resize = min_size
331 self._resizeable = True 335 self._resizeable = True
332# elif type == "":
333# self._min_cylinders_for_resize = 1
334# self._resizeable = True
335# else:
336# self._resizeable = True
337 336
338 def is_extended(self): 337 def is_extended(self):
339 if self._type == "extended": 338 if self._type == "extended":
340 return True 339 return True
341 else: 340 else:
350 def get_logicals(self): 349 def get_logicals(self):
351 if not self.is_extended(): 350 if not self.is_extended():
352 return None 351 return None
353 logicals = [] 352 logicals = []
354 start = self._start 353 start = self._start
355# while not start > self._end:
356# part = self._device.get_partition_at(start)
357# print "part=" + str(part)
358# if not part: break
359# logicals.append(part)
360# start = self._device._partitions[part].get_end() + 1
361 parts = self._device._partitions.keys() 354 parts = self._device._partitions.keys()
362 parts.sort() 355 parts.sort()
363 for part in parts: 356 for part in parts:
364 if part < 5: continue 357 if part < 5: continue
365 logicals.append(part) 358 logicals.append(part)
425 def get_min_sectors_for_resize(self): 418 def get_min_sectors_for_resize(self):
426 if self.is_extended(): 419 if self.is_extended():
427 min_size = self._start 420 min_size = self._start
428 for part in self._device._partitions: 421 for part in self._device._partitions:
429 if part < 5: continue 422 if part < 5: continue
430 min_size = part.get_end() 423 if part.get_end > min_size: min_size = part.get_end()
431 return min_size 424 return min_size
432 else: 425 else:
433 return self._min_sectors_for_resize 426 return self._min_sectors_for_resize
434 427
435 def get_max_sectors_for_resize(self): 428 def get_max_sectors_for_resize(self):
436 free_start, free_end = self._device.get_free_space(self._end) 429 free_start, free_end = self._device.get_free_space(self._end)
437 if free_end == -1: return self._end 430 if free_end == -1: return self._end
438 if free_start - 1 == self._end: 431 if free_start - 1 == self._end:
439 if self.is_logical(): 432 if self.is_logical():
440 if free_end <= self._device._partitions[self.get_extended_parent()]._end: 433 if free_end <= self._device._partitions[self.get_extended_parent()]._end:
441 return free_end 434 return free_end - self._start
442 else: 435 else:
443 return self._end 436 return self._end - self._start
444 else: 437 else:
445 return free_end 438 return free_end - self._start
446 439
447 def resize(self, start, end): 440 def resize(self, start, end):
448 part_at_start = self._device.get_partition_at(int(start)) 441 part_at_start = self._device.get_partition_at(int(start))
449 part_at_end = self._device.get_partition_at(int(end)) 442 part_at_end = self._device.get_partition_at(int(end))
450 logicals = None 443 logicals = None

Legend:
 Removed from v.231 changed lines Added in v.313