Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

container:
# A Docker image with Semgrep installed. Do not change this.
image: returntocorp/semgrep
image: returntocorp/semgrep@sha256:9349edbadf90c3f3c0c3f55867625354e89680e6fa10d9034042af52fdb0e0d0

# Skip any PR created by dependabot to avoid permission issues:
if: (github.actor != 'dependabot[bot]')
Expand Down
22 changes: 19 additions & 3 deletions browserstack/local.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import subprocess, os, time, json,logging
import subprocess, os, time, json, logging, re
import psutil

from browserstack.local_binary import LocalBinary
Expand Down Expand Up @@ -70,7 +70,16 @@ def start(self, **kwargs):
del self.options['key']

if 'binarypath' in self.options:
self.binary_path = self.options['binarypath']
candidate = os.path.realpath(self.options['binarypath'])
if not os.path.isfile(candidate):
raise BrowserStackLocalError('binarypath does not point to a file')
try:
version_output = subprocess.check_output([candidate, '--version']).decode('utf-8')
except (subprocess.SubprocessError, OSError) as e:
raise BrowserStackLocalError('binarypath failed verification: {}'.format(e))
if not re.match(r'BrowserStack Local version \d+\.\d+', version_output):
raise BrowserStackLocalError('binarypath failed verification')
self.binary_path = candidate
del self.options['binarypath']
else:
l = LocalBinary(self.key)
Expand All @@ -93,7 +102,14 @@ def start(self, **kwargs):
self.proc = subprocess.Popen(self._generate_cmd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = self.proc.communicate()

os.system('echo "" > "'+ self.local_logfile_path +'"')
logfile_dir = os.path.dirname(self.local_logfile_path)
if logfile_dir:
os.makedirs(logfile_dir, exist_ok=True)
try:
with open(self.local_logfile_path, 'w') as f:
f.write('')
except OSError as e:
raise BrowserStackLocalError('Unable to open logfile: {}'.format(e))
try:
if out:
output_string = out.decode()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
keywords = ['BrowserStack', 'Local', 'selenium', 'testing'],
classifiers = [],
install_requires=[
'psutil',
'psutil>=5.6.6,<7',
],
)

Loading