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


Python subprocess.getstatusoutput函数代码示例

本文整理汇总了Python中subprocess.getstatusoutput函数的典型用法代码示例。如果您正苦于以下问题:Python getstatusoutput函数的具体用法?Python getstatusoutput怎么用?Python getstatusoutput使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: check_status

def check_status():
    '''
    Check the status of process and pull out error messages.
    '''
    global update_err_msg, polling_err_msg
    if not update_proc:
        update_status = 'not started'
    elif update_proc.poll() is None:
        update_status = 'running({})'.format(update_proc.pid)
    else:  # dead
        update_status = 'exited({})'.format(update_proc.returncode)
        if update_err_msg == '':  # haven't pull out
            update_err_msg = update_proc.stderr.read().decode('utf-8')

    if not polling_proc:
        polling_status = 'not started'
    elif polling_proc.poll() is None:
        polling_status = 'running({})'.format(polling_proc.pid)
    else:  # dead
        polling_status = 'exited({})'.format(polling_proc.returncode)
        if polling_err_msg == '':  # haven't pull out
            polling_err_msg = polling_proc.stderr.read().decode('utf-8')

    # regenerate docs
    subprocess.getstatusoutput(DOCS_CMD)

    return update_status, polling_status
开发者ID:JoM-Lab,项目名称:JoM,代码行数:27,代码来源:daemon.py

示例2: build_one_container

def build_one_container(image_name, memory, code_address):
    """
    生成一个容器
    :param image_name: 镜像名字
    :param memory: 内存
    :param code_address: 代码zip地址
    :return: dict
    """

    port = get_one_able_post()
    system_image = get_realname_from_image_name(image_name)
    command = "docker run -d -m %dm -p %d:80 %s /bin/bash /tmp/start.sh '%s'" % (int(memory), port, system_image, code_address)

    code, _ = subprocess.getstatusoutput(command)
    if code != 0:
        return {"code": 10004}

    code, result = subprocess.getstatusoutput("docker ps | grep -v grep |grep 0.0.0.0:%d|awk -F ' ' '{print $1}'" % port)
    if code != 0:
        return {"code": 10004}

    # 记录新建容器端口情况
    obj = ContainerModel(port=port, container_id=result, memory=memory, code_address=code_address,
                         image_name=system_image, create_time=datetime.datetime.now())
    obj.save()

    return {"code": 0, "result": {"containerId": result, "port": port}}
开发者ID:richardy2012,项目名称:app,代码行数:27,代码来源:container.py

示例3: create_machine

def create_machine(project_name):
    """Create docker-machine environment and create if neccessary."""
    tool_name = re.sub(r'[\s_]', '-', project_name)
    machines = subprocess.getstatusoutput('docker-machine ls -q')
    machines = machines[1].split('\n')
    msg = """Activate with either:
        $ eval $(docker-machine env {envname})

        or if you have docker-machine bash completion:

        $ docker-machine use {envname}
        """.format(envname=tool_name)

    if not [i for i in machines if tool_name in i]:
        click.echo(
            "Creating: docker-machine env {}".format(tool_name)
        )
        status = subprocess.getstatusoutput(
            'docker-machine create --driver virtualbox {}'.format(tool_name))
        if status[0] == 0:
            click.secho("Docker-machine env `{}` created.".format(tool_name), fg='green')
            click.secho(msg, fg='yellow')
        else:
            click.secho(status[1], fg='red')
    else:
        click.secho("Docker-machine environment ready.", fg='green')
        click.secho(msg, fg='yellow')
开发者ID:dgonzo,项目名称:toadie,代码行数:27,代码来源:toadie.py

示例4: setEnvironmentDarwin

def setEnvironmentDarwin():
	brew_prefix=subprocess.getstatusoutput('brew --prefix')[1]
	if not brew_prefix:
		return 
	print("homebrew installed")
	opencv_version=subprocess.getstatusoutput('brew ls --versions opencv')[1]
	if not opencv_version:
		print("please install opencv by \n'brew install homebrew/science/opencv'")
	else:
		print("your opencv version is %s"%opencv_version)
	python_version=subprocess.getstatusoutput('python --version')[1].split(" ")[1]
	python_version="python"+".".join(python_version.split(".")[:-1])
	print(python_version)		
	PYTHONPATH=os.path.join(brew_prefix,"lib",python_version,"site-packages")
	print(PYTHONPATH)
	bashrc_fname=os.path.expanduser("~/.bashrc")
	bashrc_lines=open(bashrc_fname).read()
	if 'PYTHONPATH' not in os.environ :
		os.environ['PYTHONPATH']=PYTHONPATH
		print(os.environ['PYTHONPATH'])
		
	if os.environ['PYTHONPATH'] not in bashrc_lines :
		fp=open(bashrc_fname,"a")
		fp.write("\nexport PYTHONPATH=%s\n"%os.environ['PYTHONPATH'])
		fp.close()
	
	if PYTHONPATH not in os.environ['PYTHONPATH']:
		os.environ['PYTHONPATH']=" ".join(PYTHONPATH,os.environ['PYTHONPATH'])
		print(os.environ['PYTHONPATH'])
开发者ID:Ameb,项目名称:python-tesseract,代码行数:29,代码来源:test3.py

示例5: main

def main():
    '''
    Display HTML.
    '''
    (st, branch) = subprocess.getstatusoutput(BRANCH_CMD)
    (st, head) = subprocess.getstatusoutput(HEAD_CMD)
    update_status, polling_status = check_status()
    return '''\
<html><body>
<form action="/checkout" method="post">
current branch: {branch}
<input name="branch" type="text"/>
<input value="checkout" type="submit"/></form><br/>
current HEAD: {head}
<a href="/hook"><button type="button">pull and restart</button></a><br/><br/>
update proc: {update_status}<br/>
<pre>{update_err_msg}</pre><br/>
pollinging proc: {polling_status}<br/>
<pre>{polling_err_msg}</pre><br/>
<a href="/docs/">docs</a>
</body></html>
'''.format(branch=branch,
           head=head,
           update_status=update_status,
           update_err_msg=update_err_msg,
           polling_status=polling_status,
           polling_err_msg=polling_err_msg)
开发者ID:JoM-Lab,项目名称:JoM,代码行数:27,代码来源:daemon.py

示例6: unblock

 def unblock(self):
     '''
     '''
     st,output = getstatusoutput("pfctl -a switchyard -Fr") # flush rules
     log_debug("Flushing rules: {}".format(output))
     st,output = getstatusoutput("pfctl -X {}".format(self._token))
     log_info("Releasing pf: {}".format(output.replace('\n', '; ')))
开发者ID:ruanxuyi,项目名称:cs640,代码行数:7,代码来源:hostfirewall.py

示例7: main

def main(args):
    pc = PC()
    pc.add_func_path("../formulas")
    pc.load_formula_file("gf4d.frm")
    pc.load_formula_file("gf4d.cfrm")
    pc.compiler_name = "g++"
    pc.leave_dirty = True
    f = fractal.T(pc)
    f.loadFctFile(open(args[0]))
    outfile = f.compile()
    cfile = outfile[:-2] + "c"

    # compile the stub and the c file to create a program to profile
    files = " ".join(pc.cfiles + [cfile])
    
    cmd = "%s %s %s -o %s %s" % \
          (pc.compiler_name, files, "-g -pg -O3 -Ic -lpthread", "proftest", "")

    print(cmd)
    (status,output) = subprocess.getstatusoutput(cmd)
    if status != 0:
        raise Exception(
            "Error reported by C compiler:%s" % output)

    print(output)
    # compiled - hurrah! run it
    (status,output) = subprocess.getstatusoutput("./proftest")
    if status != 0:
        raise Exception(
            "Error reported by program:%s" % output)

    print(output)
开发者ID:edyoung,项目名称:gnofract4d,代码行数:32,代码来源:profutil.py

示例8: backup

def backup():
    for (opath,spath) in paths:
        if (not os.path.exists(opath)):next
        if (not os.path.exists(spath)):cmd = 'mkdir -p '+spath;subprocess.getstatusoutput(cmd)
        isfile = os.path.isfile(opath)
        if (isfile):filename = opath.split('/')[-1]
        isdir = os.path.isdir(opath)
        if(isdir):dirname = os.path.dirname(opath).split('/')[-1]

        if (isfile):
            #print ('check file {0}|{1}'.format(filename,path))
            #subprocess.Popen('cp -u {0} {1}'.format(path,savepath+filename),shell=True).wait()
            cmd = 'cp -u {0} {1}'.format(opath,spath)
            (status, output) = subprocess.getstatusoutput(cmd)
            print ('status: %-3s dir: %-6s'%(status,filename))
            if (status):print (' '*3,output)
            #if (not status):
            #    print('succeeded\t copy file:\t{0}'.format(filename))
            #else:
            #    print('failed   \t copy file:\t{0}'.format(filename))
            #
        elif(isdir):

            #subprocess.Popen('cp -urv {0} {1}'.format(path,savepath+dirname),shell=True).wait()
            cmd ='cp -urv {0} {1}'.format(opath,spath)
            (status, output) = subprocess.getstatusoutput(cmd)
            print ('status: %-3s dir: %-8s'%(status,dirname))
            if (status):print (' '*3,output)
            #if (not status):
            #    print('succeeded\t copy dir:\t{0}'.format(dirname))
            #else:
            #    print('failed    \t copy  dir:\t{0}'.format(dirnme))
        else:
            #print ('path:{0} \tignored'.format(opath))
            print ( 'ignored \t %s' % (opath) )
开发者ID:Changgg,项目名称:openSUSE,代码行数:35,代码来源:auto.py

示例9: __init__

    def __init__(self, interfaces, rules):
        super().__init__(interfaces, rules)
        self._intf = interfaces
        st,output = getstatusoutput("iptables-save")
        self._saved_iptables = output
        self._arpignore = {}
        self._rulecmds = [ 'iptables -F', 'iptables -t raw -F' ]

        # --protocol {}  -i {} --port {}
        doall = False
        for r in rules:
            cmds = self._parse_rule(r)
            self._rulecmds.extend(cmds)
            if r == 'all':
                doall = True

        if doall:
            badintf = []
            for intf in interfaces:
                st,output = getstatusoutput('sysctl net.ipv4.conf.{}.arp_ignore'.format(intf))
                if st != 0:
                    badintf.append(intf)
                    continue
                self._arpignore[intf] = int(output.split()[-1])
                st,output = getstatusoutput('sysctl -w net.ipv4.conf.{}.arp_ignore=8'.format(intf))
            for intf in badintf:
                self._intf.remove(intf) # alias of interfaces, so just remove
                                        # from self._intf
        log_debug("Rules to install: {}".format(self._rulecmds))
开发者ID:ruanxuyi,项目名称:cs640,代码行数:29,代码来源:hostfirewall.py

示例10: install_splash

def install_splash(newsplashfile, msg=instmsg):
  status, splashdata = getstatusoutput("pacman -Ql eclipse")
  splash = ""
  for line in splashdata.split("\n"):
    if line.endswith("splash.bmp"):
        splash = line
        break
  try:
    splashfile = splash.split()[1]
  except IndexError:
    print("Unable to find eclipse splash image (got %s)" % (splash))
    exit(1)
  esplashdir = os.path.dirname(splashfile)
  today = "-".join(map(str, localtime()[0:6]))
  backupfile = os.path.join(progdir, "splash-backup-%s.bmp" % (today))
  if os.path.exists(splashfile):
    if 0 != getstatusoutput("mv -f %s %s" % (splashfile, backupfile))[0]:
      print(ver + "\n" + req)
      exit(1)
    print(msg, end=" ")
    if 0 != getstatusoutput("cp %s %s" % (newsplashfile, splashfile))[0]:
      print()
      print("Unable to install splash image to %s/" % (esplashdir))
      exit(1)
  else:
    splashdir = os.path.dirname(splashfile)
    if 0 != getstatusoutput("mkdir -p %s" % (splashdir))[0]:
      print(ver + "\n" + req)
      exit(1)
    print(msg, end=" ")
    if 0 != getstatusoutput("cp %s %s" % (newsplashfile, splashfile))[0]:
      print()
      print("Unable to install splash image to %s/" % (esplashdir))
      exit(1)
  print("done")
开发者ID:NovaCygni,项目名称:aur-mirror,代码行数:35,代码来源:setupsplash.py

示例11: getEnv

    def getEnv( self ):
        out = dict( )
        if compiler.isMSVC( ):
            compilerDirs = {
                "msvc2010": "VS100COMNTOOLS",
                "msvc2012": "VS110COMNTOOLS",
                "msvc2013": "VS120COMNTOOLS",
                "msvc2015": "VS140COMNTOOLS"
            }
            architectures = { "x86": "x86", "x64": "amd64", "x64_cross": "x86_amd64" }
            crossmodifier = ""
            if not compiler.isNative(): crossmodifier="_cross"
            status, result = subprocess.getstatusoutput( "\"%s\\..\\..\\VC\\vcvarsall.bat\" %s > NUL && set" % (
                os.getenv( compilerDirs[ compiler.getCompilerName( ) ] ), architectures[ compiler.architecture( ) + crossmodifier ]) )
            if status != 0:
                print( "Failed to setup msvc compiler", file = sys.stderr )
            out = self.stringToEnv( result )

        elif compiler.isIntel( ):
            architectures = { "x86": "ia32", "x64": "intel64" }
            programFiles = os.getenv( "ProgramFiles(x86)" ) or os.getenv( "ProgramFiles" )
            status, result = subprocess.getstatusoutput(
                "\"%s\\Intel\\Composer XE\\bin\\compilervars.bat\" %s > NUL && set" % (
                    programFiles, architectures[ compiler.architecture( ) ]) )
            if status != 0:
                print( "Failed to setup intel compiler", file = sys.stderr )
            out = self.stringToEnv( result )
        elif compiler.isMinGW( ):
            out = { "Path": os.getenv( "Path" ) }
        return out
开发者ID:TheOneRing,项目名称:emerge,代码行数:30,代码来源:EmergeSetupHelper.py

示例12: _test_unique_prompt

def _test_unique_prompt():
    import time
    time_start = time.time()
    LOG_FILE = 'remote.log'
    import subprocess
    subprocess.getstatusoutput('rm -fr %s'%LOG_FILE)
    log_file = open(LOG_FILE, 'wb+')
    h1 = SshHost('sunfire', 'geouser', 'geouser', logfile=log_file)
    h1.login(True)
    ssh_path = h1.docmd('which ssh')
    h1.switch_user('root', 'geoprobe', True)
    h2 = SshHost('xformer2', 'geo', 'geo.geo', h1)
    iret = h2.login(True)
    if(iret<0):
        h2 = SshHost('xformer2', 'geo', 'geo.geo', h1, ssh_path=ssh_path)
        iret = h2.login(True)
    h2.switch_user('root','inetinet')
    h2.logout()
    h2.login()
    h2.switch_user('root','inetinet')
    uptime = h2.docmd('uptime')
    print('uptime of xformer2: ', uptime)
    h2.quit_user()
    h2.logout()
    h2 = TelnetHost('xformer2', 'geo', 'geo.geo', h1)
    h2.login(True)
    h2.logout()
    h1.logout()
    log_file.close()
    time_end = time.time()
    print('done in %s minutes.'%str((time_end-time_start)/60.0))
开发者ID:ravenac95,项目名称:pexpect,代码行数:31,代码来源:remote.py

示例13: startPIGPIO

 def startPIGPIO(self):
    if sys.version_info[0] < 3:
        import commands
        status, process = commands.getstatusoutput('sudo pidof pigpiod')
        if status:  #  it wasn't running, so start it
            self.LogInfo ("pigpiod was not running")
            commands.getstatusoutput('sudo pigpiod')  # try to  start it
            time.sleep(0.5)
            # check it again        
            status, process = commands.getstatusoutput('sudo pidof pigpiod')
    else:      
        import subprocess
        status, process = subprocess.getstatusoutput('sudo pidof pigpiod')
        if status:  #  it wasn't running, so start it
            self.LogInfo ("pigpiod was not running")
            subprocess.getstatusoutput('sudo pigpiod')  # try to  start it
            time.sleep(0.5)
            # check it again        
            status, process = subprocess.getstatusoutput('sudo pidof pigpiod')
    
    if not status:  # if it was started successfully (or was already running)...
        pigpiod_process = process
        self.LogInfo ("pigpiod is running, process ID is {} ".format(pigpiod_process))
    
        try:
            pi = pigpio.pi()  # local GPIO only
            self.LogInfo ("pigpio's pi instantiated")
        except Exception as e:
            start_pigpiod_exception = str(e)
            self.LogError ("problem instantiating pi: {}".format(start_pigpiod_exception))
    else:
        self.LogError ("start pigpiod was unsuccessful.")
        return False
    return True
开发者ID:Nickduino,项目名称:Pi-Somfy,代码行数:34,代码来源:operateShutters.py

示例14: intltool_version

def intltool_version():
    '''
    Return the version of intltool as a tuple.
    '''
    if sys.platform == 'win32':
        cmd = ["perl", "-e print qx(intltool-update --version) =~ m/(\d+.\d+.\d+)/;"]
        try:
            ver, ret = subprocess.Popen(cmd ,stdout=subprocess.PIPE,
                stderr=subprocess.PIPE, shell=True).communicate()
            ver = ver.decode("utf-8")
            if ver > "":
                version_str = ver
            else:
                return (0,0,0)
        except:
            return (0,0,0)
    else:
        cmd = 'intltool-update --version 2> /dev/null' # pathological case
        retcode, version_str = subprocess.getstatusoutput(cmd)
        if retcode != 0:
            return None
        cmd = 'intltool-update --version 2> /dev/null | head -1 | cut -d" " -f3'
        retcode, version_str = subprocess.getstatusoutput(cmd)
        if retcode != 0: # unlikely but just barely imaginable, so leave it
            return None
    return tuple([int(num) for num in version_str.split('.')])
开发者ID:cz172638,项目名称:gramps,代码行数:26,代码来源:setup.py

示例15: ams_config

def ams_config():

    ams_unzip()
    project_war = '%s/%s/target/%s' %(svn_path,project_name,project_name)
    project_war_ver = '%s/%s/target/%s_%s' %(svn_path,project_name,project_name,ver)
    os.system('cp -Rf %s %s_%s' %(project_war,project_war,ver))
    for i in ['28080','29080']:
        for j in ['test','staging','production']:
            project_war_ver_env_port = '%s_%s_%s_%s' %(project_war,ver,j,i)
            web_xml = '%s/WEB-INF/web.xml' %(project_war_ver_env_port)
            applicationContext_xml = '%s/WEB-INF/classes/applicationContext.xml' %project_war_ver_env_port
            os.system('cp -Rf %s %s' %(project_war_ver,project_war_ver_env_port))
            if j == 'production' or j == 'staging':
                os.system("sed -r -i 's/(<param-value>)(development|test|production)(<\/param-value>)/\1production\3/g' %s" %web_xml)
                status,output = subprocess.getstatusoutput('grep -E "<param-value>production</param-value>" %s' %web_xml)
                if status != 0:
                    logg.error("项目的web.xml配置文件修改错误:%s" %web_xml)
                    exit_script()
            else:
                os.system("sed -r -i 's/(<param-value>)(development|test|production)(<\/param-value>)/\1%s\3/g' %s" %(j,web_xml))
                status,output = subprocess.getstatusoutput('grep -E "<param-value>%s</param-value>" %s' %(j,web_xml))
                if status != 0:
                    logg.error("项目的web.xml配置文件修改错误:%s" %web_xml)
                    exit_script()

            if i == '28080':
                ii = 29080
            elif i == '29080':
                ii == 28080
            os.system("sed -i -r 's/(property name=\"port\" value=\")%s/\1%s/g' %s" %(ii,i,applicationContext_xml))
            status,output = subprocess.getstatusoutput('grep -E "name=\"port\" *value=\"%s\"" %s' %(i,applicationContext_xml))
            if status != 0:
                logg.error("项目的配置文件修改错误:%s" %applicationContext_xml)
                exit_script()
开发者ID:893271511,项目名称:web,代码行数:34,代码来源:coderelease.py


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