diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2008-08-10 08:43:22 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2008-08-10 08:43:22 (GMT) |
commit | fb42669d45fe37369565db28030c1484d754ce57 (patch) | |
tree | 4007b19db644a42f6e64e001d27b541718460c6f /scripts | |
parent | 9f4ab84437fc4e05e164c0e15d00326e7d3c1301 (diff) |
Improve Xvfb handling
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/check.py | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/scripts/check.py b/scripts/check.py index 79396cf..aa346eb 100644 --- a/scripts/check.py +++ b/scripts/check.py @@ -11,6 +11,12 @@ scripts_dir = os.path.dirname(__file__) data_dir = os.path.join(scripts_dir, 'data') pylintrc_path = os.path.join(data_dir, 'pylintrc') +def check_display(display): + result = subprocess.call(['xdpyinfo', '-display', ':%d' % display], + stdout=open(os.devnull, "w"), + stderr=open(os.devnull, "w")) + return result == 0 + class cmd_check(Command): name = 'check' @@ -18,27 +24,33 @@ class cmd_check(Command): def __init__(self): Command.__init__(self, [ - make_option('-x', '--xvfb-port', action='store', - dest='xvfb_port', default=None, - help='specify the port of the xvfb server'), make_option('-t', '--type', action='store', dest='type', default=None, help='specify the check type') ]) - def start_xvfb(self, port): - if port is None: - port = ':%d' % random.randrange(100, 1000) - - try: - p = subprocess.Popen(['Xvfb', '-ac', port], - stdout=open(os.devnull, "w"), - stderr=subprocess.STDOUT) - os.environ['DISPLAY'] = port - return p.pid - except OSError: - print 'Cannot execute xfvb, will use the default display.' - + def start_xvfb(self): + result = None + + for port in range(100, 1000): + if not check_display(port): + try: + p = subprocess.Popen(['Xvfb', '-ac', ':%d' % port], + stdout=open(os.devnull, "w"), + stderr=subprocess.STDOUT) + + tries = 10 + while tries > 0: + if check_display(port): + os.environ['DISPLAY'] = ':%d' % port + return p.pid + else: + tries -= 1 + time.sleep(0.1) + except OSError: + break + + print 'Cannot execute xfvb, will use the default display.' return None def lint(self, module): @@ -72,7 +84,7 @@ class cmd_check(Command): print 'Done.' def run(self, config, options, args): - xvfb_pid = self.start_xvfb(options.xvfb_port) + xvfb_pid = self.start_xvfb() try: if options.type == 'pylint': |