diff --git a/awx/main/management/commands/custom_venvs.py b/awx/main/management/commands/custom_venvs.py deleted file mode 100644 index 5a0489c7ee..0000000000 --- a/awx/main/management/commands/custom_venvs.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2021 Ansible, Inc. -# All Rights Reserved - -from awx.main.utils.common import get_custom_venv_choices, get_custom_venv_pip_freeze -from django.core.management.base import BaseCommand - - -class Command(BaseCommand): - """Returns either a list of custom venv paths or outputs the pip freeze from the path passed in the argument""" - - def add_arguments(self, parser): - parser.add_argument( - '--path', - dest='path', - type=str, - default='', - help='run without arguments to see a list of paths, run with one of those paths as an argument and see the pip freeze data', - ) - - def handle(self, *args, **options): - super(Command, self).__init__() - if options.get('path'): - pip_data = get_custom_venv_pip_freeze(options.get('path')) - print(pip_data) - else: - venvs = get_custom_venv_choices() - for venv in venvs: - print(venv) diff --git a/awx/main/management/commands/export_custom_venv.py b/awx/main/management/commands/export_custom_venv.py new file mode 100644 index 0000000000..1ea1d2c0b7 --- /dev/null +++ b/awx/main/management/commands/export_custom_venv.py @@ -0,0 +1,47 @@ +# Copyright (c) 2021 Ansible, Inc. +# All Rights Reserved +import sys + +from awx.main.utils.common import get_custom_venv_choices, get_custom_venv_pip_freeze +from django.core.management.base import BaseCommand +from django.conf import settings + + +class Command(BaseCommand): + """Returns either a list of custom venv paths or outputs the pip freeze from the path passed in the argument""" + + def add_arguments(self, parser): + parser.add_argument( + 'path', + type=str, + nargs='?', + default='', + help='run without arguments to see a list of paths, run with one of those paths as an argument and see the pip freeze data', + ) + + def handle(self, *args, **options): + super(Command, self).__init__() + if options.get('path'): + pip_data = get_custom_venv_pip_freeze(options.get('path')) + if pip_data: + print(pip_data) + else: + venvs = get_custom_venv_choices() + if venvs: + print('# {}'.format("Discovered virtual environments:")) + for venv in venvs: + print(venv) + + msg = [ + '', + 'To export the contents of a virtual environment, ' 're-run while supplying the path as an argument:', + 'awx-manage export_custom_venv /path/to/venv', + ] + print('\n'.join(msg)) + else: + msg = ["No custom virtual environments detected in:", settings.BASE_VENV_PATH] + + for path in settings.CUSTOM_VENV_PATHS: + msg.append(path) + + print('\n'.join(msg), file=sys.stderr)