Class: Yast::AutoinstPartitionClass
- Inherits:
-
Module
- Object
- Module
- Yast::AutoinstPartitionClass
- Defined in:
- ../../src/modules/AutoinstPartition.rb
Instance Method Summary (collapse)
- - (Object) areEqual(p1, p2)
- - (Object) AutoinstPartition
- - (Object) checkSanity(part)
- - (Object) createTree(p, parentRef, idx)
-
- (Object) exportPartition(part)
Export filtering.
- - (Object) getAllFileSystemTypes
-
- (Object) getAllUnits
“static” functions (don't need a PartitionT [this pointer]).
- - (Object) getDefaultMountPoints
- - (Object) getFileSystem(part)
- - (Object) getFormat(part)
- - (Object) getLVNameFor(mountPoint)
- - (Object) getMaxPartitionNumber
- - (Object) getNodeReference(parentRef, partitionIndex)
- - (Object) getPartitionDescription(p, enableHTML)
- - (Object) getSize(part)
- - (Object) getTokenizedSize(part)
- - (Object) getUnit(part)
- - (Object) hasValidType(field, value)
- - (Object) isField(field)
-
- (Object) isPartition(partition)
Convenience wrappers for more general object predicates.
- - (Object) isPartOfVolgroup(part)
- - (Object) main
-
- (Object) new(mp)
Constructor.
- - (Object) parsePartition(part)
-
- (Object) set(partition, field, value)
Convenience wrapper for setter.
Instance Method Details
- (Object) areEqual(p1, p2)
91 92 93 94 95 |
# File '../../src/modules/AutoinstPartition.rb', line 91 def areEqual(p1, p2) p1 = deep_copy(p1) p2 = deep_copy(p2) AutoinstCommon.areEqual(p1, p2) end |
- (Object) AutoinstPartition
74 75 76 77 78 |
# File '../../src/modules/AutoinstPartition.rb', line 74 def AutoinstPartition @allfs = FileSystems.GetAllFileSystems(true, true, "") nil end |
- (Object) checkSanity(part)
382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File '../../src/modules/AutoinstPartition.rb', line 382 def checkSanity(part) part = deep_copy(part) result = "" if "%" == getUnit(part) && 0 == getSize(part) result = Builtins.sformat( "%1You chose '%%' as size unit but did not provide a correct percentage value.\n", result ) end # ... # other tests maybe # ... result end |
- (Object) createTree(p, parentRef, idx)
182 183 184 185 186 |
# File '../../src/modules/AutoinstPartition.rb', line 182 def createTree(p, parentRef, idx) p = deep_copy(p) part_desc = getPartitionDescription(p, false) createTreeNode(getNodeReference(parentRef, idx), part_desc, []) end |
- (Object) exportPartition(part)
Export filtering
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File '../../src/modules/AutoinstPartition.rb', line 364 def exportPartition(part) part = deep_copy(part) # filter out empty string attributes result = {} result = Builtins.filter(part) do |key, value| if Ops.is_string?(value) && "" == value # false gets filtered out next false elsif Ops.is_symbol?(value) && :Empty == value next false else next true end end deep_copy(result) end |
- (Object) getAllFileSystemTypes
403 404 405 |
# File '../../src/modules/AutoinstPartition.rb', line 403 def getAllFileSystemTypes deep_copy(@allfs) end |
- (Object) getAllUnits
“static” functions (don't need a PartitionT [this pointer])
399 400 401 |
# File '../../src/modules/AutoinstPartition.rb', line 399 def getAllUnits deep_copy(@allUnits) end |
- (Object) getDefaultMountPoints
407 408 409 |
# File '../../src/modules/AutoinstPartition.rb', line 407 def getDefaultMountPoints deep_copy(@defaultMountPoints) end |
- (Object) getFileSystem(part)
229 230 231 232 |
# File '../../src/modules/AutoinstPartition.rb', line 229 def getFileSystem(part) part = deep_copy(part) Ops.get_symbol(part, "filesystem", :Empty) end |
- (Object) getFormat(part)
219 220 221 222 |
# File '../../src/modules/AutoinstPartition.rb', line 219 def getFormat(part) part = deep_copy(part) Ops.get_boolean(part, "format", false) end |
- (Object) getLVNameFor(mountPoint)
416 417 418 419 420 |
# File '../../src/modules/AutoinstPartition.rb', line 416 def getLVNameFor(mountPoint) result = removePrefix(mountPoint, "/") result = "root" if "" == result result end |
- (Object) getMaxPartitionNumber
411 412 413 |
# File '../../src/modules/AutoinstPartition.rb', line 411 def getMaxPartitionNumber @maxPartitionNumber end |
- (Object) getNodeReference(parentRef, partitionIndex)
110 111 112 113 114 115 116 117 118 |
# File '../../src/modules/AutoinstPartition.rb', line 110 def getNodeReference(parentRef, partitionIndex) # e.g.: parentRef = "drive:0" driveID = Builtins.substring( parentRef, Ops.add(Builtins.findfirstof(parentRef, "_"), 1) ) idx = Builtins.tostring(partitionIndex) Builtins.sformat("part_%1_%2", driveID, idx) end |
- (Object) getPartitionDescription(p, enableHTML)
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File '../../src/modules/AutoinstPartition.rb', line 120 def getPartitionDescription(p, enableHTML) p = deep_copy(p) part_desc = Ops.get_string(p, "mount", "") if "" == part_desc part_desc = Ops.get_string(p, "lvm_group", "") if enableHTML part_desc = Builtins.sformat( "Physical volume for volume group <<b>%1</b>>", part_desc ) else part_desc = Builtins.sformat("<%1>", part_desc) end else if enableHTML part_desc = Builtins.sformat("<b>%1</b> Partition", part_desc) end end if Ops.get_boolean(p, "create", false) part_desc = Builtins.sformat( "%1 with %2", part_desc, Ops.get_string(p, "size", "") ) else if Ops.get_boolean(p, "resize", false) part_desc = Builtins.sformat( "%1 resize part.%2 to %3", part_desc, Ops.get_integer(p, "partition_nr", 999), Ops.get_string(p, "size", "") ) else part_desc = Builtins.sformat( "%1 reuse part. %2", part_desc, Ops.get_integer(p, "partition_nr", 999) ) end end part_desc = Builtins.sformat( "%1,%2", part_desc, Partitions.FsIdToString(Ops.get_integer(p, "partition_id", 131)) ) fs = Ops.get(@allfs, Ops.get_symbol(p, "filesystem", :nothing), {}) fs_name = Ops.get_string(fs, :name, "") part_desc = Builtins.sformat("%1,%2", part_desc, fs_name) if "" != fs_name if Ops.greater_than(Builtins.size(Ops.get_list(p, "region", [])), 0) reg_info = Builtins.sformat( "%1 - %2", Ops.get_integer(p, ["region", 0], 0), Ops.get_integer(p, ["region", 1], 0) ) part_desc = Builtins.sformat("%1,%2", part_desc, reg_info) end part_desc end |
- (Object) getSize(part)
198 199 200 201 202 203 204 205 206 207 |
# File '../../src/modules/AutoinstPartition.rb', line 198 def getSize(part) part = deep_copy(part) tokenizedSize = getTokenizedSize(part) sizeString = Ops.get(tokenizedSize, 0, "0") unitString = Ops.get(tokenizedSize, 1, "") if "auto" == unitString || "max" == unitString || "" == sizeString sizeString = "0" end Builtins.tointeger(sizeString) end |
- (Object) getTokenizedSize(part)
189 190 191 192 193 194 195 |
# File '../../src/modules/AutoinstPartition.rb', line 189 def getTokenizedSize(part) part = deep_copy(part) encodedSize = Ops.get_string(part, "size", "") # regex tokenizes size strings of the liking: # "1000", "10KB", "1 GB" and "max" Builtins.regexptokenize(encodedSize, "([0-9]*)s*([A-Za-z%]*)") end |
- (Object) getUnit(part)
209 210 211 212 213 214 215 216 217 |
# File '../../src/modules/AutoinstPartition.rb', line 209 def getUnit(part) part = deep_copy(part) if "max" == Ops.get_string(part, "size", "") || "auto" == Ops.get_string(part, "size", "") return Ops.get_string(part, "size", "") else return Ops.get(getTokenizedSize(part), 1, "") end end |
- (Object) hasValidType(field, value)
87 88 89 90 |
# File '../../src/modules/AutoinstPartition.rb', line 87 def hasValidType(field, value) value = deep_copy(value) AutoinstCommon.hasValidType(@fields, field, value) end |
- (Object) isField(field)
84 85 86 |
# File '../../src/modules/AutoinstPartition.rb', line 84 def isField(field) AutoinstCommon.isValidField(@fields, field) end |
- (Object) isPartition(partition)
Convenience wrappers for more general object predicates
80 81 82 83 |
# File '../../src/modules/AutoinstPartition.rb', line 80 def isPartition(partition) partition = deep_copy(partition) AutoinstCommon.isValidObject(@fields, partition) end |
- (Object) isPartOfVolgroup(part)
224 225 226 227 |
# File '../../src/modules/AutoinstPartition.rb', line 224 def isPartOfVolgroup(part) part = deep_copy(part) Ops.get_string(part, "lvm_group", "") != "" end |
- (Object) main
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File '../../src/modules/AutoinstPartition.rb', line 13 def main Yast.import "UI" Yast.include self, "autoinstall/types.rb" Yast.include self, "autoinstall/common.rb" Yast.include self, "autoinstall/tree.rb" Yast.import "AutoinstCommon" Yast.import "Partitions" Yast.import "FileSystems" textdomain "autoinst" # defines data structur of a partition # provides types for type checking @fields = { "crypt" => "", "crypt_fs" => false, "crypt_key" => "", "create" => true, "mount" => "/", "fstopt" => "", "label" => "", "loop_fs" => false, "uuid" => "", "size" => "10G", "format" => true, "filesystem" => Partitions.DefaultFs, "mkfs_options" => "", "partition_nr" => 1, "partition_id" => 131, "mountby" => :device, "resize" => false, "lv_name" => "", "stripes" => 1, "stripesize" => 4, "lvm_group" => "", "raid_name" => "", "raid_type" => "", "raid_options" => {}, "subvolumes" => [], "pool" => false, "used_pool" => "" } @allfs = {} @defaultMountPoints = [ "/", "/boot", "/home", "/usr", "/usr/local", "swap", "/tmp" ] @allUnits = ["Byte", "MB", "GB", "%", "max"] @maxPartitionNumber = 999 AutoinstPartition() end |
- (Object) new(mp)
Constructor
106 107 108 |
# File '../../src/modules/AutoinstPartition.rb', line 106 def new(mp) set(@fields, "mount", mp) end |
- (Object) parsePartition(part)
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File '../../src/modules/AutoinstPartition.rb', line 234 def parsePartition(part) part = deep_copy(part) newPart = new(Ops.get_string(part, "mount", "")) newPart = set( newPart, "mountby", Ops.get_symbol(part, "mountby", :device) ) if Builtins.haskey(part, "label") newPart = set(newPart, "label", Ops.get_string(part, "label", "")) end newPart = set(newPart, "create", Ops.get_boolean(part, "create", true)) newPart = set(newPart, "crypt", Ops.get_string(part, "crypt", "")) newPart = set( newPart, "crypt_fs", Ops.get_boolean(part, "crypt_fs", false) ) newPart = set(newPart, "crypt_key", Ops.get_string(part, "crypt_key", "")) newPart = set(newPart, "format", Ops.get_boolean(part, "format", true)) if Builtins.haskey(part, "filesystem") newPart = set( newPart, "filesystem", Ops.get_symbol(part, "filesystem", :Empty) ) newPart = set(newPart, "format", true) end if Ops.get_boolean(newPart, "format", false) && !Builtins.isempty(Ops.get_string(part, "mkfs_options", "")) Ops.set( newPart, "mkfs_options", Ops.get_string(part, "mkfs_options", "") ) else newPart = Builtins.remove(newPart, "mkfs_options") end if !Builtins.isempty(Ops.get_list(part, "subvolumes", [])) #Filtering out all snapper subvolumes newPart["subvolumes"] = part["subvolumes"].reject { |s| s.start_with?(".snapshots") } else newPart = Builtins.remove(newPart, "subvolumes") end if !Builtins.isempty(Ops.get_string(part, "used_pool", "")) Ops.set(newPart, "used_pool", Ops.get_string(part, "used_pool", "")) else newPart = Builtins.remove(newPart, "used_pool") end if Ops.get_boolean(part, "pool", false) Ops.set(newPart, "pool", true) else newPart = Builtins.remove(newPart, "pool") end newPart = set(newPart, "loop_fs", Ops.get_boolean(part, "loop_fs", false)) if part.has_key?("partition_id") newPart["partition_id"] = part["partition_id"] else #removing default entry newPart.delete("partition_id") end newPart = set(newPart, "size", Ops.get_string(part, "size", "")) newPart = set(newPart, "lv_name", Ops.get_string(part, "lv_name", "")) newPart = set(newPart, "lvm_group", Ops.get_string(part, "lvm_group", "")) newPart = set(newPart, "stripes", Ops.get_integer(part, "stripes", 1)) # Set partition_nr too (if available) bnc#886808 newPart["partition_nr"] = part["partition_nr"] if part["partition_nr"] newPart = set( newPart, "stripesize", Ops.get_integer(part, "stripesize", 4) ) if Builtins.haskey(part, "fstopt") newPart = set( newPart, "fstopt", Ops.get_string(part, "fstopt", "defaults") ) end if Ops.get_integer(part, "stripes", 1) == 1 newPart = Builtins.remove(newPart, "stripes") newPart = Builtins.remove(newPart, "stripesize") end # partition_id enforcement if Builtins.haskey(part, "lvm_group") newPart = set(newPart, "partition_id", 142) elsif "swap" == Ops.get_string(newPart, "mount", "") newPart = set(newPart, "partition_id", 130) end if Builtins.haskey(part, "raid_name") newPart = set( newPart, "raid_name", Ops.get_string(part, "raid_name", "") ) end if Builtins.haskey(part, "raid_options") newPart = set( newPart, "raid_options", Ops.get_map(part, "raid_options", {}) ) else newPart = Builtins.remove(newPart, "raid_options") end if part["partition_id"] == Partitions.fsid_bios_grub # GRUB_BIOS partitions must not be formated # with default filesystem btrfs. (bnc#876411) # The other deleted entries would be useless in that case. newPart.delete("filesystem") newPart.delete("format") newPart.delete("crypt_fs") newPart.delete("loop_fs") newPart.delete("mountby") end if part["filesystem"] == :tmpfs # remove not needed entries for TMPFS newPart.delete("partition_nr") newPart.delete("resize") newPart.delete("crypt_fs") newPart.delete("loop_fs") end deep_copy(newPart) end |
- (Object) set(partition, field, value)
Convenience wrapper for setter
98 99 100 101 102 |
# File '../../src/modules/AutoinstPartition.rb', line 98 def set(partition, field, value) partition = deep_copy(partition) value = deep_copy(value) AutoinstCommon.set(@fields, partition, field, value) end |