mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 11:57:37 -02:30
split the one command into two for clarity and remove unused imports
This commit is contained in:
@@ -24,11 +24,11 @@ from awx.api.generics import APIView
|
|||||||
from awx.conf.registry import settings_registry
|
from awx.conf.registry import settings_registry
|
||||||
from awx.main.analytics import all_collectors
|
from awx.main.analytics import all_collectors
|
||||||
from awx.main.ha import is_ha_environment
|
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.main.utils.licensing import validate_entitlement_manifest
|
||||||
from awx.api.versioning import reverse, drf_reverse
|
from awx.api.versioning import reverse, drf_reverse
|
||||||
from awx.main.constants import PRIVILEGE_ESCALATION_METHODS
|
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
|
from awx.main.utils import set_environ
|
||||||
|
|
||||||
logger = logging.getLogger('awx.api.views.root')
|
logger = logging.getLogger('awx.api.views.root')
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
# Copyright (c) 2021 Ansible, Inc.
|
# Copyright (c) 2021 Ansible, Inc.
|
||||||
# All Rights Reserved
|
# 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.core.management.base import BaseCommand
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
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):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -16,7 +14,7 @@ class Command(BaseCommand):
|
|||||||
type=str,
|
type=str,
|
||||||
nargs='?',
|
nargs='?',
|
||||||
default='',
|
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):
|
def handle(self, *args, **options):
|
||||||
@@ -25,23 +23,10 @@ class Command(BaseCommand):
|
|||||||
pip_data = get_custom_venv_pip_freeze(options.get('path'))
|
pip_data = get_custom_venv_pip_freeze(options.get('path'))
|
||||||
if pip_data:
|
if pip_data:
|
||||||
print(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 = [
|
msg = [
|
||||||
'',
|
'To list all available custom virtual environments run:',
|
||||||
'To export the contents of a virtual environment, ' 're-run while supplying the path as an argument:',
|
'awx-manage list_custom_venvs',
|
||||||
'awx-manage export_custom_venv /path/to/venv',
|
|
||||||
]
|
]
|
||||||
print('\n'.join(msg))
|
print('\n'.join(msg))
|
||||||
else:
|
else:
|
||||||
msg = ["No custom virtual environments detected in:", settings.BASE_VENV_PATH]
|
print("missing argument: please include a path argument following the command.")
|
||||||
|
|
||||||
for path in settings.CUSTOM_VENV_PATHS:
|
|
||||||
msg.append(path)
|
|
||||||
|
|
||||||
print('\n'.join(msg), file=sys.stderr)
|
|
||||||
|
|||||||
33
awx/main/management/commands/list_custom_venvs.py
Normal file
33
awx/main/management/commands/list_custom_venvs.py
Normal file
@@ -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)
|
||||||
@@ -14,8 +14,6 @@ import threading
|
|||||||
import contextlib
|
import contextlib
|
||||||
import tempfile
|
import tempfile
|
||||||
import psutil
|
import psutil
|
||||||
import traceback
|
|
||||||
import sys
|
|
||||||
from functools import reduce, wraps
|
from functools import reduce, wraps
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|||||||
Reference in New Issue
Block a user