Best Python code snippet using lisa_python
strip_binaries.py
Source:strip_binaries.py  
...69    print('Stripping binaries:')70    for root, dirs, files in walk(bin_path):71        for name in files:72            _strip_libs(join(root, name), plt_path)73def _get_kernel_version():74    from os import uname75    _, _, release, _, _ = uname()76    return release77def _make_archive(version):78    """Make archive of platforms/.../bin and platforms/.../lib folders"""79    from os import chdir80    from subprocess import call81    from os.path import join82    from sys import stdout83    from shutil import move84    # Name of the archive is:85    # v<OF version>-D<OS X kernel version>[-ls<WM_LABEL_SIZE>]<option>.tar.xz86    # where87    #   OF version: OpenFOAM version88    #   OS X kernel version: Version of OS X kernel where binaries were built89    #   For version 3.0.0 and higher value of WM_LABEL_SIZE is also added90    #   option is optimization level: opt, debug, prof91    if version not in ['dev', 'v3.0+']:92        major = version.split('.')[0]93    else:94        major = 99995    _dir, _opts, copt, label_size = _read_environment(version)96    lib_path = join('platforms', _opts, 'lib')97    bin_path = join('platforms', _opts, 'bin')98    filename_fmt = 'v{0}-r{1}{2}-{3}.tar.bz2'99    if version == 'dev' or version.endswith('x'):100        from mkpatches import COMMITS101        if version in COMMITS['ROLLING'].keys():102            filename_fmt = 'v{{0}}-{0}-r{{1}}{{2}}-{{3}}.tar.bz2'.format(103                COMMITS['ROLLING'][version]104            )105    if int(major) >= 3:106        filename = filename_fmt.format(version, _get_kernel_version(),107                                       '-ls{0}'.format(label_size),108                                       copt.lower())109    else:110        filename = filename_fmt.format(version, _get_kernel_version(), '',111                                       copt.lower())112    chdir('OpenFOAM-{0}'.format(version))113    print('Creating archive {0} ... '.format(filename), end='')114    stdout.flush()115    call(['tar', 'cjf', filename, lib_path, bin_path])116    move(filename, '..')117    print('done.')118    chdir('..')119def _run():120    from argparse import ArgumentParser121    parser = ArgumentParser(122        description='Strip library paths from binary files.')123    parser.add_argument('-i', '--in-place', action='store_false',124                        dest='backup',...ssh_handler.py
Source:ssh_handler.py  
...30            cmd = self._get_packages()31        elif cmd_str == "hw_details":32            cmd = self._get_hardware_details()33        elif cmd_str == "kernel_version":34            cmd = self._get_kernel_version()35        print(f'[DEBUG] Running command {cmd} on host {self.host}')36        stdin, stdout, stderr = self.ssh_client.exec_command(cmd)37        # store the information in a temp file38        with open(cmd_str+".log", 'w') as file:39            file.write(stdout.read().decode("utf8"))40        41        print(f'Return Code: {stdout.channel.recv_exit_status()}')42        # free up the file objects when done43        stdin.close()44        stdout.close()45        stderr.close()46        # Add the command output file to the zip archive47        self.zip_file.write(cmd_str+".log")48    # Functions to generate command strings for each operation that is to be49    # performed on a remote host50    def _get_var_log(self):51        return "cat /var/log/messages"52    def _get_ps_aux(self):53        return "ps aux"54    def _get_packages(self):55        return "yum list installed"56    def _get_hardware_details(self):57        return "lshw"58    def _get_kernel_version(self):...scankernel.py
Source:scankernel.py  
1from leapp.libraries.common.config.version import get_target_major_version, is_rhel_realtime2from leapp.libraries.stdlib import api, CalledProcessError, run3from leapp.models import InstalledTargetKernelVersion4def _get_kernel_version(kernel_name):5    try:6        kernels = run(['rpm', '-q', kernel_name], split=True)['stdout']7    except CalledProcessError:8        return ''9    for kernel in kernels:10        # name-version-release - we want the last two fields only11        version = '-'.join(kernel.split('-')[-2:])12        if 'el{}'.format(get_target_major_version()) in version:13            return version14    return ''15def process():16    # pylint: disable=no-else-return  - false positive17    # TODO: should we take care about stuff of kernel-rt and kernel in the same18    # time when both are present? or just one? currently, handle only one19    # of these during the upgrade. kernel-rt has higher prio when original sys20    # was realtime21    if is_rhel_realtime():22        version = _get_kernel_version('kernel-rt')23        if version:24            api.produce(InstalledTargetKernelVersion(version=version))25            return26        else:27            api.current_logger().warning(28                'The kernel-rt rpm from the target RHEL has not been detected. '29                'Switching to non-preemptive kernel.'30            )31            # TODO: create report with instructions to install kernel-rt manually32            # - attach link to article if any33            # - this possibly happens just in case the repository with kernel-rt34            # # is not enabled during the upgrade.35    # standard (non-preemptive) kernel36    version = _get_kernel_version('kernel')37    if version:38        api.produce(InstalledTargetKernelVersion(version=version))39    else:40        # This is very unexpected situation. At least one kernel has to be41        # installed always. Some actors consuming the InstalledTargetKernelVersion42        # will crash without the created message. I am keeping kind of original43        # behaviour in this case, but at least the let me log the error msg44        #45        api.current_logger().error('Cannot detect any kernel RPM')...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!!
