Python subprocess.getstatusoutput() Examples

The following are 30 code examples of subprocess.getstatusoutput(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module subprocess , or try the search function .
Example #1
Source File: partial.py    From MySQL-AutoXtraBackup with MIT License 7 votes vote down vote up
def check_innodb_file_per_table(self):
        """
        Function for checking MySQL innodb_file_per_table option.
        It is needed for "Transportable Tablespace" concept.
        :return: True/False
        """
        statement = "select @@global.innodb_file_per_table"
        run_command = self.create_mysql_client_command(statement=statement)

        logger.info("Checking if innodb_file_per_table is enabled")
        status, output = subprocess.getstatusoutput(run_command)

        if status == 0 and int(output[-1]) == 1:
            logger.info("OK: innodb_file_per_table is enabled!")
            return True
        elif status == 0 and int(output[-1]) == 0:
            logger.info("OK: innodb_file_per_table is disabled!")
            return False
        else:
            logger.error("FAILED: InnoDB file per-table Check")
            logger.error(output)
            raise RuntimeError("FAILED: InnoDB file per-table Check") 
Example #2
Source File: partial.py    From MySQL-AutoXtraBackup with MIT License 6 votes vote down vote up
def check_mysql_version(self):
        """
        Function for checking MySQL version.
        Version must be >= 5.6 for using "Transportable Tablespace" concept.
        :return: True/False
        """
        statement = "select @@version"
        run_command = self.create_mysql_client_command(statement=statement)

        logger.info("Checking MySQL version")
        status, output = subprocess.getstatusoutput(run_command)

        if status == 0 and ('5.6' in output):
            logger.info("You have correct version of MySQL")
            return True
        elif status == 0 and ('5.7' in output):
            logger.info("You have correct version of MySQL")
            return True
        elif status == 0 and ('5.7' not in output) and ('5.6' not in output):
            logger.error("Your MySQL server is not supported. MySQL version must be >= 5.6")
            raise RuntimeError("Your MySQL server is not supported. MySQL version must be >= 5.6")
        else:
            logger.error("FAILED: MySQL version check")
            logger.error(output)
            raise RuntimeError("FAILED: MySQL version check") 
Example #3
Source File: clone_build_start_server.py    From MySQL-AutoXtraBackup with MIT License 6 votes vote down vote up
def prepare_startup(self, basedir_path):
        # Method for calling startup.sh file from percona-qa folder
        saved_path = os.getcwd()
        os.chdir(basedir_path)

        startup_cmd = "{}/percona-qa/startup.sh"
        logger.debug("Started to run startup.sh file...")
        status, output = subprocess.getstatusoutput(startup_cmd.format(self.testpath))
        if status == 0:
            logger.debug("Running startup.sh succeeded")
            os.chdir(saved_path)
            return True
        else:
            logger.error("Running startup.sh failed")
            logger.error(output)
            os.chdir(saved_path)
            return False 
Example #4
Source File: clone_build_start_server.py    From MySQL-AutoXtraBackup with MIT License 6 votes vote down vote up
def prepare_start_dynamic(basedir_path):
        # Method for calling start_dynamic.sh from basedir.
        # It will generate start_dynamic executables in basedir.
        saved_path = os.getcwd()
        dir_path = os.path.dirname(os.path.realpath(__file__))
        os.chdir(basedir_path)
        start_dynamic = "{}/start_dynamic.sh".format(dir_path)
        logger.debug("Running start_dynamic.sh here...")
        status, output = subprocess.getstatusoutput(start_dynamic)
        if status == 0:
            logger.debug("Running start_dynamic.sh succeeded")
            os.chdir(saved_path)
            return True
        else:
            logger.error("Running start_dynamic.sh failed")
            logger.error(output)
            os.chdir(saved_path)
            return False 
Example #5
Source File: clone_build_start_server.py    From MySQL-AutoXtraBackup with MIT License 6 votes vote down vote up
def wipe_server_all(basedir_path, options=None):
        # Method for calling "all" script which is created inside PS basedir
        saved_path = os.getcwd()
        os.chdir(basedir_path)
        logger.debug("Using all_no_cl script here...")
        if options is not None:
            all_cmd = "./all_no_cl {}"
            status, output = subprocess.getstatusoutput(all_cmd.format(options))
        else:
            all_cmd = "./all_no_cl"
            status, output = subprocess.getstatusoutput(all_cmd)
        if status == 0:
            logger.debug("Server wiped for fresh start!")
            os.chdir(saved_path)
            return True
        else:
            logger.error("All script run failed")
            logger.error(output)
            os.chdir(saved_path)
            return False 
Example #6
Source File: clone_build_start_server.py    From MySQL-AutoXtraBackup with MIT License 6 votes vote down vote up
def extract_xb_archive(self, file_name):
        # General method for extracting XB archives
        # It will create target folder inside test path
        extract_cmd = "tar -xf {}/{} -C {}"
        if os.path.isfile("{}/{}".format(self.testpath, file_name)):
            if not os.path.isdir("{}/target/{}".format(self.testpath, file_name[:-7])):
                status, output = subprocess.getstatusoutput(extract_cmd.format(self.testpath, file_name, self.testpath))
                if status == 0:
                    logger.debug("Extracted from {}".format(file_name))
                    return True
                else:
                    logger.error("Failed to extract from {}".format(file_name))
                    logger.error(output)
                    return False
            else:
                logger.debug("The 'target' folder already there...")
                return True
        else:
            logger.debug("Could not find {}".format(file_name))
            return False 
Example #7
Source File: adb.py    From mass-apk-installer with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def exec_command(self, cmd, return_stdout=False, case_sensitive=False, silence_errors=False) -> Optional[str]:
        """Low level function to send shell commands to running adb-server process.

        :raises AdbError
        """

        cmd = f"{self._path} {cmd}"
        log.info("Executing " + cmd)
        return_code, output = subprocess.getstatusoutput(cmd)

        if return_code:
            if silence_errors:
                log.error(output)
                return None

            if output is None:
                log.warning(f"command returned error code {return_code}, but no output, {cmd}")
                raise AdbError(f"Command returned error code {cmd}")

            raise AdbError(output + f" {cmd}")

        if return_stdout:
            return output.lower() if case_sensitive else output

        return None 
Example #8
Source File: operator_install.py    From hpe-solutions-openshift with Apache License 2.0 6 votes vote down vote up
def get_token(oc_path):
    """
    Get authentication token from OC command line tool

    Returns:
    The bearer token to the init_setup function

    """
    global USER_NAME, PASSWORD, IP
    print("Logging into your OpenShift Cluster")
    status, _ = subprocess.getstatusoutput(oc_path + "oc login "+IP+" -u "+USER_NAME+" -p "+ \
        PASSWORD +" --insecure-skip-tls-verify=true")
    if status == 0:
        print("Successfully logged into the OpenShift Cluster")
    else:
        print("Could not login, please enter correct login credentials")
        exit(1)
    token = subprocess.getoutput(oc_path + "oc whoami -t")

    return token

#General Function for get calls 
Example #9
Source File: clone_build_start_server.py    From MySQL-AutoXtraBackup with MIT License 6 votes vote down vote up
def clone_pxb(self):
        # Clone PXB from github based on branch values from config file.
        pxb_branches = self.pxb_branches.split()
        for branch in pxb_branches:
            clone_cmd = "git clone {} -b {} {}/PXB-{}"
            if not os.path.exists("{}/PXB-{}".format(self.testpath, branch)):
                logger.debug("Started to clone PXB...")
                status, output = subprocess.getstatusoutput(
                    clone_cmd.format(self.pxb_gitcmd, branch, self.testpath, branch))
                if status == 0:
                    logger.debug("PXB-{} cloned ready to build".format(branch))
                else:
                    logger.error("Cloning PXB-{} failed".format(branch))
                    logger.error(output)
                    return False
        return True 
Example #10
Source File: prepare.py    From MySQL-AutoXtraBackup with MIT License 6 votes vote down vote up
def start_mysql_func(self, start_tool=None, options=None):
        # Starting MySQL
        logger.info("Starting MySQL server: ")
        if start_tool is None:
            args = self.start_mysql
        else:
            args = start_tool

        if options is not None:
            start_command = "{} {}".format(args, options)
        else:
            start_command = args
        status, output = subprocess.getstatusoutput(start_command)
        if status == 0:
            logger.info("Starting MySQL ...")
            logger.info(output)
            return True
        else:
            logger.error("Error occurred while starting MySQL!")
            logger.error(output)
            raise RuntimeError("Error occurred while starting MySQL!") 
Example #11
Source File: runner_test_mode.py    From MySQL-AutoXtraBackup with MIT License 6 votes vote down vote up
def create_slave_shutdown_file(basedir, num):
        """
        Static method for creating shutdown file for slave
        :param basedir: Basedir path
        :param num: The number for slave
        :return: True on success
        :raise: RuntimeError on fail
        """
        with open("{}/stop_node{}".format(basedir, num), 'w+') as stop_file:
            shutdown_slave = "{}/bin/mysqladmin -uroot -S{}/sock{}.sock shutdown".format(basedir, basedir, num)
            stop_file.write(shutdown_slave)
            # give u+x to this file
            chmod = "chmod u+x {}/stop_node{}".format(basedir, num)
            status, output = subprocess.getstatusoutput(chmod)

            if status == 0:
                logger.debug("chmod succeeded for {}/stop_node{}".format(basedir, num))
                return True
            else:
                raise RuntimeError("Failed to chmod {}/stop_node{}".format(basedir, num)) 
Example #12
Source File: services.py    From WordOps with MIT License 6 votes vote down vote up
def stop_service(self, service_name):
        """
            Stop service
            Similar to `service xyz stop`
        """
        try:
            Log.info(self, "Stop  : {0:10}" .format(service_name), end='')
            retcode = subprocess.getstatusoutput('service {0} stop'
                                                 .format(service_name))
            if retcode[0] == 0:
                Log.info(self, "[" + Log.ENDC + Log.OKGREEN + "OK" +
                         Log.ENDC + Log.OKBLUE + "]")
                return True
            else:
                Log.debug(self, "{0}".format(retcode[1]))
                Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE + "]")
                return False
        except OSError as e:
            Log.debug(self, "{0}".format(e))
            Log.error(self, "\nFailed to stop service : {0}"
                      .format(service_name)) 
Example #13
Source File: srm.py    From rucio with Apache License 2.0 6 votes vote down vote up
def connect(self):
        """
        Establishes the actual connection to the referred RSE.
        As a quick and dirty impelementation we just use this method to check if the lcg tools are available.
        If we decide to use gfal, init should be done here.

        :raises RSEAccessDenied: Cannot connect.
        """

        status, lcglscommand = getstatusoutput('which lcg-ls')
        if status:
            raise exception.RSEAccessDenied('Cannot find lcg tools')
        endpoint_basepath = self.path2pfn(self.attributes['prefix'])
        status, result = getstatusoutput('%s -vv $LCGVO -b --srm-timeout 60 -D srmv2 -l %s' % (lcglscommand, endpoint_basepath))
        if status:
            if result == '':
                raise exception.RSEAccessDenied('Endpoint not reachable. lcg-ls failed with status code %s but no further details.' % (str(status)))
            else:
                raise exception.RSEAccessDenied('Endpoint not reachable : %s' % str(result)) 
Example #14
Source File: versions.py    From codimension with GNU General Public License v3.0 6 votes vote down vote up
def getPlantUMLVersion():
    """Provides the plantUML version"""
    if JAR_PATH is None:
        return "n/a", None

    try:
        status, output = getstatusoutput('java -jar ' + JAR_PATH + ' -version')
        if status != 0:
            return "n/a", None

        for line in output.splitlines():
            # PlantUML version 1.2019.05 (Sat Apr 20 11:45:36 GMT-05:00 2019)
            line = line.strip()
            if line.startswith('PlantUML version'):
                return line.split('version', 1)[1].strip(), JAR_PATH
    except:
        return "n/a", None
    return "could not determine", JAR_PATH 
Example #15
Source File: services.py    From WordOps with MIT License 6 votes vote down vote up
def get_service_status(self, service_name):

        try:
            is_exist = subprocess.getstatusoutput('command -v {0}'
                                                  .format(service_name))
            if is_exist[0] == 0 or service_name in ['php7.2-fpm',
                                                    'php7.3-fpm',
                                                    'php7.4-fpm']:
                retcode = subprocess.getstatusoutput('service {0} status'
                                                     .format(service_name))
                if retcode[0] == 0:
                    return True
                else:
                    Log.debug(self, "{0}".format(retcode[1]))
                    return False
            else:
                return False
        except OSError as e:
            Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
            Log.error(self, "Unable to get services status of {0}"
                      .format(service_name))
            return False 
Example #16
Source File: clone_build_start_server.py    From MySQL-AutoXtraBackup with MIT License 6 votes vote down vote up
def build_pxb(self):
        # Building pxb from source
        # For this purpose will use build_{}_pxb.sh scripts from this folder
        pxb_branches = self.pxb_branches.split()
        saved_path = os.getcwd()
        dir_path = os.path.dirname(os.path.realpath(__file__))
        for branch in pxb_branches:
            pxb_path = "{}/PXB-{}".format(self.testpath, branch)
            os.chdir(pxb_path)
            build_cmd = "{}/build_pxb.sh {} {}".format(dir_path, self.testpath, branch)
            status, output = subprocess.getstatusoutput(build_cmd)
            if status == 0:
                logger.debug("PXB build succeeded")
                os.chdir(saved_path)
            else:
                logger.error("PXB build failed")
                logger.error(output)
                os.chdir(saved_path)
                return False

        return True 
Example #17
Source File: sdp_scan.py    From bluescan with GNU General Public License v3.0 6 votes vote down vote up
def scan(self, addr:str):
        print(INFO, 'Scanning...')
        exitcode, output = subprocess.getstatusoutput('sdptool records --xml ' + addr)
        if exitcode != 0:
            sys.exit(exitcode)

        # print('[DEBUG] output:', output)
        self.parse_sdptool_output(output)
        
        # services = find_service(address=addr)
        # # print(services)
        # # print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
        # for service in services:
        #     print('Name:', service['name'] )
        #     print('ProtocolDescriptorList', service['protocol'])
        #     print('channel/PSM', service['port'])
        #     print('ServiceClassIDList:', service['service-classes'])
        #     print('Profiles:', service['profiles'])
        #     print('Description:', service['description'])
        #     print('Provider:', service['provider'])
        #     print('ServiceID', service['service-id'])
        #     print() 
Example #18
Source File: setupext.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def check(self):
        if sys.platform == 'win32':
            check_include_file(get_include_dirs(), 'png.h', 'png')
            return 'Using unknown version found on system.'

        status, output = subprocess.getstatusoutput("libpng-config --version")
        if status == 0:
            version = output
        else:
            version = None

        try:
            return self._check_for_pkg_config(
                'libpng', 'png.h',
                min_version='1.2', version=version)
        except CheckFailed as e:
            if has_include_file(get_include_dirs(), 'png.h'):
                return str(e) + ' Using unknown version found on system.'
            raise 
Example #19
Source File: operator_install.py    From hpe-solutions-openshift with Apache License 2.0 6 votes vote down vote up
def validate_kibana(installer_ip, port):
    """
    Validate kibana operator by checking the status of the operator and GUI console

    """
    status, output = subprocess.getstatusoutput("systemctl status kibana")
    if status == 0:
        print("Kibana is Active")
        output = "CLOSED"
        print("Waiting for Kibana GUI to load..")
        while output != "OPEN":
            #pingtest.py program is used to ping IP address along with the PORT number \
            # and verify if its open or closed
            _, output = subprocess.getstatusoutput("python pingtest.py "+installer_ip+" "+ port+" 2> /dev/null && \
                echo OPEN || echo CLOSED")
        print("Kibana GUI is available for use on the installer IP.. ")
    else:
        print("Kibana is not running..")

#function to deploy logstash operator 
Example #20
Source File: administration.py    From wall_e with GNU General Public License v3.0 5 votes vote down vote up
def exc(self, ctx, *args):
        logger.info("[Administration exc()] exc command detected "
                    "from {} with arguments {}".format(ctx.message.author, " ".join(args)))
        query = " ".join(args)
        # this got implemented for cases when the output of the command is too big to send to the channel
        exit_code, output = subprocess.getstatusoutput(query)
        await helper_send(ctx, "Exit Code: {}".format(exit_code))
        await helper_send(ctx, output, prefix="```", suffix="```") 
Example #21
Source File: cpuinfo.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def getoutput(cmd, successful_status=(0,), stacklevel=1):
    try:
        status, output = getstatusoutput(cmd)
    except EnvironmentError:
        e = get_exception()
        warnings.warn(str(e), UserWarning, stacklevel=stacklevel)
        return False, output
    if os.WIFEXITED(status) and os.WEXITSTATUS(status) in successful_status:
        return True, output
    return False, output 
Example #22
Source File: cpuinfo.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def getoutput(cmd, successful_status=(0,), stacklevel=1):
    try:
        status, output = getstatusoutput(cmd)
    except EnvironmentError:
        e = get_exception()
        warnings.warn(str(e), UserWarning, stacklevel=stacklevel)
        return False, ""
    if os.WIFEXITED(status) and os.WEXITSTATUS(status) in successful_status:
        return True, output
    return False, output 
Example #23
Source File: services.py    From WordOps with MIT License 5 votes vote down vote up
def restart_service(self, service_name):
        """
            Restart service
            Similar to `service xyz restart`
        """
        try:
            if service_name in ['nginx']:
                Log.wait(self, "Testing Nginx configuration ")
                # Check Nginx configuration before executing command
                sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE, shell=True)
                output, error_output = sub.communicate()
                if 'emerg' not in str(error_output):
                    Log.valide(self, "Testing Nginx configuration ")
                    Log.wait(self, "Restarting Nginx")
                    service_cmd = ('service {0} restart'.format(service_name))
                    retcode = subprocess.getstatusoutput(service_cmd)
                    if retcode[0] == 0:
                        Log.valide(self, "Restarting Nginx")
                        return True
                else:
                    Log.failed(self, "Testing Nginx configuration ")
                    return False
            else:
                service_cmd = ('service {0} restart'.format(service_name))
                Log.wait(self, "Restarting {0:10}".format(
                    service_name))
                retcode = subprocess.getstatusoutput(service_cmd)
                if retcode[0] == 0:
                    Log.valide(self, "Restarting {0:10}".format(
                        service_name))
                    return True
                else:
                    Log.debug(self, "{0}".format(retcode[1]))
                    Log.failed(self, "Restarting {0:10}".format(
                        service_name))
                    return False
        except OSError as e:
            Log.debug(self, "{0} {1}".format(e.errno, e.strerror))
            Log.error(self, "\nFailed to restart service : {0}"
                      .format(service_name)) 
Example #24
Source File: operator_install.py    From hpe-solutions-openshift with Apache License 2.0 5 votes vote down vote up
def validate_logstash():
    """
    Validate logstash operator by checking the status of the operator

    """
    status, _ = subprocess.getstatusoutput("systemctl status logstash")
    if status == 0:
        print("Logstash is Active")
    else:
        print("Logstash is not running..")

#function for creating the initial setup 
Example #25
Source File: reader.py    From Baidu_Lane_Segmentation with MIT License 5 votes vote down vote up
def __init__(self, dataset_dir, subset='train',rows=2000, cols=1354, shuffle=True, birdeye=True):
        label_dirname = dataset_dir + subset
        print (label_dirname)

        if six.PY2:
            import commands
            label_files = commands.getoutput(
                "find %s -type f | grep _bin.png | sort" %
                label_dirname).splitlines()
        else:
            import subprocess
            label_files = subprocess.getstatusoutput(
                "find %s -type f | grep _bin.png | sort" %
                label_dirname)[-1].splitlines()

        print ('---')
        print (label_files[0])
        self.label_files = label_files
        self.label_dirname = label_dirname
        self.rows = rows
        self.cols = cols
        self.index = 0
        self.subset = subset
        self.dataset_dir = dataset_dir
        self.shuffle = shuffle
        self.M = 0
        self.Minv = 0
        self.reset()
        self.get_M_Minv()
        self.augmentor = 0
        self.birdeye = birdeye
        print("images total number", len(label_files))

    # 标签转分类 255 ignore ? 
Example #26
Source File: cpuinfo.py    From lambda-packs with MIT License 5 votes vote down vote up
def getoutput(cmd, successful_status=(0,), stacklevel=1):
    try:
        status, output = getstatusoutput(cmd)
    except EnvironmentError:
        e = get_exception()
        warnings.warn(str(e), UserWarning, stacklevel=stacklevel)
        return False, output
    if os.WIFEXITED(status) and os.WEXITSTATUS(status) in successful_status:
        return True, output
    return False, output 
Example #27
Source File: cpuinfo.py    From lambda-packs with MIT License 5 votes vote down vote up
def getoutput(cmd, successful_status=(0,), stacklevel=1):
    try:
        status, output = getstatusoutput(cmd)
    except EnvironmentError:
        e = get_exception()
        warnings.warn(str(e), UserWarning, stacklevel=stacklevel)
        return False, ""
    if os.WIFEXITED(status) and os.WEXITSTATUS(status) in successful_status:
        return True, output
    return False, output 
Example #28
Source File: timeout.py    From aerospike-admin with Apache License 2.0 5 votes vote down vote up
def getstatusoutput(command, timeout=DEFAULT_TIMEOUT):
    """This is a timeout wrapper around getstatusoutput."""
    _gso = call_with_timeout(subprocess.getstatusoutput, timeout)
    try:
        return _gso(command)
    except TimeoutException:
        return (-1, "The command '%s' timed-out after %i seconds." % (command, timeout)) 
Example #29
Source File: versions.py    From codimension with GNU General Public License v3.0 5 votes vote down vote up
def getJavaVersion():
    """Provides java version"""
    from .globals import GlobalData
    if not GlobalData().javaAvailable:
        return "Not installed", None

    path = find_executable("java")
    if not path:
        return "Not installed", None

    try:
        status, output = getstatusoutput(path + ' -version')
        if status != 0:
            return "Not installed", None

        for line in output.splitlines():
            # E.g. openjdk version "1.8.0_212"
            line = line.strip()
            if 'version' in line:
                ver = line.split('version', 1)[1].strip()
                if ver.startswith('"') and ver.endswith('"'):
                    ver = ver[1:-1]
                return ver, path
    except:
        return "Not installed", None
    return "could not determine", path 
Example #30
Source File: versions.py    From codimension with GNU General Public License v3.0 5 votes vote down vote up
def getGraphvizVersion():
    """Provides the graphviz version"""
    from .globals import GlobalData
    if not GlobalData().graphvizAvailable:
        return "Not installed", None

    path = find_executable("dot")
    if not path:
        return "Not installed", None

    try:
        status, output = getstatusoutput(path + ' -V')
        if status != 0:
            return "Not installed", None

        for line in output.splitlines():
            # E.g. dot - graphviz version 2.26.3 (20100126.1600)
            line = line.strip()
            if line.startswith("dot - graphviz version "):
                line = line.replace("dot - graphviz version ", "")
                parts = line.split(" ")
                if len(parts) == 2 and parts[0][0].isdigit():
                    return parts[0], path
    except:
        return "Not installed", None
    return "could not determine", path