Skip to content

Commit cb76139

Browse files
committed
minor fixes
1 parent b5bb4f7 commit cb76139

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

browserstack/local.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def start(self, **kwargs):
7474
if not os.path.isfile(candidate):
7575
raise BrowserStackLocalError('binarypath does not point to a file')
7676
try:
77-
version_output = subprocess.check_output([candidate, '--version']).decode('utf-8')
77+
version_output = subprocess.check_output([candidate, '--version'], timeout=10).decode('utf-8')
7878
except (subprocess.SubprocessError, OSError) as e:
7979
raise BrowserStackLocalError('binarypath failed verification: {}'.format(e))
80-
if not re.match(r'BrowserStack Local version \d+\.\d+', version_output):
80+
if not re.match(LocalBinary.VERSION_REGEX, version_output):
8181
raise BrowserStackLocalError('binarypath failed verification')
8282
self.binary_path = candidate
8383
del self.options['binarypath']
@@ -99,9 +99,6 @@ def start(self, **kwargs):
9999
if 'source' in self.options:
100100
del self.options['source']
101101

102-
self.proc = subprocess.Popen(self._generate_cmd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
103-
(out, err) = self.proc.communicate()
104-
105102
logfile_dir = os.path.dirname(self.local_logfile_path)
106103
if logfile_dir:
107104
os.makedirs(logfile_dir, exist_ok=True)
@@ -110,6 +107,10 @@ def start(self, **kwargs):
110107
f.write('')
111108
except OSError as e:
112109
raise BrowserStackLocalError('Unable to open logfile: {}'.format(e))
110+
111+
self.proc = subprocess.Popen(self._generate_cmd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
112+
(out, err) = self.proc.communicate()
113+
113114
try:
114115
if out:
115116
output_string = out.decode()

browserstack/local_binary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from urllib2 import urlopen, Request
1010

1111
class LocalBinary:
12+
VERSION_REGEX = r"BrowserStack Local version \d+\.\d+"
1213
_version = None
1314

1415
def __init__(self, key, error_object=None):
@@ -159,8 +160,7 @@ def read_chunk(chunk_size):
159160
def __verify_binary(self,path):
160161
try:
161162
binary_response = subprocess.check_output([path,"--version"]).decode("utf-8")
162-
pattern = re.compile("BrowserStack Local version \d+\.\d+")
163-
return bool(pattern.match(binary_response))
163+
return bool(re.match(LocalBinary.VERSION_REGEX, binary_response))
164164
except:
165165
return False
166166

0 commit comments

Comments
 (0)