How to use get_fs_block_size method in lisa

Best Python code snippet using lisa_python

rdbtool.py

Source:rdbtool.py Github

copy

Full Screen

...318 elif not empty:319 return True320 else:321 return None322 def get_fs_block_size(self, empty=False):323 if 'bs' in self.popts:324 return int(self.popts['bs'])325 elif not empty:326 return 512327 else:328 return None329 def get_flags(self, empty=False, old_flags=0):330 flags = 0331 bootable = self.get_bootable(empty=empty)332 if bootable is not None:333 if bootable:334 flags |= PartitionBlock.FLAG_BOOTABLE335 else:336 flags |= (old_flags) & PartitionBlock.FLAG_BOOTABLE337 automount = self.get_automount(empty=empty)338 if automount is not None:339 if not automount:340 flags |= PartitionBlock.FLAG_NO_AUTOMOUNT341 else:342 flags |= (old_flags) & PartitionBlock.FLAG_NO_AUTOMOUNT343 return flags344 def get_more_dos_env(self):345 more_dos_env = []346 valid_keys = PartitionDosEnv.valid_keys347 for key in self.popts:348 if key in valid_keys:349 more_dos_env.append((key, self.popts[key]))350 if len(more_dos_env) > 0:351 return more_dos_env352 else:353 return None354 def get_more_dos_env_info(self):355 valid_keys = PartitionDosEnv.valid_keys356 info = ["[%s=<n>]" % x for x in valid_keys]357 return " ".join(info)358 def get_cyl_range(self):359 start = None360 if 'start' in self.popts:361 start = int(self.popts['start'])362 # range with start=<n> end=<n>363 if 'end' in self.popts:364 end = int(self.popts['end'])365 if start == None or end <= start:366 return None367 else:368 return (start, end)369 # expect a size370 elif 'size' in self.popts:371 size = self.popts['size']372 cyls = None373 if type(size) == int:374 cyls = size375 # size in bytes376 elif size[-1] in ('b','B'):377 num_bytes = ByteSize.parse_byte_size_str(size[:-1])378 if num_bytes == None:379 return None380 cyls = num_bytes // self.rdisk.get_cylinder_bytes()381 # size in percent382 elif size[-1] == '%':383 prc = float(size[:-1])384 cyls = int(prc * self.rdisk.get_logical_cylinders() / 100.0)385 # size in cylinders386 else:387 cyls = ByteSize.parse_byte_size_str(size)388 # check cyls389 if cyls == None or cyls < 1:390 return None391 # find a range if no start is given392 if start == None:393 start = self.rdisk.find_free_cyl_range_start(cyls)394 if start == None:395 return None396 return (start, start + cyls - 1)397 # nothing specified -> get next free range398 else:399 ranges = self.rdisk.get_free_cyl_ranges()400 if ranges == None:401 return None402 return ranges[0]403class AddCommand(PartEditCommand):404 def handle_rdisk(self, rdisk):405 self.parse_opts(rdisk)406 lo_hi = self.get_cyl_range()407 if lo_hi == None:408 print("ERROR: invalid partition range given!")409 return 1410 dostype = self.get_dos_type()411 if dostype == None:412 print("ERROR: invalid dos type!")413 return 1414 drv_name = self.get_drv_name()415 if drv_name == None:416 print("ERROR: invalid drive name!")417 flags = self.get_flags()418 boot_pri = self.get_boot_pri()419 more_dos_env = self.get_more_dos_env()420 fs_bs = self.get_fs_block_size(empty=True)421 print("creating: '%s' %s %s" % (drv_name, lo_hi, num_to_tag_str(dostype)))422 # add partition423 if rdisk.add_partition(drv_name, lo_hi, dos_type=dostype, flags=flags,424 boot_pri=boot_pri, more_dos_env=more_dos_env,425 fs_block_size=fs_bs):426 return 0427 else:428 print("ERROR: creating partition: '%s': %s" % (drv_name, lo_hi))429 return 1430class ChangeCommand(PartEditCommand):431 def handle_rdisk(self, rdisk):432 if len(self.opts) < 1:433 print("Usage: change <id> [name=<s>] [dostype=<n|tag>] [automount=<b>] [bootable=<b>] [pri=<n>] " + self.get_more_dos_env_info())434 return 1435 else:436 p = rdisk.find_partition_by_string(self.opts[0])437 if p != None:438 self.parse_opts(rdisk)439 dostype = self.get_dos_type(empty=True)440 drv_name = self.get_drv_name(empty=True)441 flags = self.get_flags(empty=True, old_flags=p.get_flags())442 boot_pri = self.get_boot_pri(empty=True)443 fs_bs = self.get_fs_block_size(empty=True)444 more_dos_env = self.get_more_dos_env()445 # change partition446 if rdisk.change_partition(p.num, drv_name=drv_name, dos_type=dostype,447 flags=flags, boot_pri=boot_pri,448 more_dos_env=more_dos_env,449 fs_block_size=fs_bs):450 return 0451 else:452 print("ERROR: changing partition: '%s'" % (drv_name))453 return 1454 else:455 print("Can't find partition: '%s'" % self.opts[0])456 return 1457# --- Export/Import file system image ---458class ExportCommand(Command):459 def handle_rdisk(self, rdisk):460 if len(self.opts) < 2:461 print("Usage: export <partition> <file>")462 return 1463 else:464 part = self.opts[0]465 file_name = self.opts[1]466 p = rdisk.find_partition_by_string(part)467 if p != None:468 blkdev = p.create_blkdev()469 blkdev.open()470 num_blks = blkdev.num_blocks471 print("exporting '%s' (%d blocks) to '%s'" % \472 (p.get_drive_name(), num_blks, file_name))473 try:474 with open(file_name, "wb") as fh:475 for b in range(num_blks):476 data = blkdev.read_block(b)477 fh.write(data)478 except IOError as e:479 print("Error writing file: '%s': %s" % (file_name, e))480 return 1481 blkdev.close()482 return 0483 else:484 print("Can't find partition: '%s'" % part)485 return 1486class ImportCommand(Command):487 def handle_rdisk(self, rdisk):488 if len(self.opts) < 2:489 print("Usage: import <partition> <file>")490 return 1491 else:492 part = self.opts[0]493 file_name = self.opts[1]494 p = rdisk.find_partition_by_string(part)495 if p != None:496 part_dev = p.create_blkdev()497 part_dev.open()498 part_blks = part_dev.num_blocks499 blk_size = part_dev.block_bytes500 total = part_blks * blk_size501 # open image502 file_size = os.path.getsize(file_name)503 file_blks = file_size // blk_size504 if file_size % blk_size != 0:505 print("image file not block size aligned!")506 return 1507 # check sizes508 if total < file_size:509 print("import image too large: partition=%d != file=%d",510 total, file_size)511 return 1512 if total > file_size:513 delta = total - file_size514 print("WARNING: import file too small: %d unused blocks", delta)515 print("importing '%s' (%d blocks) to '%s' (%d blocks)" % \516 (file_name, file_blks, p.get_drive_name(), part_blks))517 # copy image518 with open(file_name, "rb") as fh:519 for b in range(file_blks):520 data = fh.read(blk_size)521 part_dev.write_block(b, data)522 part_dev.close()523 return 0524 else:525 print("Can't find partition: '%s'" % part)526 return 1527# --- Fill empty space with partitions ---528class FillCommand(PartEditCommand):529 def handle_rdisk(self, rdisk):530 self.parse_opts(rdisk)531 ranges = rdisk.get_free_cyl_ranges()532 # nothing to do533 if ranges == None:534 return 0535 for lo_hi in ranges:536 drv_name = self.get_drv_name()537 if drv_name == None:538 print("ERROR: invalid drive name!")539 dostype = self.get_dos_type()540 if dostype == None:541 print("ERROR: invalid dostype given!")542 return 1543 flags = self.get_flags()544 boot_pri = self.get_boot_pri()545 more_dos_env = self.get_more_dos_env()546 fs_bs = self.get_fs_block_size(empty=True)547 print("creating: '%s' %s %s" % (drv_name, lo_hi, num_to_tag_str(dostype)))548 # add partition549 if not rdisk.add_partition(drv_name, lo_hi, dos_type=dostype, flags=flags,550 boot_pri=boot_pri, more_dos_env=more_dos_env,551 fs_block_size=fs_bs):552 print("ERROR: creating partition: '%s': %s" % (drv_name, lo_hi))553 return 1554 return 0555# --- Delete partition command ---556class DeleteCommand(Command):557 def __init__(self, args, opts):558 Command.__init__(self, args, opts, edit=True)559 def handle_rdisk(self, rdisk):560 if len(self.opts) < 1:...

Full Screen

Full Screen

stat.py

Source:stat.py Github

copy

Full Screen

...14 posix_os: Posix = cast(Posix, self.node.os)15 package_name = "coreutils"16 posix_os.install_packages(package_name)17 return self._check_exists()18 def get_fs_block_size(self, file: str) -> int:19 cmd_result = self.run(20 "-f --format='%S' " f"{file}",21 force_run=True,22 expected_exit_code=0,23 expected_exit_code_failure_message=(24 f"fail to get block size of {file} in file system"25 ),26 )27 return int(cmd_result.stdout)28 def get_fs_available_size(self, file: str) -> int:29 cmd_result = self.run(30 "-f --format='%a' " f"{file}",31 force_run=True,32 expected_exit_code=0,...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful