aboutsummaryrefslogtreecommitdiff
path: root/catapult/common/py_utils/py_utils/xvfb.py
blob: c09f3e333ab27f85ebeb172d71944a0382b0b1fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import logging
import subprocess
import platform
import time


def ShouldStartXvfb():
  return platform.system() == 'Linux'


def StartXvfb():
  display = ':99'
  xvfb_command = ['Xvfb', display, '-screen', '0', '1024x769x24', '-ac']
  xvfb_process = subprocess.Popen(
      xvfb_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  time.sleep(0.2)
  returncode = xvfb_process.poll()
  if returncode is None:
    os.environ['DISPLAY'] = display
  else:
    logging.error('Xvfb did not start, returncode: %s, stdout:\n%s',
                  returncode, xvfb_process.stdout.read())
    xvfb_process = None
  return xvfb_process