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

Diff of /trunk/src/GLIStorageDevice.py

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

Revision 529 Revision 530
1import commands, string, re, os, parted 1import commands, string, re, os, parted
2from decimal import Decimal 2#from decimal import Decimal
3 3
4MEGABYTE = 1024 * 1024 4MEGABYTE = 1024 * 1024
5 5
6archinfo = { 'sparc': { 'fixedparts': [ { 'minor': 3, 'type': "wholedisk" } ], 'disklabel': 'sun', 'extended': False }, 6archinfo = { 'sparc': { 'fixedparts': [ { 'minor': 3, 'type': "wholedisk" } ], 'disklabel': 'sun', 'extended': False },
7 'hppa': { 'fixedparts': [ { 'minor': 1, 'type': "boot" } ], 'disklabel': 'msdos', 'extended': False }, 7 'hppa': { 'fixedparts': [ { 'minor': 1, 'type': "boot" } ], 'disklabel': 'msdos', 'extended': False },
71 last_part = parted_part.num 71 last_part = parted_part.num
72 self._partitions[int(parted_part.num)] = Partition(self, parted_part.num, part_mb, parted_part.geom.start, parted_part.geom.end, fs_type, format=False, existing=True) 72 self._partitions[int(parted_part.num)] = Partition(self, parted_part.num, part_mb, parted_part.geom.start, parted_part.geom.end, fs_type, format=False, existing=True)
73 elif parted_part.type_name == "free": 73 elif parted_part.type_name == "free":
74 parent_part = self.get_partition_at(parted_part.geom.start, ignore_extended=0) 74 parent_part = self.get_partition_at(parted_part.geom.start, ignore_extended=0)
75 if parent_part: 75 if parent_part:
76 self._partitions[Decimal(str(float(last_log_part+0.9)))] = Partition(self, Decimal(str(float(last_log_part+0.9))), part_mb, parted_part.geom.start, parted_part.geom.end, "free", format=False, existing=False) 76 self._partitions[last_log_part+0.9] = Partition(self, last_log_part+0.9, part_mb, parted_part.geom.start, parted_part.geom.end, "free", format=False, existing=False)
77 last_log_part += 1 77 last_log_part += 1
78 else: 78 else:
79 self._partitions[Decimal(str(float(last_part+0.1)))] = Partition(self, Decimal(str(float(last_part+0.1))), part_mb, parted_part.geom.start, parted_part.geom.end, "free", format=False, existing=False) 79 self._partitions[last_part+0.1] = Partition(self, last_part+0.1, part_mb, parted_part.geom.start, parted_part.geom.end, "free", format=False, existing=False)
80 last_part += 1 80 last_part += 1
81 parted_part = self._parted_disk.next_partition(parted_part) 81 parted_part = self._parted_disk.next_partition(parted_part)
82 82
83 ## 83 ##
84 # 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)
116 for part in parts: 116 for part in parts:
117 if archinfo[self._arch]['extended'] and part > 4: break 117 if archinfo[self._arch]['extended'] and part > 4: break
118 tmppart = self._partitions[part] 118 tmppart = self._partitions[part]
119 if tmppart.get_type() == "extended": 119 if tmppart.get_type() == "extended":
120 for part_log in parts: 120 for part_log in parts:
121 if part_log < Decimal("4.9"): continue 121 if part_log < 4.9: continue
122 tmppart_log = self._partitions[part_log] 122 tmppart_log = self._partitions[part_log]
123 if tmppart_log.get_type() == "free": 123 if tmppart_log.get_type() == "free":
124 if last_log_minor < last_log_free: 124 if last_log_minor < last_log_free:
125 self._partitions[last_log_free].set_mb(self._partitions[last_log_free].get_mb()+tmppart_log.get_mb()) 125 self._partitions[last_log_free].set_mb(self._partitions[last_log_free].get_mb()+tmppart_log.get_mb())
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 = Decimal(str(last_log_minor + 0.9)) 129 last_log_free = last_log_minor + 0.9
130 tmppart_log.set_minor(last_log_free) 130 tmppart_log.set_minor(last_log_free)
131 self._partitions[last_log_free] = tmppart_log 131 self._partitions[last_log_free] = tmppart_log
132 if part_log != last_log_free: del self._partitions[part_log] 132 if part_log != last_log_free: del self._partitions[part_log]
133 continue 133 continue
134 last_log_free = part_log 134 last_log_free = part_log
144 if last_minor < last_free: 144 if last_minor < last_free:
145 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())
146 del self._partitions[part] 146 del self._partitions[part]
147 else: 147 else:
148 if not last_free: 148 if not last_free:
149 last_free = Decimal(str(last_minor + 0.1)) 149 last_free = last_minor + 0.1
150 tmppart.set_minor(last_free) 150 tmppart.set_minor(last_free)
151 self._partitions[last_free] = tmppart 151 self._partitions[last_free] = tmppart
152 if part != last_free: del self._partitions[part] 152 if part != last_free: del self._partitions[part]
153 continue 153 continue
154 last_free = part 154 last_free = part
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 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=''):
174 free_minor = Decimal(str(free_minor)) 174 free_minor = free_minor
175 new_minor = int(free_minor) + 1 175 new_minor = int(free_minor) + 1
176# print "add_partition(): free_minor=" + str(free_minor) + ", new_minor=" + str(new_minor) 176# print "add_partition(): free_minor=" + str(free_minor) + ", new_minor=" + str(new_minor)
177 if self._partitions.has_key(new_minor): 177 if self._partitions.has_key(new_minor):
178 parts = self._partitions.keys() 178 parts = self._partitions.keys()
179 parts.sort() 179 parts.sort()
194 if i == new_minor: stopscooting = 1 194 if i == new_minor: stopscooting = 1
195 if mb != self._partitions[free_minor].get_mb(): 195 if mb != self._partitions[free_minor].get_mb():
196 old_free_mb = self._partitions[free_minor].get_mb() 196 old_free_mb = self._partitions[free_minor].get_mb()
197 del self._partitions[free_minor] 197 del self._partitions[free_minor]
198 if archinfo[self._arch]['extended'] and new_minor >= 5: 198 if archinfo[self._arch]['extended'] and new_minor >= 5:
199 free_minor = Decimal(str(new_minor + 0.9)) 199 free_minor = new_minor + 0.9
200 else: 200 else:
201 free_minor = Decimal(str(new_minor + 0.1)) 201 free_minor = new_minor + 0.1
202 self._partitions[free_minor] = Partition(self, free_minor, old_free_mb-mb, 0, 0, "free") 202 self._partitions[free_minor] = Partition(self, free_minor, old_free_mb-mb, 0, 0, "free")
203# print "add_partition(): new part doesn't use all freespace. new free part is: minor=" + str(free_minor) 203# print "add_partition(): new part doesn't use all freespace. new free part is: minor=" + str(free_minor)
204 else: 204 else:
205 del self._partitions[free_minor] 205 del self._partitions[free_minor]
206 self._partitions[new_minor] = Partition(self, new_minor, mb, start, end, type, mountpoint=mountpoint, mountopts=mountopts) 206 self._partitions[new_minor] = Partition(self, new_minor, mb, start, end, type, mountpoint=mountpoint, mountopts=mountopts)
207 if type == "extended": 207 if type == "extended":
208 self._partitions[Decimal("4.9")] = Partition(self, Decimal("4.9"), mb, 0, 0, "free") 208 self._partitions[4.9] = Partition(self, 4.9, mb, 0, 0, "free")
209 self.tidy_partitions() 209 self.tidy_partitions()
210 210
211 ## 211 ##
212 # Removes partition from partition info 212 # Removes partition from partition info
213 # @param minor Minor of partition to remove 213 # @param minor Minor of partition to remove
214 def remove_partition(self, minor): 214 def remove_partition(self, minor):
215 tmppart = self._partitions[int(minor)] 215 tmppart = self._partitions[int(minor)]
216 free_minor = 0 216 free_minor = 0
217 if tmppart.is_logical(): 217 if tmppart.is_logical():
218 free_minor = Decimal(str(float(minor)-0.1)) 218 free_minor = minor-0.1
219 else: 219 else:
220 free_minor = Decimal(str(float(minor)-0.9)) 220 free_minor = minor-0.9
221 self._partitions[free_minor] = Partition(self, free_minor, tmppart.get_mb(), 0, 0, "free", format=False, existing=False) 221 self._partitions[free_minor] = Partition(self, free_minor, tmppart.get_mb(), 0, 0, "free", format=False, existing=False)
222 del self._partitions[int(minor)] 222 del self._partitions[int(minor)]
223 self.tidy_partitions() 223 self.tidy_partitions()
224 224
225 ## 225 ##
313 def get_ordered_partition_list(self): 313 def get_ordered_partition_list(self):
314 parts = self._partitions.keys() 314 parts = self._partitions.keys()
315 parts.sort() 315 parts.sort()
316 partlist = [] 316 partlist = []
317 tmppart = None 317 tmppart = None
318 tmppart_log = None
319 for part in parts: 318 for part in parts:
320 if archinfo[self._arch]['extended'] and part > Decimal("4.1"): break 319 if archinfo[self._arch]['extended'] and part > 4.1: break
321 tmppart = self._partitions[part] 320 tmppart = self._partitions[part]
322 partlist.append(part) 321 partlist.append(part)
323 if tmppart.is_extended(): 322 if tmppart.is_extended():
324 for part_log in parts: 323 for part_log in parts:
325 if part_log < Decimal("4.9"): continue 324 if part_log < 4.9: continue
326 tmppart_log = self._partitions[part_log] 325 tmppart_log = self._partitions[part_log]
327 partlist.append(part_log) 326 partlist.append(part_log)
328 return partlist 327 return partlist
329 328
330 ## 329 ##
470 if type == "ntfs": 469 if type == "ntfs":
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 .\+//'")) 470 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 .\+//'"))
472 self._min_mb_for_resize = int(min_bytes / MEGABYTE) + 1 471 self._min_mb_for_resize = int(min_bytes / MEGABYTE) + 1
473 self._resizeable = True 472 self._resizeable = True
474 elif type == "ext2" or type == "ext3": 473 elif type == "ext2" or type == "ext3":
475 block_size = string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'")) 474 block_size = int(string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\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\+//'")) 475 free_blocks = int(string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'")))
477 free_bytes = int(block_size * free_blocks) 476 free_bytes = int(block_size * free_blocks)
478 # can't hurt to pad (the +50) it a bit since this is really just a guess 477 # can't hurt to pad (the +50) it a bit since this is really just a guess
479 self._min_mb_for_resize = self._mb - int(free_bytes / MEGABYTE) + 50 478 self._min_mb_for_resize = self._mb - int(free_bytes / MEGABYTE) + 50
480 self._resizeable = True 479 self._resizeable = True
481 else: 480 else:
500 499
501 ## 500 ##
502 # Returns whether or not the partition is logical 501 # Returns whether or not the partition is logical
503 def is_logical(self): 502 def is_logical(self):
504 if self._type == "free": 503 if self._type == "free":
505 if int(self._minor) + Decimal("0.9") == Decimal(str(self._minor)): 504 if int(self._minor) + 0.9 == self._minor:
506 return True 505 return True
507 else: 506 else:
508 return False 507 return False
509 elif archinfo[self._device._arch]['extended'] and self._minor > 4: 508 elif archinfo[self._device._arch]['extended'] and self._minor > 4:
510 return True 509 return True
661 ## 660 ##
662 # Returns maximum MB for resize 661 # Returns maximum MB for resize
663 def get_max_mb_for_resize(self): 662 def get_max_mb_for_resize(self):
664 free_minor = 0 663 free_minor = 0
665 if self.is_logical(): 664 if self.is_logical():
666 free_minor = Decimal(str(self._minor + 0.9)) 665 free_minor = self._minor + 0.9
667 else: 666 else:
668 free_minor = Decimal(str(self._minor + 0.1)) 667 free_minor = self._minor + 0.1
669 if free_minor in self._device._partitions: 668 if free_minor in self._device._partitions:
670 return self._mb + self._device._partitions[free_minor]._mb 669 return self._mb + self._device._partitions[free_minor]._mb
671 else: 670 else:
672 return self._mb 671 return self._mb
673 672

Legend:
Removed from v.529  
changed lines
  Added in v.530

  ViewVC Help
Powered by ViewVC 1.1.20