コード例 #1
0
ファイル: base.py プロジェクト: linlifeng/jcvi
def sh(cmd,
       grid=False,
       infile=None,
       outfile=None,
       errfile=None,
       background=False,
       threaded=None):
    """
    simple wrapper for system calls
    """
    if grid:
        from jcvi.apps.grid import GridProcess
        pr = GridProcess(cmd,
                         infile=infile,
                         outfile=outfile,
                         errfile=errfile,
                         threaded=threaded)
        pr.start(path=None)
        return 0  # A fake retcode
    else:
        if infile:
            cmd += " < {0} ".format(infile)
        if outfile and outfile != "stdout":
            cmd += " > {0} ".format(outfile)
        if errfile:
            cmd += " 2> {0} ".format(errfile)
        if background:
            cmd += " & "

        logging.debug(cmd)
        return call(cmd, shell=True)
コード例 #2
0
ファイル: base.py プロジェクト: rrane/jcvi
def sh(cmd, grid=False, infile=None, outfile=None, errfile=None,
        append=False, background=False, threaded=None, log=True,
        grid_opts=None, shell="/bin/bash"):
    """
    simple wrapper for system calls
    """
    if not cmd:
        return 1
    if grid:
        from jcvi.apps.grid import GridProcess
        pr = GridProcess(cmd, infile=infile, outfile=outfile, errfile=errfile,
                         threaded=threaded, grid_opts=grid_opts)
        pr.start()
        return pr.jobid
    else:
        if infile:
            cat = "cat"
            if infile.endswith(".gz"):
                cat = "zcat"
            cmd = "{0} {1} | ".format(cat, infile) + cmd
        if outfile and outfile != "stdout":
            if outfile.endswith(".gz"):
                cmd += " | gzip"
            tag = ">"
            if append:
                tag = ">>"
            cmd += " {0} {1} ".format(tag, outfile)
        if errfile:
            cmd += " 2> {0} ".format(errfile)
        if background:
            cmd += " & "

        if log:
            logging.debug(cmd)
        return call(cmd, shell=True, executable=shell)
コード例 #3
0
def sh(cmd,
       grid=False,
       infile=None,
       outfile=None,
       errfile=None,
       append=False,
       background=False,
       threaded=None,
       log=True,
       grid_opts=None,
       shell="/bin/bash"):
    """
    simple wrapper for system calls
    """
    if not cmd:
        return 1
    if grid:
        from jcvi.apps.grid import GridProcess
        pr = GridProcess(cmd,
                         infile=infile,
                         outfile=outfile,
                         errfile=errfile,
                         threaded=threaded,
                         grid_opts=grid_opts)
        pr.start()
        return pr.jobid
    else:
        if infile:
            cat = "cat"
            if infile.endswith(".gz"):
                cat = "zcat"
            cmd = "{0} {1} |".format(cat, infile) + cmd
        if outfile and outfile != "stdout":
            if outfile.endswith(".gz"):
                cmd += " | gzip"
            tag = ">"
            if append:
                tag = ">>"
            cmd += " {0}{1}".format(tag, outfile)
        if errfile:
            if errfile == outfile:
                errfile = "&1"
            cmd += " 2>{0}".format(errfile)
        if background:
            cmd += " &"

        if log:
            logging.debug(cmd)
        return call(cmd, shell=True, executable=shell)
コード例 #4
0
ファイル: base.py プロジェクト: bennyyu/jcvi
def sh(cmd, grid=False, infile=None, outfile=None, errfile=None,
        background=False):
    """
    simple wrapper for system calls
    """
    if grid:
        from jcvi.apps.grid import GridProcess
        pr = GridProcess(cmd, infile=infile, outfile=outfile, errfile=errfile)
        pr.start(path=None)
        return 0  # A fake retcode
    else:
        if infile:
            cmd += " < {0} ".format(infile)
        if outfile and outfile != "stdout":
            cmd += " > {0} ".format(outfile)
        if errfile:
            cmd += " 2> {0} ".format(errfile)
        if background:
            cmd += " & "

        logging.debug(cmd)
        return call(cmd, shell=True)