diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-06-16 02:25:43 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-06-16 06:23:50 +0530 |
commit | f0c9fb96827ff798a48626e7e5d32a9c5de7b97e (patch) | |
tree | 440139f107fb95d967f5ff32361a194e4e5afd22 /yt_dlp/YoutubeDL.py | |
parent | 560738f34de4df6eaf82290fd503def3f366f878 (diff) | |
download | hypervideo-pre-f0c9fb96827ff798a48626e7e5d32a9c5de7b97e.tar.lz hypervideo-pre-f0c9fb96827ff798a48626e7e5d32a9c5de7b97e.tar.xz hypervideo-pre-f0c9fb96827ff798a48626e7e5d32a9c5de7b97e.zip |
[utils] `Popen`: Refactor to use contextmanager
Fixes https://github.com/yt-dlp/yt-dlp/issues/3531#issuecomment-1156223597
Diffstat (limited to 'yt_dlp/YoutubeDL.py')
-rw-r--r-- | yt_dlp/YoutubeDL.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 1932af3fe..ffb0e1adf 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -3705,14 +3705,12 @@ class YoutubeDL: if source == 'source': try: - sp = Popen( + stdout, _, _ = Popen.run( ['git', 'rev-parse', '--short', 'HEAD'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE, - cwd=os.path.dirname(os.path.abspath(__file__))) - out, err = sp.communicate_or_kill() - out = out.decode().strip() - if re.match('[0-9a-f]+', out): - write_debug('Git HEAD: %s' % out) + text=True, cwd=os.path.dirname(os.path.abspath(__file__)), + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if re.fullmatch('[0-9a-f]+', stdout.strip()): + write_debug(f'Git HEAD: {stdout.strip()}') except Exception: with contextlib.suppress(Exception): sys.exc_clear() |