From 779ca8b260018d13df22c83d29e7819d41073301 Mon Sep 17 00:00:00 2001 From: Rebeccah Date: Wed, 12 May 2021 11:48:40 -0400 Subject: [PATCH] split the one command into two for clarity and remove unused imports --- awx/api/views/root.py | 4 +-- .../management/commands/export_custom_venv.py | 29 ++++------------ .../management/commands/list_custom_venvs.py | 33 +++++++++++++++++++ awx/main/utils/common.py | 2 -- 4 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 awx/main/management/commands/list_custom_venvs.py diff --git a/awx/api/views/root.py b/awx/api/views/root.py index 9ab8ff0840..393440fe5c 100644 --- a/awx/api/views/root.py +++ b/awx/api/views/root.py @@ -24,11 +24,11 @@ from awx.api.generics import APIView from awx.conf.registry import settings_registry from awx.main.analytics import all_collectors from awx.main.ha import is_ha_environment -from awx.main.utils import get_awx_version, get_custom_venv_choices +from awx.main.utils import get_awx_version, to_python_boolean, get_custom_venv_choices from awx.main.utils.licensing import validate_entitlement_manifest from awx.api.versioning import reverse, drf_reverse from awx.main.constants import PRIVILEGE_ESCALATION_METHODS -from awx.main.models import Project, Organization, Instance, InstanceGroup, JobTemplate +from awx.main.models import Project, Organization, Instance, InstanceGroup from awx.main.utils import set_environ logger = logging.getLogger('awx.api.views.root') diff --git a/awx/main/management/commands/export_custom_venv.py b/awx/main/management/commands/export_custom_venv.py index 1ea1d2c0b7..93ef6d71f4 100644 --- a/awx/main/management/commands/export_custom_venv.py +++ b/awx/main/management/commands/export_custom_venv.py @@ -1,14 +1,12 @@ # 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 awx.main.utils.common import 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""" + """Returns the pip freeze from the path passed in the argument""" def add_arguments(self, parser): parser.add_argument( @@ -16,7 +14,7 @@ class Command(BaseCommand): 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', + help='run this with a path to a virutal environment as an argument to see the pip freeze data', ) def handle(self, *args, **options): @@ -25,23 +23,10 @@ class Command(BaseCommand): 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', + 'To list all available custom virtual environments run:', + 'awx-manage list_custom_venvs', ] 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) + else: + print("missing argument: please include a path argument following the command.") diff --git a/awx/main/management/commands/list_custom_venvs.py b/awx/main/management/commands/list_custom_venvs.py new file mode 100644 index 0000000000..bec712eaf9 --- /dev/null +++ b/awx/main/management/commands/list_custom_venvs.py @@ -0,0 +1,33 @@ +# Copyright (c) 2021 Ansible, Inc. +# All Rights Reserved +import sys + +from awx.main.utils.common import get_custom_venv_choices +from django.core.management.base import BaseCommand +from django.conf import settings + + +class Command(BaseCommand): + """Returns either a list of custom venv paths from the path passed in the argument""" + + def handle(self, *args, **options): + super(Command, self).__init__() + 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, ' 'run the following command 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) diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index e33d132245..873717b5fa 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -14,8 +14,6 @@ import threading import contextlib import tempfile import psutil -import traceback -import sys from functools import reduce, wraps from decimal import Decimal