|
|
@ -841,17 +841,31 @@ class Popen(subprocess.Popen):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
_startupinfo = None
|
|
|
|
_startupinfo = None
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
def __init__(self, *args, text=False, **kwargs):
|
|
|
|
|
|
|
|
if text is True:
|
|
|
|
|
|
|
|
kwargs['universal_newlines'] = True # For 3.6 compatibility
|
|
|
|
|
|
|
|
kwargs.setdefault('encoding', 'utf-8')
|
|
|
|
|
|
|
|
kwargs.setdefault('errors', 'replace')
|
|
|
|
super().__init__(*args, **kwargs, startupinfo=self._startupinfo)
|
|
|
|
super().__init__(*args, **kwargs, startupinfo=self._startupinfo)
|
|
|
|
|
|
|
|
|
|
|
|
def communicate_or_kill(self, *args, **kwargs):
|
|
|
|
def communicate_or_kill(self, *args, **kwargs):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
return self.communicate(*args, **kwargs)
|
|
|
|
return self.communicate(*args, **kwargs)
|
|
|
|
except BaseException: # Including KeyboardInterrupt
|
|
|
|
except BaseException: # Including KeyboardInterrupt
|
|
|
|
self.kill()
|
|
|
|
self.kill(timeout=None)
|
|
|
|
self.wait()
|
|
|
|
|
|
|
|
raise
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def kill(self, *, timeout=0):
|
|
|
|
|
|
|
|
super().kill()
|
|
|
|
|
|
|
|
if timeout != 0:
|
|
|
|
|
|
|
|
self.wait(timeout=timeout)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
|
|
def run(cls, *args, **kwargs):
|
|
|
|
|
|
|
|
with cls(*args, **kwargs) as proc:
|
|
|
|
|
|
|
|
stdout, stderr = proc.communicate_or_kill()
|
|
|
|
|
|
|
|
return stdout or '', stderr or '', proc.returncode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_subprocess_encoding():
|
|
|
|
def get_subprocess_encoding():
|
|
|
|
if sys.platform == 'win32' and sys.getwindowsversion()[0] >= 5:
|
|
|
|
if sys.platform == 'win32' and sys.getwindowsversion()[0] >= 5:
|
|
|
@ -2556,7 +2570,7 @@ def check_executable(exe, args=[]):
|
|
|
|
""" Checks if the given binary is installed somewhere in PATH, and returns its name.
|
|
|
|
""" Checks if the given binary is installed somewhere in PATH, and returns its name.
|
|
|
|
args can be a list of arguments for a short output (like -version) """
|
|
|
|
args can be a list of arguments for a short output (like -version) """
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
Popen([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate_or_kill()
|
|
|
|
Popen.run([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
except OSError:
|
|
|
|
except OSError:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
return exe
|
|
|
|
return exe
|
|
|
@ -2569,14 +2583,11 @@ def _get_exe_version_output(exe, args, *, to_screen=None):
|
|
|
|
# STDIN should be redirected too. On UNIX-like systems, ffmpeg triggers
|
|
|
|
# STDIN should be redirected too. On UNIX-like systems, ffmpeg triggers
|
|
|
|
# SIGTTOU if yt-dlp is run in the background.
|
|
|
|
# SIGTTOU if yt-dlp is run in the background.
|
|
|
|
# See https://github.com/ytdl-org/youtube-dl/issues/955#issuecomment-209789656
|
|
|
|
# See https://github.com/ytdl-org/youtube-dl/issues/955#issuecomment-209789656
|
|
|
|
out, _ = Popen(
|
|
|
|
stdout, _, _ = Popen.run([encodeArgument(exe)] + args, text=True,
|
|
|
|
[encodeArgument(exe)] + args, stdin=subprocess.PIPE,
|
|
|
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate_or_kill()
|
|
|
|
|
|
|
|
except OSError:
|
|
|
|
except OSError:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
if isinstance(out, bytes): # Python 2.x
|
|
|
|
return stdout
|
|
|
|
out = out.decode('ascii', 'ignore')
|
|
|
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def detect_exe_version(output, version_re=None, unrecognized='present'):
|
|
|
|
def detect_exe_version(output, version_re=None, unrecognized='present'):
|
|
|
@ -4796,14 +4807,13 @@ def write_xattr(path, key, value):
|
|
|
|
|
|
|
|
|
|
|
|
value = value.decode()
|
|
|
|
value = value.decode()
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
p = Popen(
|
|
|
|
_, stderr, returncode = Popen.run(
|
|
|
|
[exe, '-w', key, value, path] if exe == 'xattr' else [exe, '-n', key, '-v', value, path],
|
|
|
|
[exe, '-w', key, value, path] if exe == 'xattr' else [exe, '-n', key, '-v', value, path],
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
|
|
|
except OSError as e:
|
|
|
|
except OSError as e:
|
|
|
|
raise XAttrMetadataError(e.errno, e.strerror)
|
|
|
|
raise XAttrMetadataError(e.errno, e.strerror)
|
|
|
|
stderr = p.communicate_or_kill()[1].decode('utf-8', 'replace')
|
|
|
|
if returncode:
|
|
|
|
if p.returncode:
|
|
|
|
raise XAttrMetadataError(returncode, stderr)
|
|
|
|
raise XAttrMetadataError(p.returncode, stderr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def random_birthday(year_field, month_field, day_field):
|
|
|
|
def random_birthday(year_field, month_field, day_field):
|
|
|
@ -5146,10 +5156,8 @@ def windows_enable_vt_mode(): # TODO: Do this the proper way https://bugs.pytho
|
|
|
|
if get_windows_version() < (10, 0, 10586):
|
|
|
|
if get_windows_version() < (10, 0, 10586):
|
|
|
|
return
|
|
|
|
return
|
|
|
|
global WINDOWS_VT_MODE
|
|
|
|
global WINDOWS_VT_MODE
|
|
|
|
startupinfo = subprocess.STARTUPINFO()
|
|
|
|
|
|
|
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
subprocess.Popen('', shell=True, startupinfo=startupinfo).wait()
|
|
|
|
Popen.run('', shell=True)
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|