Browse Source

Merge pull request #3 from miljank/master

Adding ability to pass arbitrary args to Xvfb.
changes/49/376949/1
Corey Goldberg 8 years ago
parent
commit
47b27033b4
  1. 15
      xvfbwrapper/xvfbwrapper.py

15
xvfbwrapper/xvfbwrapper.py

@ -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))

Loading…
Cancel
Save