Best Python code snippet using autotest_python
service.py
Source:service.py
...571 except NameError:572 result_parser = _result_parsers[get_name_of_init(run)]573 _service_result_parser = _ServiceResultParser(result_parser)574 return _service_result_parser575def _get_service_command_generator(run=utils.run):576 """577 Lazy initializer for ServiceCommandGenerator using the auto-detect init command.578 :return: ServiceCommandGenerator for the current init command.579 :rtype: _ServiceCommandGenerator580 """581 # _service_command_generator is explicitly undefined so that we get the NameError on first access582 # pylint: disable=W0601583 global _service_command_generator584 try:585 return _service_command_generator586 except NameError:587 command_generator = _command_generators[get_name_of_init(run)]588 _service_command_generator = _ServiceCommandGenerator(589 command_generator)590 return _service_command_generator591def ServiceManager(run=utils.run):592 """593 Detect which init program is being used, init or systemd and return a594 class has methods to start/stop services.595 # Get the system service manager596 service_manager = ServiceManager()597 # Stating service/unit "sshd"598 service_manager.start("sshd")599 # Getting a list of available units600 units = service_manager.list()601 # Disabling and stopping a list of services602 services_to_disable = ['ntpd', 'httpd']603 for s in services_to_disable:604 service_manager.disable(s)605 service_manager.stop(s)606 :return: SysVInitServiceManager or SystemdServiceManager607 :rtype: _GenericServiceManager608 """609 service_manager = _service_managers[get_name_of_init(run)]610 # _service_command_generator is explicitly undefined so that we get the NameError on first access611 # pylint: disable=W0601612 global _service_manager613 try:614 return _service_manager615 except NameError:616 _service_manager = service_manager(_get_service_command_generator(run),617 _get_service_result_parser(run))618 return _service_manager619def _auto_create_specific_service_result_parser(run=utils.run):620 """621 Create a class that will create partial functions that generate result_parser622 for the current init command.623 :return: A ServiceResultParser for the auto-detected init command.624 :rtype: _ServiceResultParser625 """626 result_parser = _result_parsers[get_name_of_init(run)]627 # remove list method628 command_list = [c for c in COMMANDS if c not in ["list", "set_target"]]629 return _ServiceResultParser(result_parser, command_list)630def _auto_create_specific_service_command_generator(run=utils.run):...
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!!