How to use _run_get_output method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...626 self.log.warn('version %s.%s being used is not guaranteed to '627 'work properly. Mininum required version is %s.%s.',628 current_version[0], current_version[1],629 GRUBBY_REQ_VERSION[0], GRUBBY_REQ_VERSION[1])630 def _run_get_output(self, arguments):631 '''632 Utility function that runs a command and returns command output633 '''634 if self.debug_run:635 self.log.debug('running: "%s"', ' '.join(arguments))636 result = None637 try:638 result = subprocess.Popen(arguments, shell=False,639 stdin=subprocess.PIPE,640 stdout=subprocess.PIPE,641 close_fds=True) except Exception:643 pass644 if result is not None:645 result = result.strip()646 if self.debug_run:647 logging.debug('previous command output: "%s"', result)648 else:649 self.log.error('_run_get_output error while running: "%s"',650 ' '.join(arguments))651 return result652 def _run_get_output_err(self, arguments):653 '''654 Utility function that runs a command and returns command output655 '''656 if self.debug_run:657 self.log.debug('running: "%s"', ' '.join(arguments))658 result = None659 try:660 result = subprocess.Popen(arguments, shell=False,661 stdin=subprocess.PIPE,662 stdout=subprocess.PIPE,663 stderr=subprocess.PIPE,664 close_fds=True) except Exception:666 pass667 if result is not None:668 result = result.strip()669 if self.debug_run:670 logging.debug('previous command output/error: "%s"', result)671 else:672 self.log.error('_run_get_output_err error while running: "%s"',673 ' '.join(arguments))674 return result675 def _run_get_return(self, arguments):676 '''677 Utility function that runs a command and returns status code678 '''679 if self.debug_run:680 self.log.debug('running: "%s"', ' '.join(arguments))681 result = None682 try:683 result = if self.debug_run:685 logging.debug('previous command result: %s', result)686 except OSError:687 result = -1688 self.log.error('caught OSError, returning %s', result)689 return result690 def _set_bootloader(self, bootloader=None):691 '''692 Attempts to detect what bootloader is installed on the system693 The result of this method is used in all other calls to grubby,694 so that it acts accordingly to the bootloader detected.695 '''696 if bootloader is None:697 result = self.get_bootloader()698 if result is not None:699 self.bootloader = result700 else:701 if bootloader in self.SUPPORTED_BOOTLOADERS:702 self.bootloader = bootloader703 else:704 raise ValueError('Bootloader "%s" is not supported' %705 bootloader)706 def _dist_uses_grub2(self):707 if self.get_architecture().startswith('ppc64'):708 (d_name, d_version, d_id) = platform.dist()709 if d_name.lower() == 'redhat' and d_version >= 7:710 return True711 if d_name.lower() == 'suse' and d_version >= 12:712 return True713 return False714 def _run_grubby_prepare_args(self, arguments, include_bootloader=True):715 '''716 Prepares the argument list when running a grubby command717 '''718 args = []719 if self.path is None:720 self._set_path()721 args.append(self.path)722 if self.path is not None and not os.path.exists(self.path):723 self.log.error('grubby executable does not exist: "%s"', self.path)724 if not os.access(self.path, os.R_OK | os.X_OK):725 self.log.error('insufficient permissions (read and execute) '726 'for grubby executable: "%s"', self.path)727 # If a bootloader has been detected, that is, a mode has been set,728 # it's passed as the first command line argument to grubby729 if include_bootloader and self.bootloader is not None:730 args.append('--%s' % self.bootloader)731 # Override configuration file732 if self.opts is not None and self.opts.config_file:733 args.append('--config-file=%s' % self.opts.config_file)734 elif self._dist_uses_grub2():735 args.append('--config-file=/boot/grub2/grub.cfg')736 args += arguments737 return args738 def _run_grubby_get_output(self, arguments, include_bootloader=True):739 '''740 Utility function that runs grubby with arguments and returns output741 '''742 args = self._run_grubby_prepare_args(arguments, include_bootloader)743 return self._run_get_output(args)744 def _run_grubby_get_return(self, arguments, include_bootloader=True):745 '''746 Utility function that runs grubby with and returns status code747 '''748 args = self._run_grubby_prepare_args(arguments, include_bootloader)749 return self._run_get_return(args)750 def _extract_tarball(self, tarball, directory):751 '''752 Extract tarball into the an directory753 This code assume the first (or only) entry is the main directory754 :type tarball: string755 :param tarball: tarball file path756 :type directory: string757 :param directory: directory path...

Full Screen

Full Screen Github


Full Screen

...43from build_model import BuildSpec44from config import DATA_DIR, OS_WIN, HOSTOS45from run_vars import MLSDK, runtime_values, MAKE46TEMPLATES_DIR = os.path.join(DATA_DIR, 'templates')47def _run_get_output(verbose, args, config=None):48 my_args = list(args)49 # replace generic 'mabu' with another invocation50 if my_args[0] == 'mabu':51 import mabu52 mabu_path = []53 def add_user_path(path):54 mabu_path.append(path)55 build_env.iterate_search_path(add_user_path, lambda: False, lambda _: False)56 # find base.comp last57 mabu_path.append(os.path.join(TEMPLATES_DIR, 'default'))58 # modify the build spec per the supplied config59 if config:60 my_spec = BuildSpec(str(build_env.spec()), config=config)61 else:62 my_spec = build_env.spec()63 my_args[0:1] = [64 sys.executable,65 mabu.__file__,66 '-t',67 str(my_spec),68 '--path',69 os.pathsep.join(mabu_path)70 ]71 # run, but stifle embedded prints, only printing on error72 myenv = os.environ.copy()73 myenv['PYTHONPATH'] = os.pathsep.join(sys.path)74 cmp =,75 stdout=subprocess.PIPE, stderr=subprocess.PIPE,76 universal_newlines=True, env=myenv)77 if cmp.returncode != 0:78 diags.error("failed to invoke mabu subprocess:\n{}{}".format(79 cmp.stdout, cmp.stderr80 ))81 return None82 if verbose:83"{} yielded:\n{}".format(utils.format_command_line(my_args), cmp.stdout))84 return cmp.stdout85def _parse_assignments(text):86 """87 Read a set of VAR=VALUE lines and create a map.88 :param text:89 :rtype: dict[str,str]90 """91 vars = {}92 for line in text.split('\n'):93 line = line.strip()94 try:95 idx = line.index('=')96 var = line[0:idx]97 value = line[idx+1:]98 # remove some mabu escapes99 value = value.replace("'", "")100 value = value.replace("$$", "$")101 vars[var] = value102 except ValueError:103 pass104 return vars105def _canonicalize(path):106 c = os.path.realpath(path)107 if HOSTOS == OS_WIN:108 # realpath doesn't correct capitalization.109 # for our purposes, this is safe.110 c = c.lower()111 # cmake strings interpret slashes, so, forward-slasherize these112 c = c.replace('\\', '/')113 return c114def _fetch_toolchains(verbose, cmake_vars):115 toolchains = _run_get_output(verbose, ['mabu', '-q', '--print-tools'])116 if verbose:117"Toolchains:\n{}".format(toolchains))118 tool_vars = _parse_assignments(toolchains)119 if 'CC' not in tool_vars:120 diags.error("Did not detect CC in mabu --print-tools (run with '-v' or '--debug')")121 if 'CXX' not in tool_vars:122 diags.error("Did not detect CXX in mabu --print-tools (run with '-v' or '--debug')")123 cmake_vars['CMAKE_MAKE_PROGRAM'] = _canonicalize(runtime_values[MAKE])124 cmake_vars['CMAKE_C_COMPILER'] = _canonicalize(tool_vars['CC'])125 cmake_vars['CMAKE_CXX_COMPILER'] = _canonicalize(tool_vars['CXX'])126 cmake_vars['CMAKE_AR'] = _canonicalize(tool_vars.get('AR', 'ar'))127 cmake_vars['CMAKE_RANLIB'] = _canonicalize(tool_vars.get('RANLIB', 'ranlib'))128 bin_dir, _ = os.path.split(cmake_vars['CMAKE_C_COMPILER'])129 cmake_vars['TOOLS_BIN'] = bin_dir130def _fetch_settings(verbose, cmake_type, mabu_kind, cmake_vars):131 project = os.path.join(TEMPLATES_DIR, 'empty_{}.mabu'.format(mabu_kind))132 settings = _run_get_output(verbose,133 ['mabu', '-q', '--print-build-vars', project],134 config='blank')135 if verbose:136"Settings for {}:\n{}".format(mabu_kind, settings))137 if verbose:138"Release settings for {}:\n{}".format(mabu_kind, settings))139 prj_vars = _parse_assignments(settings)140 if mabu_kind == kinds.program.NAME:141 # assume the program flags apply to any build (let cmake figure out '-fPIC' and such)142 # record where we found these settings143 base = build_env.find_component_on_path(None, 'base') or os.path.join(TEMPLATES_DIR, 'default', 'base.comp')144 cmake_vars['MABU_BASE'] = base.replace('\\', '/')145 cmake_vars['MABU_SETTINGS'] = settings.replace('\r', '').replace('\n', '\n# ')146 cmake_vars['MABU_TEMPLATE'] = project...

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:


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

Run autotest 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?