diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/media/webrtc/third_party_build/run_operations.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webrtc/third_party_build/run_operations.py')
-rw-r--r-- | dom/media/webrtc/third_party_build/run_operations.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/dom/media/webrtc/third_party_build/run_operations.py b/dom/media/webrtc/third_party_build/run_operations.py new file mode 100644 index 0000000000..794ea268d8 --- /dev/null +++ b/dom/media/webrtc/third_party_build/run_operations.py @@ -0,0 +1,78 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +import os +import subprocess +import sys + +# This is a collection of helper functions that use the subprocess.run +# command to execute commands. In the future, if we have cases where +# we find common python functionality in utilizing the data returned +# from these functions, that functionality can live here for easy reuse +# between other python scripts in dom/media/webrtc/third_party_build. + + +# must run 'hg' with HGPLAIN=1 to ensure aliases don't interfere with +# command output. +env = os.environ.copy() +env["HGPLAIN"] = "1" + + +def run_hg(cmd): + cmd_list = cmd.split(" ") + res = subprocess.run( + cmd_list, + capture_output=True, + text=True, + env=env, + ) + if res.returncode != 0: + print( + "Hit return code {} running '{}'. Aborting.".format(res.returncode, cmd), + file=sys.stderr, + ) + print(res.stderr) + sys.exit(1) + stdout = res.stdout.strip() + return [] if len(stdout) == 0 else stdout.split("\n") + + +def run_git(cmd, working_dir): + cmd_list = cmd.split(" ") + res = subprocess.run( + cmd_list, + capture_output=True, + text=True, + cwd=working_dir, + ) + if res.returncode != 0: + print( + "Hit return code {} running '{}'. Aborting.".format(res.returncode, cmd), + file=sys.stderr, + ) + print(res.stderr) + sys.exit(1) + stdout = res.stdout.strip() + return [] if len(stdout) == 0 else stdout.split("\n") + + +def run_shell(cmd, capture_output=True): + res = subprocess.run( + cmd, + shell=True, + capture_output=capture_output, + text=True, + ) + if res.returncode != 0: + print( + "Hit return code {} running '{}'. Aborting.".format(res.returncode, cmd), + file=sys.stderr, + ) + print(res.stderr) + sys.exit(1) + output_lines = [] + if capture_output: + stdout = res.stdout.strip() + output_lines = [] if len(stdout) == 0 else stdout.split("\n") + + return output_lines |