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

Diff of /trunk/src/GLIStorageDevice.py

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

Revision 492 Revision 494
1import commands, string, re, os, parted 1import commands, string, re, os, parted
2from decimal import Decimal
2 3
3MEGABYTE = 1024 * 1024 4MEGABYTE = 1024 * 1024
4 5
5class Device: 6class Device:
6 "Class representing a partitionable device." 7 "Class representing a partitionable device."
52 part_mb = int((parted_part.geom.end - parted_part.geom.start + 1) * self._sector_bytes / MEGABYTE) 53 part_mb = int((parted_part.geom.end - parted_part.geom.start + 1) * self._sector_bytes / MEGABYTE)
53 if parted_part.num >= 1: 54 if parted_part.num >= 1:
54 fs_type = "" 55 fs_type = ""
55 if parted_part.fs_type != None: fs_type = parted_part.fs_type.name 56 if parted_part.fs_type != None: fs_type = parted_part.fs_type.name
56 if parted_part.type == 2: fs_type = "extended" 57 if parted_part.type == 2: fs_type = "extended"
57 # Insert code to calculate MB here ---------------------------------------v
58 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) 58 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)
59 elif parted_part.type_name == "free": 59 elif parted_part.type_name == "free":
60 parent_part = self.get_partition_at(parted_part.geom.start, ignore_extended=0) 60 parent_part = self.get_partition_at(parted_part.geom.start, ignore_extended=0)
61 if parent_part: 61 if parent_part:
62 # And here ----------------------------------------------------------------------------v
63 self._partitions[float(last_log_part+0.9)] = Partition(self, float(last_log_part+0.9), part_mb, parted_part.geom.start, parted_part.geom.end, "free", format=False, existing=False) 62 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)
64 last_log_part += 1 63 last_log_part += 1
65 else: 64 else:
66 # And here ----------------------------------------------------------------------------v
67 self._partitions[float(last_log_part+0.1)] = Partition(self, float(last_log_part+0.1), part_mb, parted_part.geom.start, parted_part.geom.end, "free", format=False, existing=False) 65 self._partitions[Decimal(str(float(last_log_part+0.1)))] = Partition(self, Decimal(str(float(last_log_part+0.1))), part_mb, parted_part.geom.start, parted_part.geom.end, "free", format=False, existing=False)
68 last_part += 1 66 last_part += 1
69 parted_part = self._parted_disk.next_partition(parted_part) 67 parted_part = self._parted_disk.next_partition(parted_part)
70 68
71 def set_partitions_from_install_profile_structure(self, ips): 69 def set_partitions_from_install_profile_structure(self, ips):
72 pass 70 pass
85# 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'])) 83# 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']))
86 84
87 def get_device(self): 85 def get_device(self):
88 return self._device 86 return self._device
89 87
88 def tidy_partitions(self):
89 last_minor = 0
90 last_log_minor = 4
91 last_free = 0
92 last_log_free = 0
93 parts = self._partitions.keys()
94 parts.sort()
95 for part in parts:
96 if self.archinfo[self._arch]['extended'] and part > 4: break
97 tmppart = self._partitions[part]
98 if tmppart.get_type() == "extended":
99 for part_log in parts:
100 if part_log < Decimal("4.9"): continue
101 tmppart_log = self._partitions[part_log]
102 if tmppart_log.get_type() == "free":
103 if not last_log_free:
104 tmppart_log.set_minor(Decimal(str(last_log_minor + 0.9)))
105 else:
106 if last_log_minor < last_log_free:
107 self._partitions[last_log_free].set_mb(self._partitions[last_log_free].get_mb()+tmppart_log.get_mb())
108 del self._partitions[part_log]
109 last_log_free = part_log
110 else:
111 if part_log > (last_log_minor + 1):
112 tmppart_log.set_minor(last_log_minor + 1)
113 last_log_minor = part_log
114 if tmppart.get_type() == "free":
115 if not last_free:
116 tmppart.set_minor(Decimal(str(last_minor + 0.1)))
117 else:
118 if last_minor < last_free:
119 self._partitions[last_free].set_mb(self._partitions[last_free].get_mb()+tmppart.get_mb())
120 del self_partitions[part]
121 last_free = part
122 else:
123 if part > (last_minor + 1):
124 tmppart.set_minor(last_minor + 1)
125 last_minor = part
126
90 def add_partition(self, free_minor, mb, start, end, type, mountpoint='', mountopts=''): 127 def add_partition(self, free_minor, mb, start, end, type, mountpoint='', mountopts=''):
91 free_minor = float(free_minor) 128 free_minor = Decimal(str(free_minor))
92 new_minor = int(free_minor) + 1 129 new_minor = int(free_minor) + 1
130# print "add_partition(): free_minor=" + str(free_minor) + ", new_minor=" + str(new_minor)
93 if self._partitions.has_key(new_minor): 131 if self._partitions.has_key(new_minor):
94 parts = self._partitions.keys() 132 parts = self._partitions.keys()
95 parts.sort() 133 parts.sort()
96 parts.reverse() 134 parts.reverse()
97 hole_at = 0 135 hole_at = 0
106 if i >= hole_at and hole_at: continue 144 if i >= hole_at and hole_at: continue
107 if i >= new_minor: 145 if i >= new_minor:
108 self._partitions[i].set_minor(i+1) 146 self._partitions[i].set_minor(i+1)
109 self._partitions[i+1] = self._partitions[i] 147 self._partitions[i+1] = self._partitions[i]
110 if i == new_minor: stopscooting = 1 148 if i == new_minor: stopscooting = 1
149 if mb != self._partitions[free_minor].get_mb():
150 old_free_mb = self._partitions[free_minor].get_mb()
111 del self._partitions[free_minor] 151 del self._partitions[free_minor]
152 if self.archinfo[self._arch]['extended'] and new_minor >= 5:
153 free_minor = Decimal(str(new_minor + 0.9))
154 else:
155 free_minor = Decimal(str(new_minor + 0.1))
156 self._partitions[free_minor] = Partition(self, free_minor, old_free_mb-mb, 0, 0, "free")
157# print "add_partition(): new part doesn't use all freespace. new free part is: minor=" + str(free_minor)
158 else:
159 del self._partitions[free_minor]
112 self._partitions[new_minor] = Partition(self, new_minor, mb, start, end, type, mountpoint=mountpoint, mountopts=mountopts) 160 self._partitions[new_minor] = Partition(self, new_minor, mb, start, end, type, mountpoint=mountpoint, mountopts=mountopts)
161 if type == "extended":
162 self._partitions[Decimal("4.9")] = Partition(self, Decimal("4.9"), mb, 0, 0, "free")
163 self.tidy_partitions()
113 164
114 def remove_partition(self, minor): 165 def remove_partition(self, minor):
115 tmppart = self._partitions[int(minor)] 166 tmppart = self._partitions[int(minor)]
116 free_minor = 0 167 free_minor = 0
117 if tmppart.is_logical(): 168 if tmppart.is_logical():
118 free_minor = float(minor)-0.1 169 free_minor = Decimal(str(float(minor)-0.1))
119 else: 170 else:
120 free_minor = float(minor)-0.9 171 free_minor = Decimal(str(float(minor)-0.9))
121 self._partitions[free_minor] = Partition(self, free_minor, tmppart.get_mb(), 0, 0, "free", format=False, existing=False) 172 self._partitions[free_minor] = Partition(self, free_minor, tmppart.get_mb(), 0, 0, "free", format=False, existing=False)
122 del self._partitions[int(minor)] 173 del self._partitions[int(minor)]
174 self.tidy_partitions()
123 175
124 def get_free_space(self, start): 176 def get_free_space(self, start):
125 GAP_SIZE = 100 177 GAP_SIZE = 100
126 parts = self._partitions.keys() 178 parts = self._partitions.keys()
127 parts.sort() 179 parts.sort()
201 parts.sort() 253 parts.sort()
202 partlist = [] 254 partlist = []
203 tmppart = None 255 tmppart = None
204 tmppart_log = None 256 tmppart_log = None
205 for part in parts: 257 for part in parts:
206 if self.archinfo[self._arch]['extended'] and part > 4.1: break 258 if self.archinfo[self._arch]['extended'] and part > Decimal("4.1"): break
207 tmppart = self._partitions[part] 259 tmppart = self._partitions[part]
208 partlist.append(part) 260 partlist.append(part)
209 if tmppart.is_extended(): 261 if tmppart.is_extended():
210 for part_log in parts: 262 for part_log in parts:
211 if part_log < 4.9: continue 263 if part_log < Decimal("4.9"): continue
212 tmppart_log = self._partitions[part_log] 264 tmppart_log = self._partitions[part_log]
213 partlist.append(part_log) 265 partlist.append(part_log)
214 return partlist 266 return partlist
215 267
216 def get_install_profile_structure(self): 268 def get_install_profile_structure(self):
348 else: 400 else:
349 return False 401 return False
350 402
351 def is_logical(self): 403 def is_logical(self):
352 if self._type == "free": 404 if self._type == "free":
353 if int(self._minor) + 0.9 == self._minor: 405 if int(self._minor) + Decimal("0.9") == Decimal(str(self._minor)):
354 return True 406 return True
355 else: 407 else:
356 return False 408 return False
357 elif self._device.archinfo[self._device._arch]['extended'] and self._minor > 4: 409 elif self._device.archinfo[self._device._arch]['extended'] and self._minor > 4:
358 return True 410 return True
392 def get_end(self): 444 def get_end(self):
393 return int(self._end) 445 return int(self._end)
394 446
395 def get_mb(self): 447 def get_mb(self):
396 return int(self._mb) 448 return int(self._mb)
449
450 def set_mb(self, mb):
451 self._mb = int(mb)
397 452
398 def set_type(self, type): 453 def set_type(self, type):
399 self._type = type 454 self._type = type
400 455
401 def get_type(self): 456 def get_type(self):

Legend:
Removed from v.492  
changed lines
  Added in v.494

  ViewVC Help
Powered by ViewVC 1.1.20