Skip to content

Commit 3ce697b

Browse files
committed
Optimize virtual display and logging code
1 parent 6c59e68 commit 3ce697b

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed

seleniumbase/virtual_display/abstractdisplay.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
from seleniumbase.virtual_display import xauth
88

99
mutex = Lock()
10-
RANDOMIZE_DISPLAY_NR = False
11-
if RANDOMIZE_DISPLAY_NR:
12-
import random
13-
random.seed()
1410
MIN_DISPLAY_NR = 1000
1511
USED_DISPLAY_NR_LIST = []
1612

@@ -59,8 +55,6 @@ def search_for_display(self):
5955
display = max(MIN_DISPLAY_NR, max(ls) + 3)
6056
else:
6157
display = MIN_DISPLAY_NR
62-
if RANDOMIZE_DISPLAY_NR:
63-
display += random.randint(0, 100)
6458
return display
6559

6660
def redirect_display(self, on):

seleniumbase/virtual_display/easyprocess.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import time
1414

1515
log = logging.getLogger(__name__)
16+
log.setLevel(logging.ERROR)
1617
SECTION_LINK = 'link'
1718
POLL_TIME = 0.1
1819
USE_POLL = 0

seleniumbase/virtual_display/xauth.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'''Utility functions for xauth.'''
22
import os
33
import hashlib
4-
from seleniumbase.virtual_display import easyprocess
4+
from seleniumbase.virtual_display.easyprocess import EasyProcess
55

66

77
class NotFoundError(Exception):
@@ -14,8 +14,11 @@ def is_installed():
1414
Return whether or not xauth is installed.
1515
'''
1616
try:
17-
easyprocess.EasyProcess(['xauth', '-h']).check_installed()
18-
except easyprocess.EasyProcessCheckInstalledError:
17+
p = EasyProcess(['xauth', '-V'])
18+
p.enable_stdout_log = False
19+
p.enable_stderr_log = False
20+
p.call()
21+
except Exception:
1922
return False
2023
else:
2124
return True
@@ -33,4 +36,4 @@ def call(*args):
3336
'''
3437
Call xauth with the given args.
3538
'''
36-
easyprocess.EasyProcess(['xauth'] + list(args)).call()
39+
EasyProcess(['xauth'] + list(args)).call()

seleniumbase/virtual_display/xephyr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from seleniumbase.virtual_display.easyprocess import EasyProcess
22
from seleniumbase.virtual_display.abstractdisplay import AbstractDisplay
33

4-
PACKAGE = 'xephyr'
54
PROGRAM = 'Xephyr'
6-
URL = None
75

86

97
class XephyrDisplay(AbstractDisplay):
@@ -26,8 +24,10 @@ def __init__(self, size=(1024, 768), color_depth=24, bgcolor='black'):
2624

2725
@classmethod
2826
def check_installed(cls):
29-
EasyProcess([PROGRAM, '-help'], url=URL,
30-
ubuntu_package=PACKAGE).check_installed()
27+
p = EasyProcess([PROGRAM, '-help'])
28+
p.enable_stdout_log = False
29+
p.enable_stderr_log = False
30+
p.call()
3131

3232
@property
3333
def _cmd(self):

seleniumbase/virtual_display/xvfb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from seleniumbase.virtual_display.easyprocess import EasyProcess
22
from seleniumbase.virtual_display.abstractdisplay import AbstractDisplay
33

4-
PACKAGE = 'xvfb'
54
PROGRAM = 'Xvfb'
6-
URL = None
75

86

97
class XvfbDisplay(AbstractDisplay):
@@ -32,8 +30,10 @@ def __init__(self, size=(1024, 768), color_depth=24,
3230

3331
@classmethod
3432
def check_installed(cls):
35-
EasyProcess([PROGRAM, '-help'], url=URL,
36-
ubuntu_package=PACKAGE).check_installed()
33+
p = EasyProcess([PROGRAM, '-help'])
34+
p.enable_stdout_log = False
35+
p.enable_stderr_log = False
36+
p.call()
3737

3838
@property
3939
def _cmd(self):

seleniumbase/virtual_display/xvnc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from seleniumbase.virtual_display.easyprocess import EasyProcess
22
from seleniumbase.virtual_display.abstractdisplay import AbstractDisplay
33

4-
PACKAGE = 'tightvncserver'
54
PROGRAM = 'Xvnc'
6-
URL = None
75

86

97
class XvncDisplay(AbstractDisplay):
@@ -30,8 +28,10 @@ def __init__(self, size=(1024, 768), color_depth=24,
3028

3129
@classmethod
3230
def check_installed(cls):
33-
EasyProcess([PROGRAM, '-help'], url=URL,
34-
ubuntu_package=PACKAGE).check_installed()
31+
p = EasyProcess([PROGRAM, '-help'])
32+
p.enable_stdout_log = False
33+
p.enable_stderr_log = False
34+
p.call()
3535

3636
@property
3737
def _cmd(self):

0 commit comments

Comments
 (0)