mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-03 05:59:10 +00:00
gst-env: Improve coding style and cleanup
* Remove unused variables * Remove unused imports * Apply pycodestyle style suggestions - Missing newlines - spaces before brackets - Wrong indentations Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1743>
This commit is contained in:
parent
c769a089ea
commit
cfea428081
1 changed files with 30 additions and 22 deletions
52
gst-env.py
52
gst-env.py
|
@ -1,17 +1,14 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import contextlib
|
|
||||||
import glob
|
import glob
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
import site
|
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import pathlib
|
import pathlib
|
||||||
import signal
|
import signal
|
||||||
|
@ -42,7 +39,7 @@ SHAREDLIB_REG = re.compile(r'\.so|\.dylib|\.dll')
|
||||||
GSTPLUGIN_FILEPATH_REG_TEMPLATE = r'.*/{libdir}/gstreamer-1.0/[^/]+$'
|
GSTPLUGIN_FILEPATH_REG_TEMPLATE = r'.*/{libdir}/gstreamer-1.0/[^/]+$'
|
||||||
GSTPLUGIN_FILEPATH_REG = None
|
GSTPLUGIN_FILEPATH_REG = None
|
||||||
|
|
||||||
BC_RC = '''
|
BC_RC = '''
|
||||||
BASH_COMPLETION_SCRIPTS="{bash_completions}"
|
BASH_COMPLETION_SCRIPTS="{bash_completions}"
|
||||||
BASH_COMPLETION_PATHS="{bash_completions_paths}"
|
BASH_COMPLETION_PATHS="{bash_completions_paths}"
|
||||||
for p in $BASH_COMPLETION_PATHS; do
|
for p in $BASH_COMPLETION_PATHS; do
|
||||||
|
@ -71,6 +68,7 @@ def listify(o):
|
||||||
return o
|
return o
|
||||||
raise AssertionError('Object {!r} must be a string or a list'.format(o))
|
raise AssertionError('Object {!r} must be a string or a list'.format(o))
|
||||||
|
|
||||||
|
|
||||||
def stringify(o):
|
def stringify(o):
|
||||||
if isinstance(o, str):
|
if isinstance(o, str):
|
||||||
return o
|
return o
|
||||||
|
@ -80,6 +78,7 @@ def stringify(o):
|
||||||
raise AssertionError('Did not expect object {!r} to have more than one element'.format(o))
|
raise AssertionError('Did not expect object {!r} to have more than one element'.format(o))
|
||||||
raise AssertionError('Object {!r} must be a string or a list'.format(o))
|
raise AssertionError('Object {!r} must be a string or a list'.format(o))
|
||||||
|
|
||||||
|
|
||||||
def prepend_env_var(env, var, value, sysroot):
|
def prepend_env_var(env, var, value, sysroot):
|
||||||
if var is None:
|
if var is None:
|
||||||
return
|
return
|
||||||
|
@ -96,6 +95,7 @@ def prepend_env_var(env, var, value, sysroot):
|
||||||
env[var] = val + env_val
|
env[var] = val + env_val
|
||||||
env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
|
env[var] = env[var].replace(os.pathsep + os.pathsep, os.pathsep).strip(os.pathsep)
|
||||||
|
|
||||||
|
|
||||||
def get_target_install_filename(target, filename):
|
def get_target_install_filename(target, filename):
|
||||||
'''
|
'''
|
||||||
Checks whether this file is one of the files installed by the target
|
Checks whether this file is one of the files installed by the target
|
||||||
|
@ -106,6 +106,7 @@ def get_target_install_filename(target, filename):
|
||||||
return install_filename
|
return install_filename
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_pkgconfig_variable_from_pcfile(pcfile, varname):
|
def get_pkgconfig_variable_from_pcfile(pcfile, varname):
|
||||||
variables = {}
|
variables = {}
|
||||||
substre = re.compile('\$\{[^${}]+\}')
|
substre = re.compile('\$\{[^${}]+\}')
|
||||||
|
@ -123,6 +124,7 @@ def get_pkgconfig_variable_from_pcfile(pcfile, varname):
|
||||||
variables[key] = value
|
variables[key] = value
|
||||||
return variables.get(varname, '')
|
return variables.get(varname, '')
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
def get_pkgconfig_variable(builddir, pcname, varname):
|
def get_pkgconfig_variable(builddir, pcname, varname):
|
||||||
'''
|
'''
|
||||||
|
@ -147,6 +149,7 @@ def is_gio_module(target, filename, builddir):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def is_library_target_and_not_plugin(target, filename):
|
def is_library_target_and_not_plugin(target, filename):
|
||||||
'''
|
'''
|
||||||
Don't add plugins to PATH/LD_LIBRARY_PATH because:
|
Don't add plugins to PATH/LD_LIBRARY_PATH because:
|
||||||
|
@ -169,6 +172,7 @@ def is_library_target_and_not_plugin(target, filename):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def is_binary_target_and_in_path(target, filename, bindir):
|
def is_binary_target_and_in_path(target, filename, bindir):
|
||||||
if target['type'] != 'executable':
|
if target['type'] != 'executable':
|
||||||
return False
|
return False
|
||||||
|
@ -200,6 +204,7 @@ def get_wine_subprocess_env(options, env):
|
||||||
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
|
||||||
def setup_gdb(options):
|
def setup_gdb(options):
|
||||||
python_paths = set()
|
python_paths = set()
|
||||||
|
|
||||||
|
@ -242,20 +247,22 @@ def setup_gdb(options):
|
||||||
|
|
||||||
return python_paths
|
return python_paths
|
||||||
|
|
||||||
def is_bash_completion_available (options):
|
|
||||||
return os.path.exists(os.path.join(options.builddir, 'subprojects/gstreamer/data/bash-completion/helpers/gst'))
|
def is_bash_completion_available(options):
|
||||||
|
return os.path.exists(os.path.join(options.builddir, 'subprojects/gstreamer/data/bash-completion/helpers/gst'))
|
||||||
|
|
||||||
|
|
||||||
def get_subprocess_env(options, gst_version):
|
def get_subprocess_env(options, gst_version):
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
|
|
||||||
env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
|
env["CURRENT_GST"] = os.path.normpath(SCRIPTDIR)
|
||||||
env["GST_VERSION"] = gst_version
|
env["GST_VERSION"] = gst_version
|
||||||
prepend_env_var (env, "GST_VALIDATE_SCENARIOS_PATH", os.path.normpath(
|
prepend_env_var(env, "GST_VALIDATE_SCENARIOS_PATH", os.path.normpath(
|
||||||
"%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR),
|
"%s/subprojects/gst-devtools/validate/data/scenarios" % SCRIPTDIR),
|
||||||
options.sysroot)
|
options.sysroot)
|
||||||
env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
|
env["GST_VALIDATE_PLUGIN_PATH"] = os.path.normpath(
|
||||||
"%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
|
"%s/subprojects/gst-devtools/validate/plugins" % options.builddir)
|
||||||
prepend_env_var (env, "GST_VALIDATE_APPS_DIR", os.path.normpath(
|
prepend_env_var(env, "GST_VALIDATE_APPS_DIR", os.path.normpath(
|
||||||
"%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR),
|
"%s/subprojects/gst-editing-services/tests/validate" % SCRIPTDIR),
|
||||||
options.sysroot)
|
options.sysroot)
|
||||||
env["GST_ENV"] = 'gst-' + gst_version
|
env["GST_ENV"] = 'gst-' + gst_version
|
||||||
|
@ -264,10 +271,10 @@ def get_subprocess_env(options, gst_version):
|
||||||
"%s/subprojects/gst-devtools/validate/tools" % options.builddir),
|
"%s/subprojects/gst-devtools/validate/tools" % options.builddir),
|
||||||
options.sysroot)
|
options.sysroot)
|
||||||
|
|
||||||
prepend_env_var (env, "GST_VALIDATE_SCENARIOS_PATH", os.path.normpath(
|
prepend_env_var(env, "GST_VALIDATE_SCENARIOS_PATH", os.path.normpath(
|
||||||
"%s/subprojects/gst-examples/webrtc/check/validate/scenarios" %
|
"%s/subprojects/gst-examples/webrtc/check/validate/scenarios" %
|
||||||
SCRIPTDIR), options.sysroot)
|
SCRIPTDIR), options.sysroot)
|
||||||
prepend_env_var (env, "GST_VALIDATE_APPS_DIR", os.path.normpath(
|
prepend_env_var(env, "GST_VALIDATE_APPS_DIR", os.path.normpath(
|
||||||
"%s/subprojects/gst-examples/webrtc/check/validate/apps" %
|
"%s/subprojects/gst-examples/webrtc/check/validate/apps" %
|
||||||
SCRIPTDIR), options.sysroot)
|
SCRIPTDIR), options.sysroot)
|
||||||
|
|
||||||
|
@ -404,7 +411,6 @@ def get_subprocess_env(options, gst_version):
|
||||||
installed_s = subprocess.check_output(meson + ['introspect', options.builddir, '--installed'])
|
installed_s = subprocess.check_output(meson + ['introspect', options.builddir, '--installed'])
|
||||||
for path, installpath in json.loads(installed_s.decode()).items():
|
for path, installpath in json.loads(installed_s.decode()).items():
|
||||||
installpath_parts = pathlib.Path(installpath).parts
|
installpath_parts = pathlib.Path(installpath).parts
|
||||||
path_parts = pathlib.Path(path).parts
|
|
||||||
|
|
||||||
# We want to add all python modules to the PYTHONPATH
|
# We want to add all python modules to the PYTHONPATH
|
||||||
# in a manner consistent with the way they would be imported:
|
# in a manner consistent with the way they would be imported:
|
||||||
|
@ -423,7 +429,7 @@ def get_subprocess_env(options, gst_version):
|
||||||
if os.path.commonprefix(["gi/overrides", install_subpath]):
|
if os.path.commonprefix(["gi/overrides", install_subpath]):
|
||||||
overrides_dirs.add(os.path.dirname(path))
|
overrides_dirs.add(os.path.dirname(path))
|
||||||
else:
|
else:
|
||||||
python_dirs.add(path[:len (install_subpath) * -1])
|
python_dirs.add(path[:len(install_subpath) * -1])
|
||||||
|
|
||||||
if path.endswith('.prs'):
|
if path.endswith('.prs'):
|
||||||
presets.add(os.path.dirname(path))
|
presets.add(os.path.dirname(path))
|
||||||
|
@ -466,11 +472,11 @@ def get_subprocess_env(options, gst_version):
|
||||||
# Preserve default paths when empty
|
# Preserve default paths when empty
|
||||||
prepend_env_var(env, 'XDG_DATA_DIRS', '/usr/local/share/:/usr/share/', '')
|
prepend_env_var(env, 'XDG_DATA_DIRS', '/usr/local/share/:/usr/share/', '')
|
||||||
|
|
||||||
prepend_env_var (env, 'XDG_DATA_DIRS', os.path.join(options.builddir,
|
prepend_env_var(env, 'XDG_DATA_DIRS', os.path.join(options.builddir,
|
||||||
'subprojects',
|
'subprojects',
|
||||||
'gst-docs',
|
'gst-docs',
|
||||||
'GStreamer-doc'),
|
'GStreamer-doc'),
|
||||||
options.sysroot)
|
options.sysroot)
|
||||||
|
|
||||||
if 'XDG_CONFIG_DIRS' not in env or not env['XDG_CONFIG_DIRS']:
|
if 'XDG_CONFIG_DIRS' not in env or not env['XDG_CONFIG_DIRS']:
|
||||||
# Preserve default paths when empty
|
# Preserve default paths when empty
|
||||||
|
@ -481,12 +487,14 @@ def get_subprocess_env(options, gst_version):
|
||||||
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
|
||||||
def get_windows_shell():
|
def get_windows_shell():
|
||||||
command = ['powershell.exe' ,'-noprofile', '-executionpolicy', 'bypass', '-file',
|
command = ['powershell.exe', '-noprofile', '-executionpolicy', 'bypass', '-file',
|
||||||
os.path.join(SCRIPTDIR, 'data', 'misc', 'cmd_or_ps.ps1')]
|
os.path.join(SCRIPTDIR, 'data', 'misc', 'cmd_or_ps.ps1')]
|
||||||
result = subprocess.check_output(command)
|
result = subprocess.check_output(command)
|
||||||
return result.decode().strip()
|
return result.decode().strip()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(prog="gst-env")
|
parser = argparse.ArgumentParser(prog="gst-env")
|
||||||
|
|
||||||
|
@ -536,10 +544,10 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# The following incantation will retrieve the current branch name.
|
# The following incantation will retrieve the current branch name.
|
||||||
try:
|
try:
|
||||||
gst_version = git("rev-parse", "--symbolic-full-name", "--abbrev-ref", "HEAD",
|
gst_version = git("rev-parse", "--symbolic-full-name", "--abbrev-ref", "HEAD",
|
||||||
repository_path=options.srcdir).strip('\n')
|
repository_path=options.srcdir).strip('\n')
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
gst_version = "unknown"
|
gst_version = "unknown"
|
||||||
|
|
||||||
if options.wine:
|
if options.wine:
|
||||||
gst_version += '-' + os.path.basename(options.wine)
|
gst_version += '-' + os.path.basename(options.wine)
|
||||||
|
@ -571,7 +579,7 @@ if __name__ == "__main__":
|
||||||
bash_completions_files = []
|
bash_completions_files = []
|
||||||
for p in BASH_COMPLETION_PATHS:
|
for p in BASH_COMPLETION_PATHS:
|
||||||
if os.path.exists(p):
|
if os.path.exists(p):
|
||||||
bash_completions_files += os.listdir(path=p)
|
bash_completions_files += os.listdir(path=p)
|
||||||
bc_rc = BC_RC.format(bash_completions=' '.join(bash_completions_files), bash_completions_paths=' '.join(BASH_COMPLETION_PATHS))
|
bc_rc = BC_RC.format(bash_completions=' '.join(bash_completions_files), bash_completions_paths=' '.join(BASH_COMPLETION_PATHS))
|
||||||
tmprc.write(bc_rc)
|
tmprc.write(bc_rc)
|
||||||
tmprc.flush()
|
tmprc.flush()
|
||||||
|
|
Loading…
Reference in a new issue