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


Python Popen.strip方法代码示例

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


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

示例1: CheckRequiredExecutables

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
def CheckRequiredExecutables(PATH=os.getcwd(), datatype='nuc',mpi=False):
	'''
	will check if you have the mdoeltest and garli installed and in your PATH
	'''
	print 'Checking required executables and paths . . .'
	if datatype == 'nuc':
		jm = os.getenv('JMODELTEST_HOME')
		if not jm:
			print 'jModelTest not in your PATH. Please set the PATH to $JMODELTEST_HOME with export'
			print 'or set it in your bash file (.bashrc in Unix) e.g. export JMODELTEST_HOME=<PATH_TO_JMODELTEST>'
			sys.exit(-1)
		print jm
	else:
		pt = os.getenv('PROTTEST_HOME')
		if not pt:
			print 'ProtTest not in your PATH. Please set the PATH to $PROTTEST_HOME with export'
			print 'or set it in your bash file (.bashrc in Unix)e.g. export PROTTEST_HOME=<PATH_TO_PROTTEST>'
			sys.exit(-1)
		print pt
	
	p,f = Popen('which Garli-2.0',shell=True, stdout=PIPE).communicate()
	if not p.strip():
		print'No executable of GARLI in your PATH (or older version of Garli). Please copy the executable to the bin folder or assign the PATH with export'
		print 'or set it in your bash file (.bashrc in Unix)'
		sys.exit(-1)
	print p
	
	if mpi:
		garlimpi=os.getenv('GARLIMPI_HOME')
		q,g = Popen('which mpirun',shell=True, stdout=PIPE).communicate()
		if not q.strip() or not garlimpi:
			print 'Trying to use MPI with MPI applications. Install mpirun and related resources. Set a GARLIMPI_HOME to the executable with export'
			print 'e.g. export GARLIMPIHOME=[PATH_TO_GARLI], or set it in your bash file (.bashrc in Unix)'
			print 'MAKE SURE YOUR GARLI IS COMPILED FOR MPI'
			sys.exit(-1)
开发者ID:jshleap,项目名称:Phylogenetics,代码行数:37,代码来源:GarliRunner.py

示例2: get_umi_reads_and_sites

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
def get_umi_reads_and_sites(sample):
    S_number = sample.split("_")[1]
    command = "awk '{sum+=$4} END{print sum}' *%s.bg" % (S_number)
    umi_reads = Popen(command, stdout=PIPE, shell=True).stdout.read()
    command = "wc -l *%s.bg" % (S_number)
    sites = Popen(command, stdout=PIPE, shell=True).stdout.read()

    return umi_reads.strip(), sites.strip().split(" ")[0]
开发者ID:hesselberthlab,项目名称:5OH,代码行数:10,代码来源:1.5_grab_stats.py

示例3: stop

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
def stop():
    pid = Popen(['pidof','/opt/vsftpd-2.3.4/vsftpd'],stdout=PIPE).stdout.read()
    if pid:
        Popen(['kill',pid.strip()])
        return "killed pid: %s" % pid.strip()
    else:
        return "not running"
开发者ID:Samuirai,项目名称:matrix,代码行数:9,代码来源:vsftpd234.py

示例4: add_ipv6_vxlan_flows

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
    def add_ipv6_vxlan_flows(self,**args):
        """
        Compute node only
        """
        # 参数提取:虚拟机名称
        if "instance_name" not in args:
            return {"code":0,"message":"Domain name not specified !"}
        # 参数提取:虚拟机 IPv6 地址的 vlan 信息
        if "vlan_id" not in args:
            return {"code":0,"message":"Ip vlan id not specified !"}
        # 参数提取:虚拟机的 IPv6 地址
        if "ip" not in args:
            return {"code":0,"message":"Domain Ip not specified !"}
        # 参数提取:vxlan 端口号
        if "vxlan_port" not in args:
            return {"code":0,"message":"Domain vxlan_port not specified !"}
        # 参数提取:虚拟机的 mac 地址。这个暂时忽略上层传过来的值,直接从本地系统中去获取
        domifinfo = "virsh domiflist %s" % args["instance_name"]
        devices = Popen(domifinfo,shell=True,stdout=PIPE).stdout.read()
        if "bridge" not in devices:
            return {"code":0,"message":"Domain or ovs bridge may not exist!"}
        keyword = "br0" #if args["bridge"] == "br-wan" else "br1"
        line = [qline for qline in devices.split("\n") if keyword in qline ][0]
        mac = line.split()[4].strip()
        # 本地准备额外的参数:获取用于网络节点连接的端口号
        ovs_port_prefix = "wan" #if args["bridge"] == "br-wan" else "lan"
        device = "%s%s" % (ovs_port_prefix,args["instance_name"])
        desc = "ovs-vsctl get Interface %s ofport"%device
        js = Popen(desc,shell=True,stdout=PIPE).stdout.read()
        ofport = js.strip()

        # 检查是否存在上次生成的流表文件
        tmpfile = "/tmp/%s_add_ipv6_%s_vxlan_flows" % (args["instance_name"],"wan")
        if os.path.exists(tmpfile):
            os.remove(tmpfile)

        # 读取指定的流表模板
        template_path = "%s%s" % (self.network_dir,"apply_ipv6_wan_flows_template")
        fd = open(template_path, "r")
        flows = fd.read()
        fd.close()
        
        # 将信息带入流表模板,生成流表文件
        with open(tmpfile,"a") as fd:
            qflows = flows.replace('QPORT','%s'%ofport)\
                          .replace('QMAC','%s'%mac)\
                          .replace('SRC_IP','%s'%args["ip"])\
                          .replace('DEFAULT_VXLAN_PORT','%s'%args["vxlan_port"])\
                          .replace('VLAN_ID', '%s'%args["vlan_id"])
            fd.write(qflows)

        # 通过执行命令的方式应用生成的流表文件
        apply_flows = "ovs-ofctl add-flows %s %s" % ("br-wan",tmpfile) # IPv6 只适用于外网
        errinfo = Popen(apply_flows,shell=True,stderr=PIPE).stderr.read()

        # 结果返回
        if errinfo is not None and len(errinfo.strip()) > 0:
            return {"code":0,"message":"Fail to add flows with file '%s' : %s"%(tmpfile,errinfo)}
        else:
            return {"code":1,"message":"success"}
开发者ID:guojy8993,项目名称:TinyCloud,代码行数:62,代码来源:network.py

示例5: _supported_lxc

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
def _supported_lxc():
    output = Popen("which lxc-start 2>/dev/null", stdout=PIPE, shell=True).stdout.read()
    if output.strip() == "":
        return False

    output = Popen("(lxc-version 2>/dev/null || lxc-start --version) | sed 's/.* //'", stdout=PIPE, shell=True).stdout.read()
    supported, _ = _supported_tuple(output.strip(), (0, 7, 5))
    return supported
开发者ID:TENorbert,项目名称:ferry,代码行数:10,代码来源:install.py

示例6: get_host_port

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
 def get_host_port(host):
     host_ofport_name = "vxlan%s"%host
     find_ofport = "ovs-vsctl get Interface %s ofport" % host_ofport_name
     find_ofport_result = Popen(find_ofport,shell=True,stdout=PIPE).stdout.read()
     if "no row" in find_ofport_result.strip():
         return None
     else:
         return find_ofport_result.strip()
开发者ID:guojy8993,项目名称:TinyCloud,代码行数:10,代码来源:network.py

示例7: upgrade

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
def upgrade(request):
    step = 'overview'
    show_output = False
    errormsg = ''

    if request.POST.get('start') == '1':
        step = 'check_usb'

    if request.POST.get('check_usb') == '1':
        result = Popen(["sudo /bin/busybox sh /usr/sbin/upgrader check_usb"], shell=True, stdout=PIPE, close_fds=True).communicate()[0]
        result = result.strip()
        if result == 'yes':
            step = 'format_usb'
        elif result == 'sizefail':
            step = 'check_usb'
            errormsg = 'sizefail'
        elif result == 'nodrive':
            step = 'check_usb'
            errormsg = 'nodrive'

    if request.POST.get('format_usb') == '1':
        Popen(["sudo /bin/busybox sh /usr/sbin/upgrader format_usb"], shell=True, stdout=PIPE, close_fds=True).communicate()[0]
        step = 'backup_to_usb'

    if request.POST.get('backup_to_usb') == '1':
        Popen(["sudo /bin/busybox sh /usr/sbin/upgrader backup_to_usb 2>&1 > /tmp/backup_output"], shell=True, stdout=PIPE, close_fds=True)
        show_output = True
        step = 'backup_to_usb'

    if request.POST.get('proceed_to_step_4') == '1':
        step = 'download_image'

    if request.POST.get('download_image') == '1':
        result = Popen(["sudo /bin/busybox sh /usr/sbin/upgrader download_image"], shell=True, stdout=PIPE, close_fds=True).communicate()[0]
        result = result.strip()
        if result == 'yes':
            step = 'ensure_usb_unplugged'
        else:
            step = 'download_image'
            errormsg = 'imagefail'

    if request.POST.get('ensure_usb_unplugged') == '1':
        result = Popen(["sudo /bin/busybox sh /usr/sbin/upgrader check_usb"], shell=True, stdout=PIPE, close_fds=True).communicate()[0]
        result = result.strip()
        if result == 'nodrive':
            step = 'start_upgrade'
        else:
            step = 'ensure_usb_unplugged'
            errormsg = 'usbfail'

    if request.POST.get('start_upgrade') == '1':
        import os
        os.system("sudo /bin/busybox sh /usr/sbin/upgrader run_upgrade &")

    return render_to_response('upgrade/' + step + '.html', {
        'show_output': show_output,
        'errormsg': errormsg,
    }, context_instance=RequestContext(request))
开发者ID:enigmagroup,项目名称:enigmasuite,代码行数:60,代码来源:views.py

示例8: _is_running_btrfs

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
 def _is_running_btrfs(self):
     logging.warning("checking for btrfs")
     cmd = 'cat /etc/mtab | grep btrfs | awk \'{print $2}\''
     output = Popen(cmd, stdout=PIPE, shell=True).stdout.read()
     if output.strip() != "":
         dirs = output.strip().split("\n")
         for d in dirs:
             if self._is_parent_dir(d, DOCKER_DIR):
                 return True
     return False
开发者ID:georgepoenaru,项目名称:ferry,代码行数:12,代码来源:install.py

示例9: find_jstack

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
def find_jstack(pid):
    default = Popen("which jstack", stdout=PIPE, stdin=DEVNULL, shell=True).communicate()[0]
    if default.strip():
        return default.strip()
    if os.environ.get('JAVA_HOME'):
        return os.path.join(os.environ['JAVA_HOME'], 'bin', 'jstack')
    jvm_bin_path = os.path.dirname(os.readlink('/proc/{pid}/exe'.format(pid=pid)))
    if jvm_bin_path.strip():
        return os.path.join(jvm_bin_path.strip(), 'jstack')
    raise RuntimeError("Could not find jstack - do you have it installed in $JAVA_HOME?")
开发者ID:HubSpot,项目名称:astack,代码行数:12,代码来源:astack.py

示例10: get_selection

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
def get_selection(aps, vpns, gsms, others):
    """Combine the arg lists and send to dmenu for selection.
    Also executes the associated action.

    Args: args - aps: list of Actions
                 vpns: list of Actions
                 gsms: list of Actions
                 others: list of Actions
    """

    conf = configparser.ConfigParser()
    conf.read(expanduser("~/.config/networkmanager-dmenu/config.ini"))

    try:
        rofi_highlight = conf.getboolean('dmenu', 'rofi_highlight')
    except (configparser.NoOptionError, configparser.NoSectionError):
        rofi_highlight = False

    inp = []
    empty_action = [Action('', None)]
    all_actions = []
    all_actions += aps + empty_action if aps else []
    all_actions += vpns + empty_action if vpns else []
    all_actions += gsms + empty_action if gsms else []
    all_actions += others

    if rofi_highlight is True:
        inp = [str(action) for action in all_actions]
    else:
        inp = [('** ' if action.is_active else '   ') + str(action)
               for action in all_actions]
    active_lines = [index for index, action in enumerate(all_actions)
                    if action.is_active]

    inp_bytes = "\n".join([i for i in inp]).encode(ENC)
    command = dmenu_cmd(len(inp), active_lines=active_lines)
    sel = Popen(command, stdin=PIPE, stdout=PIPE,
                env=ENV).communicate(input=inp_bytes)[0].decode(ENC)

    if not sel.rstrip():
        sys.exit()

    if rofi_highlight is False:
        action = [i for i in aps + vpns + gsms + others
                  if ((str(i).strip() == str(sel.strip())
                       and not i.is_active) or
                      ('** ' + str(i) == str(sel.rstrip('\n'))
                       and i.is_active))]
    else:
        action = [i for i in aps + vpns + gsms + others
                  if str(i).strip() == sel.strip()]
    assert len(action) == 1, \
            u"Selection was ambiguous: '{}'".format(str(sel.strip()))
    return action[0]
开发者ID:Cypher1,项目名称:Castle,代码行数:56,代码来源:wifi.py

示例11: add_vxlan_flows

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
    def add_vxlan_flows(self,**args):
        """
        Compute node only
        """
        if "bridge" not in args:
            return {"code":0,"message":"OVS bridge not specified !"}
        if "instance_name" not in args:
            return {"code":0,"message":"Domain name not specified !"}

        if "vlan_id" not in args:
            return {"code":0,"message":"Ip vlan id not specified !"}
        
        if "ip" not in args:
            return {"code":0,"message":"Domain Ip not specified !"}
        if "vxlan_port" not in args:
            return {"code":0,"message":"Domain vxlan_port not specified !"}
        vxlan_port = args["vxlan_port"]
        vlan_id = args["vlan_id"]
        domifinfo = "virsh domiflist %s" % args["instance_name"]
        devices = Popen(domifinfo,shell=True,stdout=PIPE).stdout.read()
        if "bridge" not in devices:
            return {"code":0,"message":"Domain or ovs bridge may not exist!"}
        keyword = "br0" if args["bridge"] == "br-wan" else "br1"
        line = [qline for qline in devices.split("\n") if keyword in qline ][0]
        mac = line.split()[4].strip()
        ovs_port_prefix = "wan" if args["bridge"] == "br-wan" else "lan"
        device = "%s%s" % (ovs_port_prefix,args["instance_name"])
        desc = "ovs-vsctl get Interface %s ofport"%device
        js = Popen(desc,shell=True,stdout=PIPE).stdout.read()
        ofport = js.strip()
        template_path = "%s%s" % (self.network_dir,"apply_%s_flows_template"%("wan" if args["bridge"] == "br-wan" else "lan"))
        tmpfile = "/tmp/%s_add_%s_vxlan_flows" % (args["instance_name"],"wan" if args["bridge"] == "br-wan" else "lan")

        fd = open(template_path, "r")
        flows = fd.read()
        fd.close()         
        
        if os.path.exists(tmpfile):
            os.remove(tmpfile)
        with open(tmpfile,"a") as fd:
            qflows = flows.replace('QPORT','%s'%ofport)\
                          .replace('QMAC','%s'%mac)\
                          .replace('SRC_IP','%s'%args["ip"])\
                          .replace('DEFAULT_VXLAN_PORT','%s'%vxlan_port)\
                          .replace('VLAN_ID', '%s'%vlan_id)
            if "br-lan" in args["bridge"]:
                qflows = qflows.replace('VNI','%s'%args["vni"])
            fd.write(qflows)
        apply_flows = "ovs-ofctl add-flows %s %s" % (args["bridge"],tmpfile)
        errinfo = Popen(apply_flows,shell=True,stderr=PIPE).stderr.read()
        if errinfo is not None and len(errinfo.strip()) > 0:
            return {"code":0,"message":"Fail to add flows with file '%s' : %s"%(tmpfile,errinfo)}
        else:
            return {"code":1,"message":"success"}       
开发者ID:guojy8993,项目名称:TinyCloud,代码行数:56,代码来源:network.py

示例12: check

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
 def check(self,):
     res = []
     for el in self.tail:
         cmd = base64.b64decode(el.split(':')[1])
         output = Popen(['tail', '-n', '1', cmd], stdout=PIPE).communicate()[0]
         res.append(self.diff_value(el, output.strip()))
     for el in self.call:
         cmd = base64.b64decode(el.split(':')[1])
         output = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE).stdout.read()
         res.append(self.diff_value(el, output.strip()))
     return res
开发者ID:2naive,项目名称:yandex-tank,代码行数:13,代码来源:agent.py

示例13: login

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
 def login(self, user, password, email, registry):
     """
     Login to a remote registry. 
     """
     cmd = self.docker + ' ' + self.login_cmd + ' -u %s -p %s -e %s %s' % (user, password, email, registry)
     logging.warning(cmd)
     output = Popen(cmd, stdout=PIPE, shell=True).stdout.read()
     if output.strip() == "Login Succeeded":
         return True
     else:
         logging.error(output.strip())
         return False
开发者ID:kanasite,项目名称:ferry,代码行数:14,代码来源:docker.py

示例14: remove_ipv6_flows

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
    def remove_ipv6_flows(self,**args):
        """
        Work for network node and compute node.
        """
        # 从参数中读取要取消流表的 IPv6 地址
        if "domain_ip" not in args or not args["domain_ip"]:
            return {"code":0,"message":"Domain IP need to be specified !"}

        # 检测要执行的刷流表命令文件是否已存在
        tmp_flows = "/tmp/remove_all_ipv6_%s_flows.txt" % (args["domain_ip"])
        if os.path.exists(tmp_flows):
            os.remove(tmp_flows)

        # 读取刷流表命令文件的模板
        remove_flow_template = "%s%s"%(self.network_dir, "remove_all_ipv6_template")
        with open(remove_flow_template, "r") as fd:
            flows = fd.read()
            fd.close()

        # 根据实际参数替换模板中的占位符
        with open(tmp_flows,"a") as fd:
            flows = flows.replace('SRC_IP','%s'%args["domain_ip"])\
                         .replace('BRIDGE', 'br-wan') # IPv6 只适用于 br-wan
            fd.write(flows)
            fd.close()

        # 应用流表命令文件
        apply_flows = "/bin/bash %s" % tmp_flows
        errinfo = Popen(apply_flows,shell=True,stderr=PIPE).stderr.read()
        if errinfo is not None and len(errinfo.strip()) > 0:
            return {"code":0,"message":"Fail to add flows with file '%s' : %s"%(tmp_flows,errinfo)}
        else:
            return {"code":1,"message":"success"}
开发者ID:guojy8993,项目名称:TinyCloud,代码行数:35,代码来源:network.py

示例15: get_lsb_distributor

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import strip [as 别名]
def get_lsb_distributor():
    """Return the distributor ID as received from lsb_release."""
    try:
        res = Popen(["lsb_release", "-s", "-i"], stdout=PIPE).communicate()[0]
        return res.strip()
    except OSError:
        return 'Debian'
开发者ID:rubenquidam,项目名称:trisquel-packages,代码行数:9,代码来源:__init__.py


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