Fix print error when migrating to python3.
This is causing errors on the ci: https://ci.chromium.org/p/webrtc/builders/ci/Win32%20Release%20%28Clang%29/24047 No-Presubmit: True Bug: webrtc:13607 Change-Id: I05c85d5d67ab71ef971899a60daffa2c10b72305 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249783 Reviewed-by: Christoffer Jansson <jansson@google.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Jeremy Leconte <jleconte@google.com> Cr-Commit-Position: refs/heads/main@{#35823}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
e8d854eca1
commit
e006b7d103
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env vpython3
|
||||
# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
||||
#
|
||||
# Use of this source code is governed by a BSD-style license
|
||||
@ -36,68 +36,68 @@ WEBCAM_MAC = ('open', '/Applications/ManyCam/ManyCam.app')
|
||||
|
||||
|
||||
def IsWebCamRunning():
|
||||
if sys.platform == 'win32':
|
||||
process_name = 'ManyCam.exe'
|
||||
elif sys.platform.startswith('darwin'):
|
||||
process_name = 'ManyCam'
|
||||
elif sys.platform.startswith('linux'):
|
||||
# TODO(bugs.webrtc.org/9636): Currently a no-op on Linux: sw webcams no
|
||||
# longer in use.
|
||||
print 'Virtual webcam: no-op on Linux'
|
||||
if sys.platform == 'win32':
|
||||
process_name = 'ManyCam.exe'
|
||||
elif sys.platform.startswith('darwin'):
|
||||
process_name = 'ManyCam'
|
||||
elif sys.platform.startswith('linux'):
|
||||
# TODO(bugs.webrtc.org/9636): Currently a no-op on Linux: sw webcams no
|
||||
# longer in use.
|
||||
print('Virtual webcam: no-op on Linux')
|
||||
return True
|
||||
else:
|
||||
raise Exception('Unsupported platform: %s' % sys.platform)
|
||||
for p in psutil.process_iter():
|
||||
try:
|
||||
if process_name == p.name:
|
||||
print('Found a running virtual webcam (%s with PID %s)' %
|
||||
(p.name, p.pid))
|
||||
return True
|
||||
else:
|
||||
raise Exception('Unsupported platform: %s' % sys.platform)
|
||||
for p in psutil.process_iter():
|
||||
try:
|
||||
if process_name == p.name:
|
||||
print 'Found a running virtual webcam (%s with PID %s)' % (
|
||||
p.name, p.pid)
|
||||
return True
|
||||
except psutil.AccessDenied:
|
||||
pass # This is normal if we query sys processes, etc.
|
||||
return False
|
||||
except psutil.AccessDenied:
|
||||
pass # This is normal if we query sys processes, etc.
|
||||
return False
|
||||
|
||||
|
||||
def StartWebCam():
|
||||
try:
|
||||
if sys.platform == 'win32':
|
||||
subprocess.check_call(WEBCAM_WIN)
|
||||
print 'Successfully launched virtual webcam.'
|
||||
elif sys.platform.startswith('darwin'):
|
||||
subprocess.check_call(WEBCAM_MAC)
|
||||
print 'Successfully launched virtual webcam.'
|
||||
elif sys.platform.startswith('linux'):
|
||||
# TODO(bugs.webrtc.org/9636): Currently a no-op on Linux: sw webcams no
|
||||
# longer in use.
|
||||
print 'Not implemented on Linux'
|
||||
try:
|
||||
if sys.platform == 'win32':
|
||||
subprocess.check_call(WEBCAM_WIN)
|
||||
print('Successfully launched virtual webcam.')
|
||||
elif sys.platform.startswith('darwin'):
|
||||
subprocess.check_call(WEBCAM_MAC)
|
||||
print('Successfully launched virtual webcam.')
|
||||
elif sys.platform.startswith('linux'):
|
||||
# TODO(bugs.webrtc.org/9636): Currently a no-op on Linux: sw webcams no
|
||||
# longer in use.
|
||||
print('Not implemented on Linux')
|
||||
|
||||
except Exception as e:
|
||||
print 'Failed to launch virtual webcam: %s' % e
|
||||
return False
|
||||
except Exception as e:
|
||||
print('Failed to launch virtual webcam: %s' % e)
|
||||
return False
|
||||
|
||||
return True
|
||||
return True
|
||||
|
||||
|
||||
def _ForcePythonInterpreter(cmd):
|
||||
"""Returns the fixed command line to call the right python executable."""
|
||||
out = cmd[:]
|
||||
if out[0] == 'python':
|
||||
out[0] = sys.executable
|
||||
elif out[0].endswith('.py'):
|
||||
out.insert(0, sys.executable)
|
||||
return out
|
||||
"""Returns the fixed command line to call the right python executable."""
|
||||
out = cmd[:]
|
||||
if out[0] == 'python':
|
||||
out[0] = sys.executable
|
||||
elif out[0].endswith('.py'):
|
||||
out.insert(0, sys.executable)
|
||||
return out
|
||||
|
||||
|
||||
def Main(argv):
|
||||
if not IsWebCamRunning():
|
||||
if not StartWebCam():
|
||||
return 1
|
||||
if not IsWebCamRunning():
|
||||
if not StartWebCam():
|
||||
return 1
|
||||
|
||||
if argv:
|
||||
return subprocess.call(_ForcePythonInterpreter(argv))
|
||||
else:
|
||||
return 0
|
||||
if argv:
|
||||
return subprocess.call(_ForcePythonInterpreter(argv))
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(Main(sys.argv[1:]))
|
||||
sys.exit(Main(sys.argv[1:]))
|
||||
|
||||
Reference in New Issue
Block a user