From 915b917ba655e1724f6da9969823d44a39c0c2c8 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Tue, 4 Feb 2025 13:53:12 -0300 Subject: [PATCH] gst-indent: Refactor indent call to make it callable from other scripts Part-of: --- scripts/gst-indent.py | 34 +++------------------------------- scripts/gst_indent_common.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 scripts/gst_indent_common.py diff --git a/scripts/gst-indent.py b/scripts/gst-indent.py index 4222aa44f3..7ef82e1d23 100755 --- a/scripts/gst-indent.py +++ b/scripts/gst-indent.py @@ -1,36 +1,8 @@ #!/usr/bin/env python -import subprocess from sys import argv -import shutil +from gst_indent_common import indent + if __name__ == '__main__': - indent = shutil.which('gst-indent-1.0') - - if not indent: - raise RuntimeError('''Did not find gst-indent-1.0, please install it before continuing.''') - - version = subprocess.run([indent, '--version'], capture_output=True, text=True) - - if 'GNU' not in version.stdout: - raise RuntimeError(f'''Did not find gst-indent-1.0, please install it before continuing. - (Found {indent}, but it doesn't seem to be gst-indent-1.0)''') - - # Run twice. GNU indent isn't idempotent - # when run once - for i in range(2): - subprocess.check_call([indent, - '--braces-on-if-line', - '--case-brace-indentation0', - '--case-indentation2', - '--braces-after-struct-decl-line', - '--line-length80', - '--no-tabs', - '--cuddle-else', - '--dont-line-up-parentheses', - '--continuation-indentation4', - '--honour-newlines', - '--tab-size8', - '--indent-level2', - '--leave-preprocessor-space'] + argv[1:] - ) + indent(argv[1:]) diff --git a/scripts/gst_indent_common.py b/scripts/gst_indent_common.py new file mode 100644 index 0000000000..d5abd05629 --- /dev/null +++ b/scripts/gst_indent_common.py @@ -0,0 +1,34 @@ +import shutil +import subprocess + + +def indent(*args): + indent = shutil.which('gst-indent-1.0') + + if not indent: + raise RuntimeError('''Did not find gst-indent-1.0, please install it before continuing.''') + + version = subprocess.run([indent, '--version'], capture_output=True, text=True) + + if 'GNU' not in version.stdout: + raise RuntimeError(f'''Did not find gst-indent-1.0, please install it before continuing. + (Found {indent}, but it doesn't seem to be gst-indent-1.0)''') + + # Run twice. GNU indent isn't idempotent + # when run once + for i in range(2): + subprocess.check_call([indent, + '--braces-on-if-line', + '--case-brace-indentation0', + '--case-indentation2', + '--braces-after-struct-decl-line', + '--line-length80', + '--no-tabs', + '--cuddle-else', + '--dont-line-up-parentheses', + '--continuation-indentation4', + '--honour-newlines', + '--tab-size8', + '--indent-level2', + '--leave-preprocessor-space'] + list(args) + )