elasticsearch_fixture.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:snovault 作者: ENCODE-DCC 项目源码 文件源码
def server_process(datadir, host='127.0.0.1', port=9201, prefix='', echo=False):
    args = [
        os.path.join(prefix, 'elasticsearch'),
        '-Enetwork.host=%s' % host,
        '-Ehttp.port=%d' % port,
        '-Epath.data=%s' % os.path.join(datadir, 'data'),
        '-Epath.logs=%s' % os.path.join(datadir, 'logs'),
    ]
    if os.environ.get('TRAVIS'):
        print('IN TRAVIS')
        echo=True
        args.append('-Epath.conf=%s/conf' % os.environ['TRAVIS_BUILD_DIR'])
    elif os.path.exists('/etc/elasticsearch'):
        print('NOT IN TRAVIS')
        args.append('-Epath.conf=/etc/elasticsearch')
    print(args)
    process = subprocess.Popen(
        args,
        close_fds=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
    )

    SUCCESS_LINE = b'started\n'

    lines = []
    for line in iter(process.stdout.readline, b''):
        if echo:
            sys.stdout.write(line.decode('utf-8'))
        lines.append(line)
        if line.endswith(SUCCESS_LINE):
            print('detected start, broke')
            break
    else:
        code = process.wait()
        msg = ('Process return code: %d\n' % code) + b''.join(lines).decode('utf-8')
        raise Exception(msg)

    if not echo:
        process.stdout.close()
    print('returning process')
    return process
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号