Merge pull request #3 from miljank/master

Adding ability to pass arbitrary args to Xvfb.
This commit is contained in:
Corey Goldberg 2013-05-18 07:18:26 -07:00
commit 47b27033b4
1 changed files with 10 additions and 5 deletions

View File

@ -18,11 +18,18 @@ import time
class Xvfb:
def __init__(self, width=800, height=680, colordepth=24):
def __init__(self, width=800, height=680, colordepth=24, **kwargs):
self.width = width
self.height = height
self.colordepth = colordepth
self.xvfb_cmd = [
'-screen', '0', '%dx%dx%d' % (self.width, self.height, self.colordepth)
]
for key, value in kwargs.items():
self.xvfb_cmd = self.xvfb_cmd + ["-%s" % key, value]
self.proc = None
if 'DISPLAY' in os.environ:
self.old_display_num = os.environ['DISPLAY'].split(':')[1]
@ -31,10 +38,8 @@ class Xvfb:
def start(self):
self.vdisplay_num = self.search_for_free_display()
self.xvfb_cmd = [
'Xvfb', ':%d' % (self.vdisplay_num,), '-screen', '0',
'%dx%dx%d' % (self.width, self.height, self.colordepth)
]
self.xvfb_cmd = ['Xvfb', ':%d' % self.vdisplay_num] + self.xvfb_cmd
self.proc = subprocess.Popen(self.xvfb_cmd,
stdout=open(os.devnull),
stderr=open(os.devnull))