当前位置: 首页>>代码示例>>Python>>正文


Python subprocess32.CalledProcessError方法代码示例

本文整理汇总了Python中subprocess32.CalledProcessError方法的典型用法代码示例。如果您正苦于以下问题:Python subprocess32.CalledProcessError方法的具体用法?Python subprocess32.CalledProcessError怎么用?Python subprocess32.CalledProcessError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在subprocess32的用法示例。


在下文中一共展示了subprocess32.CalledProcessError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _autodetect_unzip_command

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def _autodetect_unzip_command():
  unzip_cmd = None
  unzip_output = None
  try:
    unzip_output = subprocess.check_output(["unzip", "-v"])
    unzip_cmd = "unzip -q $ARCHIVE"
  except subprocess.CalledProcessError as e:
    pass

  # On MacOS Yosemite, unzip does not support Zip64, but ditto is available.
  # See: https://github.com/vivlabs/instaclone/issues/1
  if not unzip_cmd or not unzip_output or unzip_output.find("ZIP64_SUPPORT") < 0:
    log.debug("did not find 'unzip' with Zip64 support; trying ditto")
    try:
      # ditto has no simple flag to check its version and exit with 0 status code.
      subprocess.check_call(["ditto", "-c", "/dev/null", tempfile.mktemp()])
      unzip_cmd = "ditto -x -k $ARCHIVE ."
    except subprocess.CalledProcessError as e:
      log.debug("did not find ditto")

  if not unzip_cmd:
    raise ArchiveError("Archive handling requires 'unzip' or 'ditto' in path")

  log.debug("unzip command: %s", unzip_cmd)
  return unzip_cmd 
开发者ID:vivlabs,项目名称:instaclone,代码行数:27,代码来源:archives.py

示例2: test_create_error

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def test_create_error(self):
        """Test Pod Creation Hook Failure"""
        with patch_object(self.plugin, '_configure_interface',
                          autospec=True) as m_configure_interface:
            # Set up mock objects
            m_configure_interface.side_effect = CalledProcessError(1,'','')
            self.plugin.delete = MagicMock(spec=self.plugin.delete)

            # Set up args
            namespace = 'ns'
            pod_name = 'pod1'
            docker_id = 13

            # Call method under test
            assert_raises(SystemExit, self.plugin.create, namespace, pod_name, docker_id)
            self.plugin.delete.assert_called_once_with(namespace, pod_name, docker_id) 
开发者ID:projectcalico,项目名称:k8s-exec-plugin,代码行数:18,代码来源:kube_plugin_test.py

示例3: test_create_error_delete_error

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def test_create_error_delete_error(self):
        """Test Error in Pod Creation Hook Failure
        Tests that we handle errors when cleaning up gracefully.
        """
        with patch_object(self.plugin, '_configure_interface',
                          autospec=True) as m_configure_interface:
            # Set up mock objects
            m_configure_interface.side_effect = CalledProcessError(1,'','')
            self.plugin.delete = MagicMock(spec=self.plugin.delete)
            self.plugin.delete.side_effect = KeyError

            # Set up args
            namespace = 'ns'
            pod_name = 'pod1'
            docker_id = 13

            # Call method under test
            assert_raises(SystemExit, self.plugin.create, namespace, pod_name, docker_id)
            self.plugin.delete.assert_called_once_with(namespace, pod_name, docker_id) 
开发者ID:projectcalico,项目名称:k8s-exec-plugin,代码行数:21,代码来源:kube_plugin_test.py

示例4: on_message

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def on_message(self, client, userdata, msg):
        """Process a message"""
        self.logger.info('Received command on {0}: {1}'.format(self.cmdTopic, msg.payload))
        
        inArgs = msg.payload.split(' ')
        cmdArgs = []
        for arg in self.command.split(' '):
          if arg.find(';') == -1 or arg.find('|') == -1 or arg.find('//') == -1:
            cmdArgs.append(arg)
        for arg in inArgs:
          if arg != 'NA' and arg.find(';') == -1 and arg.find('|') == -1 and arg.find('//') == -1:
            cmdArgs.append(arg)

        self.logger.info('Executing command with the following arguments: {0}'.format(cmdArgs))
        try:
          output = subprocess.check_output(cmdArgs, shell=False, universal_newlines=True)
          self.logger.info('Command results to be published to {0}\n{1}'.format(self.pubTopic, output))
          self.publishImpl(output, self.pubTopic)
        except subprocess.CalledProcessError as e:
          self.logger.info('Command returned an error code: {0}\n{1}'.format(e.returncode, e.output))
          self.publishImpl('ERROR', self.pubTopic) 
开发者ID:rkoshak,项目名称:sensorReporter,代码行数:23,代码来源:execActuator.py

示例5: screenshot

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def screenshot(self, filename=None):
        """
        Return:
            PIL.Image
            
        Raises:
            EnvironmentError
        """
        tmpfile = tempfile.mktemp(prefix='atx-screencap-', suffix='.tiff')
        try:
            idevice("screenshot", "--udid", self.udid, tmpfile)
        except subprocess.CalledProcessError as e:
            sys.exit(e.message)

        try:
            image = Image.open(tmpfile)
            image.load()
            if filename:
                image.save(filename)
            return image
        finally:
            if os.path.exists(tmpfile):
                os.unlink(tmpfile) 
开发者ID:NetEaseGame,项目名称:ATX,代码行数:25,代码来源:ioskit.py

示例6: create_veth

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def create_veth(veth_name_host, veth_name_ns_temp):
    """
    Create the veth (pair).
    :param veth_name_host: The name of the veth interface
    :param veth_name_ns_temp: The temporary interface name of the veth that will be
    moved into the namespace.
    :return: None. Raises CalledProcessError on error.
    """
    # Create the veth
    _log.debug("Creating veth %s in temp_ns: %s", veth_name_host, veth_name_ns_temp)
    check_output(['ip', 'link',
                'add', veth_name_host,
                'type', 'veth',
                'peer', 'name', veth_name_ns_temp],
               timeout=IP_CMD_TIMEOUT)

    # Set the host end of the veth to 'up' so felix notices it.
    check_output(['ip', 'link', 'set', veth_name_host, 'up'],
               timeout=IP_CMD_TIMEOUT) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:21,代码来源:netns.py

示例7: veth_exists

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def veth_exists(veth_name_host):
    """
    Check if the veth exists on the host.
    :param veth_name_host: The name of the veth interface.
    :return: True if veth exists, False if veth does not exist
    """
    # Suppress output
    with open(os.devnull, 'w') as fnull:
        try:
            check_call(["ip", "link", "show", veth_name_host],
                       stderr=fnull,
                       stdout=fnull)
            return True
        except CalledProcessError:
            # veth does not exist
            return False 
开发者ID:projectcalico,项目名称:libcalico,代码行数:18,代码来源:netns.py

示例8: check_returncode

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def check_returncode(self):
            """Raise CalledProcessError if the exit code is non-zero."""
            if self.returncode:
                raise CalledProcessError(
                    self.returncode, self.args, self.stdout, self.stderr
                ) 
开发者ID:python-poetry,项目名称:poetry,代码行数:8,代码来源:_compat.py

示例9: _autodetect_zip_command

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def _autodetect_zip_command():
  try:
    zip_output = subprocess.check_output(["zip", "-v"])
    zip_cmd = "zip -q -r $ARCHIVE $DIR"
  except subprocess.CalledProcessError as e:
    raise ArchiveError("Archive handling requires 'zip' in path: %s" % e)

  if zip_output.find("ZIP64_SUPPORT") < 0:
    log.warn("installed 'zip' doesn't have Zip64 support so will fail for large archives")
  log.debug("zip command: %s", zip_cmd)
  return zip_cmd 
开发者ID:vivlabs,项目名称:instaclone,代码行数:13,代码来源:archives.py

示例10: subproc_call

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def subproc_call(cmd, timeout=None):
    try:
        output = subprocess.check_output(
                cmd, stderr=subprocess.STDOUT,
                shell=True, timeout=timeout)
        return output
    except subprocess.TimeoutExpired as e:
        logger.warn("Command timeout!")
        logger.warn(e.output)
    except subprocess.CalledProcessError as e:
        logger.warn("Commnad failed: {}".format(e.returncode))
        logger.warn(e.output) 
开发者ID:anonymous-author1,项目名称:DDRL,代码行数:14,代码来源:concurrency.py

示例11: _remove_endpoint

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def _remove_endpoint(self, endpoint):
        """
        Remove the provided endpoint on this host from Calico networking.
        - Removes any IP address assignments.
        - Removes the veth interface for this endpoint.
        - Removes the endpoint object from etcd.
        """
        # Remove any IP address assignments that this endpoint has
        ip_set = set()
        for net in endpoint.ipv4_nets | endpoint.ipv6_nets:
            ip_set.add(net.ip)
        logger.info("Removing IP addresses %s from endpoint %s",
                    ip_set, endpoint.name)
        self._datastore_client.release_ips(ip_set)

        # Remove the veth interface from endpoint
        logger.info("Removing veth interfaces")
        try:
            netns.remove_veth(endpoint.name)
        except CalledProcessError:
            logger.exception("Could not remove veth interface from "
                             "endpoint %s", endpoint.name)

        # Remove endpoint from the datastore.
        try:
            self._datastore_client.remove_workload(
                HOSTNAME, ORCHESTRATOR_ID, self.docker_id)
        except KeyError:
            logger.exception("Error removing workload.")
        logger.info("Removed Calico endpoint %s", endpoint.endpoint_id) 
开发者ID:projectcalico,项目名称:k8s-exec-plugin,代码行数:32,代码来源:calico_kubernetes.py

示例12: test_remove_endpoint_with_exceptions

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def test_remove_endpoint_with_exceptions(self, m_remove_veth):
        """Test Container Remove Exception Handling

        Failures in remove_veth and remove_workload should gently raise exceptions without exit.
        """
        # Raise errors under test.
        m_remove_veth.side_effect = CalledProcessError(1, '', '')
        self.m_datastore_client.remove_workload.side_effect = KeyError

        self.plugin._remove_endpoint(MagicMock()) 
开发者ID:projectcalico,项目名称:k8s-exec-plugin,代码行数:12,代码来源:kube_plugin_test.py

示例13: test_log_error

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def test_log_error(self):
        with patch('calico_kubernetes.tests.kube_plugin_test.'
                   'calico_kubernetes.check_output',
                   autospec=True) as m_check_output:
            # Mock to throw Exception
            m_check_output.side_effect = CalledProcessError

            # Call function, assert Exception is caught.
            _log_interfaces("12345") 
开发者ID:projectcalico,项目名称:k8s-exec-plugin,代码行数:11,代码来源:kube_plugin_test.py

示例14: subproc_call

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def subproc_call(cmd, timeout=None):
    """Execute a command with timeout, and return both STDOUT/STDERR.

    Args:
        cmd (str): the command to execute.
        timeout (float): timeout in seconds.

    Returns:
        output (bytes), retcode(int): If timeout, retcode is -1.

    """
    try:
        output = subprocess.check_output(
            cmd, stderr=subprocess.STDOUT,
            shell=True, timeout=timeout)
        return output, 0
    except subprocess.TimeoutExpired as e:
        print("Command '{}' timeout!".format(cmd))
        print(e.output.decode('utf-8'))
        return e.output, -1
    except subprocess.CalledProcessError as e:
        print("Command '{}' failed, return code={}".format(cmd, e.returncode))
        print(e.output.decode('utf-8'))
        return e.output, e.returncode
    except Exception:
        print("Command '{}' failed to run.".format(cmd))
        return "", -2 
开发者ID:blue-oil,项目名称:blueoil,代码行数:29,代码来源:tune_ray.py

示例15: run

# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import CalledProcessError [as 别名]
def run(self,run_id,inputs={}):
        in_file = ''
        
        #retrieve all the parameters and map them to the series of calls to be executed...
        command = ['ls','-als']
        self.db_start(run_id,in_file,self.params)
        
        #workflow is to run through the stage correctly and then check for error handles
        #[3a]execute the command here----------------------------------------------------
        output,err = '',{}
        try:
            output = subprocess.check_output(command,stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as E:
            print('ouput: '+E.output)             #what you would see in the term
            err['output'] = E.output
            #the python exception issues (shouldn't have any...
            print('message: '+E.message)          #?? empty
            err['message'] = E.message
            #return codes used for failure....
            print('code: '+str(E.returncode))     #return 1 for a fail in art?
            err['code'] = E.returncode
        except OSError as E:
            print('ouput: '+E.strerror)             #what you would see in the term
            err['output'] = E.strerror
            #the python exception issues (shouldn't have any...
            print('message: '+E.message)          #?? empty
            err['message'] = E.message
            #the error num
            print('code: '+str(E.errno))
            err['code'] = E.errno
        print('output:\n'+output)
        #[3a]execute the command here----------------------------------------------------
        #[3b]do a os directory/data check or a ls type command to check the size
        #[3b]of the produced data to ensure that everything is fine...        
        if err == {}:
            self.db_stop(run_id,{'output':output},'',True)
            return output
        else:
            self.db_stop(run_id,{'output':output},err['message'],False)
            return None 
开发者ID:TheJacksonLaboratory,项目名称:SVE,代码行数:42,代码来源:stage_wrapper.py


注:本文中的subprocess32.CalledProcessError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。