gst-indent: Refactor indent call to make it callable from other scripts

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8409>
This commit is contained in:
L. E. Segovia 2025-02-04 13:53:12 -03:00 committed by GStreamer Marge Bot
parent 5de3cfca31
commit 915b917ba6
2 changed files with 37 additions and 31 deletions

View File

@ -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:])

View File

@ -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)
)