Best Python code snippet using autotest_python
boottool.py
Source:boottool.py
...1581 value = getattr(opts, action)1582 if value is not None:1583 has_action = True1584 return has_action1585 def opts_get_action(self, opts):1586 '''1587 Gets the selected action from the parsed opts1588 '''1589 global ACTIONS_OPT_METHOD_NAME1590 for action in ACTIONS_OPT_METHOD_NAME:1591 value = getattr(opts, action)1592 if value is not None:1593 return action1594 return None1595 def check_values(self, opts, args):1596 '''1597 Validate the option the user has supplied1598 '''1599 # check if an action has been selected1600 if not self.opts_has_action(opts):1601 self.print_help()1602 raise SystemExit1603 # check if action needs a --title option1604 action = self.opts_get_action(opts)1605 if action in ACTIONS_REQUIRE_TITLE:1606 if opts.title is None:1607 print 'Action %s requires a --title parameter' % action1608 raise SystemExit1609 return (opts, args)1610class BoottoolApp(object):1611 '''1612 The boottool application itself1613 '''1614 def __init__(self):1615 self.opts = None1616 self.args = None1617 self.option_parser = OptionParser()1618 self.grubby = None1619 self.log = logging.getLogger(self.__class__.__name__)1620 def _parse_command_line(self):1621 '''1622 Parsers the command line arguments1623 '''1624 (self.opts,1625 self.args) = self.option_parser.parse_args()1626 def _configure_logging(self):1627 '''1628 Configures logging based on --debug= command line switch1629 We do not have as many levels as the original boottool(.pl) had, but1630 we accept the same range of parameters and adjust it to our levels.1631 '''1632 log_map = {0: logging.WARNING,1633 1: logging.INFO,1634 2: logging.DEBUG}1635 try:1636 level = int(self.opts.debug)1637 except ValueError:1638 level = 01639 max_level = max(log_map.keys())1640 if level > max_level:1641 level = max_level1642 if os.environ.has_key('BOOTTOOL_DEBUG_RUN'):1643 logging_level = logging.DEBUG1644 else:1645 logging_level = log_map.get(level)1646 logging.basicConfig(level=logging_level,1647 format=LOGGING_FORMAT)1648 def run(self):1649 self._parse_command_line()1650 self._configure_logging()1651 # if we made this far, the command line checking succeeded1652 if self.opts.grubby_path:1653 self.grubby = Grubby(self.opts.grubby_path, self.opts)1654 else:1655 install_grubby_if_necessary()1656 self.grubby = Grubby(opts=self.opts)1657 if self.opts.bootloader:1658 self.log.debug('Forcing bootloader "%s"', self.opts.bootloader)1659 try:1660 self.grubby._set_bootloader(self.opts.bootloader)1661 except ValueError as msg:1662 self.log.error(msg)1663 sys.exit(-1)1664 #1665 # The following implements a simple action -> method dispatcher1666 # First, we look for a method named action_ + action_name on the1667 # app instance itself. If not found, we try to find a method with1668 # the same name as the action in the grubby instance.1669 #1670 action_name = self.option_parser.opts_get_action(self.opts)1671 try:1672 action_method = getattr(self, "action_%s" % action_name)1673 except AttributeError:1674 action_method = getattr(self.grubby, action_name)1675 if action_method:1676 result = action_method()1677 if result is None:1678 result = 01679 elif isinstance(result, str):1680 print result1681 result = 01682 sys.exit(result)1683 #1684 # The following block implements actions. Actions are methods that will be...
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!!