Best Python code snippet using autotest_python
GLIStorageDevice.py
Source:GLIStorageDevice.py
...108 elif parted_part.type_name == "free":109 if self._disklabel == "mac":110 free_minor = int(GLIUtility.spawn("mac-fdisk -l %s | grep '@ %s' | cut -d ' ' -f 1" % (self._device, str(parted_part.geom.start)), return_output=True)[1].strip()[-1])111 elif self.get_extended_partition() and parted_part.geom.start >= self.get_partition(self.get_extended_partition()).get_start() and parted_part.geom.end <= self.get_partition(self.get_extended_partition()).get_end():112 if self._partitions[-1].get_minor() > 4:113 free_minor = self._partitions[-1].get_minor() + FREE_MINOR_FRAC_LOG114 else:115 free_minor = 4 + FREE_MINOR_FRAC_LOG116 else:117 try:118 free_minor = self._partitions[-1].get_minor() + FREE_MINOR_FRAC_PRI119 except IndexError:120 free_minor = FREE_MINOR_FRAC_PRI121 self._partitions.append(Partition(self, free_minor, part_mb, parted_part.geom.start, parted_part.geom.end, "free", format=False, existing=False))122 parted_part = self._parted_disk.next_partition(parted_part)123 # Juggle minor numbers so they match physical disk order. People may complain, but we're actually doing them a favor124 self.reorder_minors()125 ##126 # Reorders partition minors so that they match physical disk order127 def reorder_minors(self):128 for i, part in enumerate(self._partitions):129 if not i:130 last_minor = 0131 else:132 last_minor = self._partitions[i-1].get_minor()133 if part.get_type() == "free":134 if self._disklabel == "mac":135 new_minor = last_minor + 1136 elif last_minor and part.is_logical():137 if self.get_partition(last_minor).is_extended():138 last_minor = 4139 new_minor = last_minor + FREE_MINOR_FRAC_LOG140 else:141 new_minor = last_minor + FREE_MINOR_FRAC_PRI142 part.set_minor(new_minor)143 else:144 if not last_minor:145 new_minor = 1146 else:147 new_minor = int(last_minor) + 1148 part.set_minor(new_minor)149 ##150 # Imports partition info from the install profile partition structure151 # @param ips Parameter structure returned from install_profile.get_partition_tables()152 def set_partitions_from_install_profile_structure(self, ips):153 for tmppart in ips:154 existing = False155 if tmppart['origminor'] and not tmppart['format']:156 existing = True157 self._partitions.append(Partition(self, tmppart['minor'], tmppart['mb'], tmppart['start'], tmppart['end'], tmppart['type'], format=tmppart['format'], origminor=tmppart['origminor'], existing=existing, mountpoint=tmppart['mountpoint'], mountopts=tmppart['mountopts'], mkfsopts=tmppart['mkfsopts'], resized=(existing and tmppart['resized'])))158 ##159 # Returns the partition object with the specified minor160 # @param minor Minor number of partition object to get161 def get_partition(self, minor):162 for part in self._partitions:163 if part.get_minor() == minor:164 return part165 return None166 def get_partition_position(self, minor):167 for i, part in enumerate(self._partitions):168 if part.get_minor() == minor:169 return i170 return -1171 ##172 # Returns name of device (e.g. /dev/hda) being represented173 def get_device(self):174 return self._device175 ##176 # Returns whether the device is local or not177 def is_local(self):178 return self._local_device179 ##180 # Uses magic to apply the recommended partition layout181 def do_recommended(self):182 free_minor = 0183 recommended_parts = [ { 'type': "ext2", 'size': 100, 'mountpoint': "/boot" },184 { 'type': "linux-swap", 'size': 512, 'mountpoint': "" },185 { 'type': "ext3", 'size': "*", 'mountpoint': "/" } ]186 to_create = []187 physical_memory = int(GLIUtility.spawn(r"free -m | egrep '^Mem:' | sed -e 's/^Mem: \+//' -e 's/ \+.\+$//'", return_output=True)[1].strip())188# parts = self.get_ordered_partition_list()189 # Search for concurrent unallocated space >=4GB190 for part in self._partitions:191 if part.get_type() == "free" and part.get_mb() >= 4096:192 free_minor = part.get_minor()193 break194 if not free_minor:195 raise GLIException("RecommendedPartitionLayoutError", "notice", "do_recommended", "You do not have atleast 4GB of concurrent unallocated space. Please remove some partitions and try again.")196 remaining_free = self.get_partition(free_minor).get_mb()197 for newpart in recommended_parts:198 # extended/logical partitions suck like a hoover199 if self._labelinfo['extended'] and free_minor == (3 + FREE_MINOR_FRAC_PRI) and not newpart == recommended_parts[-1]:200 if self.get_extended_partition():201 raise GLIException("RecommendedPartitionLayoutError", "notice", "do_recommended", "This code is not yet robust enough to handle automatic partitioning with your current layout.")202 to_create.append({ 'type': "extended", 'size': remaining_free, 'mountpoint': "", 'free_minor': free_minor })203 free_minor = 4 + FREE_MINOR_FRAC_LOG204 newpart['free_minor'] = free_minor205 # Small hack to calculate optimal swap partition size206 if newpart['type'] == "linux-swap" and physical_memory and physical_memory < 1024:207 newpart['size'] = physical_memory * 2208 to_create.append(newpart)209 free_minor = free_minor + 1210 if not newpart['size'] == "*":211 remaining_free = remaining_free - newpart['size']212 for newpart in to_create:213 if newpart['size'] == "*":214 # This doesn't seem quite right...it should probably be set to remaining_free215# newpart['size'] = self.get_partition(newpart['free_minor']).get_mb()216 newpart['size'] = remaining_free217 self.add_partition(newpart['free_minor'], newpart['size'], 0, 0, newpart['type'], mountpoint=newpart['mountpoint'])218 def find_free_minor(self, min, max):219 good_minor = max220 for i in range(int(max) - 1, int(min) - 1, -1):221 if not self.get_partition(i):222 good_minor = i223# print "min = %s, max = %s, good_minor = %s" % (str(min), str(max), str(good_minor))224 return good_minor225 ##226 # Combines free space and closes gaps in minor numbers. This is used internally227 def tidy_partitions(self):228 newparts = []229 for i, part in enumerate(self._partitions):230 if part.get_type() == "free":231 if i and newparts[-1].get_type() == "free":232 newparts[-1].set_mb(newparts[-1].get_mb()+part.get_mb())233# self._partitions.pop(i)234 continue235 else:236 if self._disklabel == "mac":237 part.set_minor(self.find_free_minor(newparts[-1].get_minor() + 1, part.get_minor()))238 elif self._labelinfo['extended'] and part.get_minor() > 4:239 last_minor = newparts[-1].get_minor()240 if last_minor <= 4: last_minor = 4241 part.set_minor(last_minor + FREE_MINOR_FRAC_LOG)242 else:243 if i:244 free_minor = newparts[-1].get_minor() + FREE_MINOR_FRAC_PRI245 else:246 free_minor = FREE_MINOR_FRAC_PRI247 part.set_minor(free_minor)248 else:249 if self._labelinfo['extended'] and part.get_minor() > 4:250 part.set_minor(self.find_free_minor(5, part.get_minor()))251 else:252 part.set_minor(self.find_free_minor(1, part.get_minor()))253 newparts.append(part)254 self._partitions = newparts255 ##256 # Adds a new partition to the partition info257 # @param free_minor minor of unallocated space partition is being created in258 # @param mb size of partition in MB259 # @param start Start sector (only used for existing partitions)260 # @param end End sector (only used for existing partitions)261 # @param type Partition type (ext2, ext3, fat32, linux-swap, free, extended, etc.)262 # @param mountpoint='' Partition mountpoint263 # @param mountopts='' Partition mount options264 # @param mkfsopts='' Additional mkfs options265 def add_partition(self, free_minor, mb, start, end, type, mountpoint='', mountopts='',mkfsopts=''):266 # Automatically pick the first unused minor if not a local device267 if not self._local_device or free_minor == -1:268 tmpminor = self._partitions[-1].get_minor()269 if self._disklabel == "mac":270 free_minor = tmpminor + 1271 elif self._labelinfo['extended'] and tmpminor > 4:272 free_minor = tmpminor + FREE_MINOR_FRAC_LOG273 else:274 free_minor = tmpminor + FREE_MINOR_FRAC_PRI275 self._partitions.append(Partition(self, free_minor, mb, 0, 0, "free"))276 if self._disklabel == "mac":277 new_minor = free_minor278 else:279 new_minor = int(free_minor) + 1280 free_minor_pos = self.get_partition_position(free_minor)281 if self._local_device:282 # Check to see if the new minor we picked already exists. If it does, scoot all partitions from283 # that one on down a minor284 if self.get_partition(new_minor):285 for i, part in enumerate(self._partitions):286 if i <= free_minor_pos or new_minor > part.get_minor(): continue287 part.set_minor(part.get_minor() + 1)288 # If the size specified for the new partition is less than the size of the unallocated space that it289 # is getting placed into, a new partition to represent the remaining unallocated space needs to be290 # created.291 if mb != self.get_partition(free_minor).get_mb():292 old_free_mb = self.get_partition(free_minor).get_mb()293 self._partitions.pop(free_minor_pos)294 if self._disklabel == "mac":295 free_minor = new_minor + 1296 if self.get_partition(free_minor):297 for i, part in enumerate(self._partitions):298 if i < self.get_partition_position(new_minor+1) or free_minor > part.get_minor(): continue299 part.set_minor(part.get_minor() + 1)300 if self._labelinfo['extended'] and new_minor > 4:301 free_minor = new_minor + FREE_MINOR_FRAC_LOG302 else:303 free_minor = new_minor + FREE_MINOR_FRAC_PRI304 self._partitions.insert(free_minor_pos, Partition(self, free_minor, old_free_mb-mb, 0, 0, "free"))305 else:306 self._partitions.pop(free_minor_pos)307 self._partitions.insert(free_minor_pos, Partition(self, new_minor, mb, start, end, type, mountpoint=mountpoint, mountopts=mountopts,mkfsopts=mkfsopts))308 # When we create an extended partition, we have to create the partition to represent the unallocated309 # space inside of the extended partition310 if type == "extended":311 self._partitions.insert(self.get_partition_position(self.get_extended_partition()) + 1, Partition(self, (4 + FREE_MINOR_FRAC_LOG), mb, 0, 0, "free"))312 new_minor_pos = self.get_partition_position(new_minor)313 self.tidy_partitions()314 return self._partitions[new_minor_pos].get_minor()315 ##316 # Removes partition from partition info317 # @param minor Minor of partition to remove318 def remove_partition(self, minor):319 part = self.get_partition(minor)320 part_pos = self.get_partition_position(minor)321 free_minor = 0322 if self._disklabel == "mac":323 free_minor = minor324 elif part.is_logical():325 free_minor = int(minor-1)+FREE_MINOR_FRAC_LOG326 else:327 free_minor = int(minor-1)+FREE_MINOR_FRAC_PRI328 if part.get_type() == "extended":329 # Remove free partition inside extended330 self._partitions.pop(part_pos+1)331 self._partitions[part_pos] = Partition(self, free_minor, part.get_mb(), 0, 0, "free", format=False, existing=False)332 self.tidy_partitions()333 ##334 # This function clears the partition table335 def clear_partitions(self):336 self._partitions = [ Partition(self, (0 + FREE_MINOR_FRAC_PRI), self.get_total_mb(), 0, 0, "free", format=False, existing=False) ]337 self._disklabel = archinfo[self._arch]338 ##339 # Returns an ordered list (disk order) of partition minors340 def get_ordered_partition_list(self):341 partlist = []342 for part in self._partitions:343 partlist.append(part.get_minor())344 return partlist345 ##346 # Returns partition info in a format suitable for passing to install_profile.set_partition_tables()347 def get_install_profile_structure(self):348 devlist = []349 for tmppart in self._partitions:350# tmppart = self._partitions[part]351 devlist.append({ 'mb': tmppart.get_mb(), 'minor': float(tmppart.get_minor()), 'origminor': tmppart.get_orig_minor(), 'type': tmppart.get_type(), 'mountpoint': tmppart.get_mountpoint(), 'mountopts': tmppart.get_mountopts(), 'format': tmppart.get_format(), 'mkfsopts': tmppart.get_mkfsopts(), 'start': tmppart._start, 'end': tmppart._end, 'resized': tmppart.get_resized() })352 return devlist353 ##354 # Returns the minor of the extended partition, if any355 def get_extended_partition(self):356 for part in self._partitions:357 if part.is_extended():358 return part.get_minor()359 return 0360 ##361 # Returns the drive model362 def get_model(self):363 if self._local_device:364 return self._parted_dev.model365 else:366 return "Generic disk"367 ##368 # Sets the disklabel type369 def set_disklabel(self, disklabel):370 self._disklabel = disklabel371 ##372 # Returns the disklabel type373 def get_disklabel(self):374 return self._disklabel375 ##376 # Returns the number of sectors on the device377 def get_num_sectors(self):378 return long(self._total_sectors)379 ##380 # Returns the size of a cylinder in bytes381 def get_cylinder_size(self):382 return long(self._cylinder_bytes)383 ##384 # Returns the size of a sector in bytes385 def get_sector_size(self):386 return long(self._sector_bytes)387 ##388 # Returns the number of cylinders389 def get_num_cylinders(self):390 return long(self._geometry['cylinders'])391 ##392 # Returns the total number of bytes on the device393 def get_drive_bytes(self):394 return long(self._total_bytes)395 ##396 # Returns the total number of MB on the device397 def get_total_mb(self):398 if self._local_device:399 return self._total_mb400 else:401 total_mb = 0402 for tmppart in self._partitions:403 total_mb += tmppart.get_mb()404 return total_mb405 ##406 # Returns partition info dictionary407 def get_partitions(self):408 return self._partitions409##410# This class represents a partition within a GLIStorageDevice object411class Partition:412 "Class representing a single partition within a Device object"413 _device = None414 _minor = 0415 _orig_minor = 0416 _start = 0417 _end = 0418 _type = None419 _mountpoint = None420 _mountopts = None421 _format = None422 _resizeable = None423 _min_mb_for_resize = 0424 _mb = ""425 _mkfsopts = None426 _resized = False427 _name = None428 429 ##430 # Initialization function for the Partition class431 # @param device Parent GLIStorageDevice object432 # @param minor Minor of partition433 # @param mb Parameter Size of partition in MB434 # @param start Parameter Start sector of partition435 # @param end Parameter Start sector of partition436 # @param type Parameter Type of partition (ext2, ext3, fat32, linux-swap, free, extended, etc.)437 # @param mountpoint='' Mountpoint of partition438 # @param mountopts='' Mount options of partition439 # @param mkfsopts='' Additional mkfs options440 # @param format=True Format partition441 # @param existing=False This partition exists on disk442 def __init__(self, device, minor, mb, start, end, type, mountpoint='', mountopts='', format=True, existing=False, origminor=0, mkfsopts='', resized=False, name=""):443 self._device = device444 self._minor = float(minor)445 self._start = long(start)446 self._end = long(end)447 self._type = type or "unknown"448 self._mountpoint = mountpoint449 self._mountopts = mountopts450 self._format = format451 self._mb = mb452 self._orig_minor = origminor453 self._mkfsopts = mkfsopts454 self._resizeable = False455 self._resized = resized456 self._name = name457 self._flags = []458 if type != "free":459 if existing and not origminor:460 self._orig_minor = self._minor461 self._minor = int(self._minor)462 self._orig_minor = int(self._orig_minor)463 if existing:464 try:465 parted_part = device._parted_disk.get_partition(self._orig_minor)466 label_type = device._parted_disk.type.name467 if label_type == "loop":468 dev_node = device._device469 else:470 dev_node = device._device + str(self._orig_minor)471 # The 10 is completely arbitrary. If flags seem to be missed, this number should be increased472 for flag in range(0, 10):473 if parted_part.is_flag_available(flag) and parted_part.get_flag(flag):474 self._flags.append(flag)475 if type == "ext2" or type == "ext3":476 block_size = long(string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'")))477 free_blocks = long(string.strip(commands.getoutput("dumpe2fs -h " + dev_node + r" 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'")))478 free_bytes = long(block_size * free_blocks)479 # can't hurt to pad (the +50) it a bit since this is really just a guess480 self._min_mb_for_resize = self._mb - long(free_bytes / MEGABYTE) + 50481 self._resizeable = True482 elif type == "ntfs":483 min_bytes = long(commands.getoutput("ntfsresize -f --info " + dev_node + " | grep -e '^You might resize' | sed -e 's/You might resize at //' -e 's/ bytes or .\+//'"))484 self._min_mb_for_resize = long(min_bytes / MEGABYTE) + 50485 self._resizeable = True486 else:487 parted_part = self._device._parted_disk.get_partition(int(self._orig_minor))488 parted_fs = parted_part.geom.file_system_open()489 resize_constraint = parted_fs.get_resize_constraint()490 min_bytes = resize_constraint.min_size * self._device._sector_bytes491 self._min_mb_for_resize = long(min_bytes / MEGABYTE) + 1492 self._resizeable = True493 except:494 self._resizeable = False495 def __getitem__(self, name):496 tmpdict = { 'start': self.get_start,497 'end': self.get_end,498 'format': self.get_format,499 'type': self.get_type,500 'resized': self.get_resized,501 'minor': self.get_minor,502 'mb': self.get_mb,503 'origminor': self.get_orig_minor,504 'mountpoint': self.get_mountpoint,505 'mountopts': self.get_mountopts,506 'mkfsopts': self.get_mkfsopts,507 'flags': self.get_flags,508 'devnode': self.get_devnode,509 'name': self.get_name510 }511 if name in tmpdict:512 return tmpdict[name]()513 else:514 raise ValueError(name + " is not a valid attribute!")515 def __setitem__(self, name, value):516 tmpdict = { 'start': self.set_start,517 'end': self.set_end,518 'format': self.set_format,519 'type': self.set_type,520# 'resized': self.set_resized,521 'minor': self.set_minor,522 'mb': self.set_mb,523 'origminor': self.set_orig_minor,524 'mountpoint': self.set_mountpoint,525 'mountopts': self.set_mountopts,526 'mkfsopts': self.set_mkfsopts,527 'flags': self.set_flags,528 'name': self.set_name529 }530 if name in tmpdict:531 tmpdict[name](value)532 else:533 raise ValueError(name + " is not a valid attribute!")534 ##535 # Returns the dev node that this partition will have536 def get_devnode(self):537 device = self._device.get_device()538 if device[-1] in "0123456789":539 return device + "p" + str(self.get_minor())540 else:541 return device + str(self.get_minor())542 ##543 # Returns whether or not the partition is extended544 def is_extended(self):545 if self._type == "extended":546 return True547 else:548 return False549 ##550 # Returns whether or not the partition is logical551 def is_logical(self):552 if self._type == "free":553 if int(self._minor) + FREE_MINOR_FRAC_LOG == self._minor:554 return True555 else:556 return False557 elif self._device._labelinfo['extended'] and self._minor > 4:558 return True559 else:560 return False561 ##562 # Returns a list of logical partitions if this is an extended partition563 def get_logicals(self):564 if not self.is_extended():565 return None566 logicals = []567 for part in self._device._partitions:568 if part.get_minor() > 4 and not part.get_type() == "free":569 logicals.append(part.get_minor())570 return logicals571 ##572 # Returns the extened parent partition if this is a logical partition (no longer used)573 def get_extended_parent(self):574 if not self.is_logical():575 return None576 else:577 return self._device.get_partition_at(self._start, ignore_extended=0)578 ##579 # Sets the options passed to mkfs580 # @param mkfsopts Options passed to mkfs581 def set_mkfsopts(self, mkfsopts):582 self._mkfsopts = mkfsopts583 ##584 # Returns the options passes to mkfs585 def get_mkfsopts(self):586 return self._mkfsopts587 ##588 # Sets the start sector for the partition589 # @param start Start sector590 def set_start(self, start):591 self._start = long(start)592 ##593 # Returns the start sector for the partition594 def get_start(self):595 return long(self._start)596 ##597 # Sets the end sector of the partition598 # @param end End sector599 def set_end(self, end):600 self._end = long(end)601 ##602 # Returns end sector for the partition603 def get_end(self):604 return long(self._end)605 ##606 # Returns size of partition in MB607 def get_mb(self):608 return self._mb609 ##610 # Sets size of partition in MB611 # @param mb Parameter description612 def set_mb(self, mb):613 self._mb = mb614 ##615 # Sets type of partition616 # @param type Parameter description617 def set_type(self, type):618 self._type = type619 ##620 # Returns type of partition621 def get_type(self):622 return self._type623 ##624 # Returns parent GLIStorageDevice object625 def get_device(self):626 return self._device627 ##628 # Sets minor of partition629 # @param minor New minor630 def set_minor(self, minor):631 self._minor = float(minor)632 ##633 # Returns minor of partition634 def get_minor(self):635 if int(self._minor) == self._minor:636 return int(self._minor)637 else:638 return float(self._minor)639 ##640 # Sets the original minor of the partition641 # @param orig_minor Parameter description642 def set_orig_minor(self, orig_minor):643 self._orig_minor = int(orig_minor)644 ##645 # Returns the original minor of the partition646 def get_orig_minor(self):647 return self._orig_minor648 ##649 # Sets the mountpoint for the partition650 # @param mountpoint Mountpoint651 def set_mountpoint(self, mountpoint):652 self._mountpoint = mountpoint653 ##654 # Returns the mountpoint for the partition655 def get_mountpoint(self):656 return self._mountpoint657 ##658 # Sets the mount options for the partition659 # @param mountopts Mount options660 def set_mountopts(self, mountopts):661 self._mountopts = mountopts662 ##663 # Returns the mount options for the partition664 def get_mountopts(self):665 return self._mountopts666 ##667 # Set whether to format the partition668 # @param format Format this partition (True/False)669 def set_format(self, format):670 self._format = format671 ##672 # Returns whether to format the partition673 def get_format(self):674 return self._format675 ##676 # Returns whether to partition is resized677 def get_resized(self):678 return self._resized679 ##680 # Returns whether the partition is resizeable681 def is_resizeable(self):682 return self._resizeable683 ##684 # Sets partition flags685 def set_flags(self, flags):686 self._flags = flags687 ##688 # Returns partition flags689 def get_flags(self):690 return self._flags691 ##692 # Sets partition name693 def set_name(self, name):694 self._name = name695 ##696 # Returns partition name697 def get_name(self):698 return self._name699 ##700 # Returns minimum MB for resize701 def get_min_mb_for_resize(self):702# if self.is_extended():703# min_size = self._start704# for part in self._device._partitions:705# if part < 5: continue706# if part.get_end > min_size: min_size = part.get_end()707# return min_size708# else:709 if self._resizeable:710 return self._min_mb_for_resize711 else:712 return -1713 ##714 # Returns maximum MB for resize715 def get_max_mb_for_resize(self):716 if self._resizeable:717 minor_pos = self._device.get_partition_position(self._minor)718 try:719 free_minor = self._device._partitions[minor_pos+1].get_minor()720 except:721 free_minor = 0722 if not free_minor or not self._device.get_partition(free_minor).get_type() == "free": return self._mb723 if self._device.get_partition(free_minor).is_logical():724 if self.is_logical():725 return self._mb + self._device.get_partition(free_minor).get_mb()726 else:727 return self._mb728 else:729 return self._mb + self._device.get_partition(free_minor).get_mb()730 else:731 return -1732 ##733 # Resizes the partition734 # @param mb New size in MB735 def resize(self, mb):736 minor_pos = self._device.get_partition_position(self._minor)737 try:738 free_minor = self._device._partitions[minor_pos+1].get_minor()739 except:740 free_minor = 0741 if mb < self._mb:742 # Shrinking743 if not free_minor or not self._device.get_partition(free_minor).get_type() == "free":744 if self._device._disklabel == "mac":745 free_minor = self._minor + 1746 elif self.is_logical():747 free_minor = self._minor + FREE_MINOR_FRAC_LOG748 else:749 free_minor = self._minor + FREE_MINOR_FRAC_PRI750 if self._device.get_partition(free_minor):751 for i, part in enumerate(self._device._partitions):752 if i <= minor_pos or free_minor > part.get_minor(): continue753 part.set_minor(part.get_minor() + 1)754 self._device._partitions.insert(minor_pos+1, Partition(self._device, free_minor, self._mb - mb, 0, 0, "free", format=False, existing=False))755 else:756 self._device.get_partition(free_minor).set_mb(self._device.get_partition(free_minor).get_mb() + (self._mb - mb))757 self._mb = mb758 else:759 if mb == self._mb + self._device.get_partition(free_minor).get_mb():760 # Using all available unallocated space761 self._device._partitions.pop(self._device.get_partition_position(free_minor))762 self._mb = mb763 else:764 # Growing765 self._device.get_partition(free_minor).set_mb(self._device.get_partition(free_minor).get_mb() - (mb - self._mb))766 self._mb = mb767 self._resized = True...
semver.py
Source:semver.py
...16 is_max_minor = str.startswith(semver_version, '^')17 if get_major(version) == get_major(semver_version):18 if is_max_minor:19 return version20 if get_minor(version) == get_minor(semver_version):21 if is_max_build:22 return version23 if get_build(version) == get_build(semver_version):24 return version25 raise exceptions.DeploymentError('No matching semver version found in tags')26def is_valid_semver(version_string):27 return re.match(regex.get_semver_env_value_regex(), version_string)28def is_valid_static(version_string):29 return re.match(regex.get_static_version_regex(), version_string)30def sort_compare(ver1, ver2):31 if get_major(ver1) == get_major(ver2):32 if get_minor(ver1) == get_minor(ver2):33 return get_build(ver2) - get_build(ver1)34 else:35 return get_minor(ver2) - get_minor(ver1)36 else:37 return get_major(ver2) - get_major(ver1)38def get_major(version):39 return int(version.split('.')[0].replace('~', '').replace('^', ''))40def get_minor(version):41 return int(version.split('.')[1])42def get_build(version):43 build = version.split('.')[2]...
z3_dep_solver.py
Source:z3_dep_solver.py
...18 get_major(tp_a) < get_major(tp_b),19 T,20 z3.If(21 z3.And(22 get_major(tp_a) == get_major(tp_b), get_minor(tp_a) < get_minor(tp_b)23 ),24 T,25 z3.And(26 get_minor(tp_a) == get_minor(tp_b), get_micro(tp_a) < get_micro(tp_b)27 ),28 ),29 )30def le_tuple(tp_a, tp_b):31 return z3.Or(tp_a == tp_b, lt_tuple(tp_a, tp_b))32def ge_tuple(a, b):33 return le_tuple(b, a)34def gt_tuple(a, b):35 return lt_tuple(b, a)36def eq_tuple(a, b):37 return a == b38def ne_tuple(a, b):39 return a != b40def solve_deps(deps: list):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!