add the conditionals for incorrect paths and helpful info for if a user does that

and remove unused import
This commit is contained in:
Rebeccah
2021-06-02 13:54:23 -04:00
parent cece7ff741
commit 550ab82f63
4 changed files with 50 additions and 35 deletions

View File

@@ -24,7 +24,7 @@ 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
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

View File

@@ -26,7 +26,8 @@ class Command(BaseCommand):
results = {} results = {}
path = options.get('path') path = options.get('path')
if path: if path:
if path[0] in get_custom_venv_choices(): # verify this is a valid path all_venvs = get_custom_venv_choices()
if path[0] in all_venvs: # verify this is a valid path
path = path[0] path = path[0]
orgs = [{"name": org.name, "id": org.id} for org in Organization.objects.filter(custom_virtualenv=path)] orgs = [{"name": org.name, "id": org.id} for org in Organization.objects.filter(custom_virtualenv=path)]
jts = [{"name": jt.name, "id": jt.id} for jt in JobTemplate.objects.filter(custom_virtualenv=path)] jts = [{"name": jt.name, "id": jt.id} for jt in JobTemplate.objects.filter(custom_virtualenv=path)]
@@ -38,14 +39,21 @@ class Command(BaseCommand):
results["inventory_sources"] = invsrc results["inventory_sources"] = invsrc
print('\n', '# {}'.format("Virtual environments associations:")) print('\n', '# {}'.format("Virtual environments associations:"))
print(yaml.dump(results)) print(yaml.dump(results))
if not options.get('q'):
msg = [ if not options.get('q'):
'', msg = [
'To list all (now deprecated) custom virtual environments run:', '',
'awx-manage list_custom_venvs', '- To list all (now deprecated) custom virtual environments run:',
'', 'awx-manage list_custom_venvs',
'To export the contents of a (deprecated) virtual environment, ' 'run the following command while supplying the path as an argument:', '',
'awx-manage export_custom_venv /path/to/venv', '- To export the contents of a (deprecated) 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)) '- Run these commands with `-q` to remove tool tips.',
'',
]
print('\n'.join(msg))
else:
print('\n', '# Incorrect path, verify your path is from the following list:')
print('\n'.join(all_venvs), '\n')

View File

@@ -1,7 +1,7 @@
# Copyright (c) 2021 Ansible, Inc. # Copyright (c) 2021 Ansible, Inc.
# All Rights Reserved # All Rights Reserved
from awx.main.utils.common import get_custom_venv_pip_freeze from awx.main.utils.common import get_custom_venv_pip_freeze, get_custom_venv_choices
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@@ -21,17 +21,26 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
super(Command, self).__init__() super(Command, self).__init__()
if options.get('path'): if options.get('path'):
pip_data = get_custom_venv_pip_freeze(options.get('path')[0]) path = options.get('path')
if pip_data: all_venvs = get_custom_venv_choices()
print('\n', '# {}'.format("Virtual environment contents:")) if path[0] in all_venvs:
print(pip_data) pip_data = get_custom_venv_pip_freeze(options.get('path')[0])
if not options.get('q'): if pip_data:
msg = [ print('\n', '# {}'.format("Virtual environment contents:"))
'To list all (now deprecated) custom virtual environments run:', print(pip_data)
'awx-manage list_custom_venvs', if not options.get('q'):
'', msg = [
'To view the connections a (deprecated) virtual environment had in the database, run the following command while supplying the path as an argument:', '- To list all (now deprecated) custom virtual environments run:',
'awx-manage custom_venv_associations /path/to/venv', 'awx-manage list_custom_venvs',
'', '',
] '- To view the connections a (deprecated) virtual environment had in the database, run the following command while supplying the path as an argument:',
print('\n'.join(msg)) 'awx-manage custom_venv_associations /path/to/venv',
'',
'- Run these commands with `-q` to remove tool tips.',
'',
]
print('\n'.join(msg))
else:
print('\n', '# Incorrect path, verify your path is from the following list:')
print('\n'.join(all_venvs))

View File

@@ -18,21 +18,19 @@ class Command(BaseCommand):
venvs = get_custom_venv_choices() venvs = get_custom_venv_choices()
if venvs: if venvs:
print('\n', '# {}'.format("Discovered virtual environments:")) print('\n', '# {}'.format("Discovered virtual environments:"))
for venv in venvs: print('\n'.join(venvs), '\n')
print(venv)
if not options.get('q'): if not options.get('q'):
msg = [ msg = [
'', '- To export the contents of a (deprecated) virtual environment, ' 'run the following command while supplying the path as an argument:',
'To export the contents of a (deprecated) virtual environment, ' 'run the following command while supplying the path as an argument:',
'awx-manage export_custom_venv /path/to/venv', 'awx-manage export_custom_venv /path/to/venv',
'', '',
'To view the connections a (deprecated) virtual environment had in the database, run the following command while supplying the path as an argument:', '- To view the connections a (deprecated) virtual environment had in the database, run the following command while supplying the path as an argument:',
'awx-manage custom_venv_associations /path/to/venv', 'awx-manage custom_venv_associations /path/to/venv',
'', '',
'- Run these commands with `-q` to remove tool tips.',
'',
] ]
print('\n'.join(msg)) print('\n'.join(msg))
else:
print('\n')
else: else:
msg = ["No custom virtual environments detected in:", settings.BASE_VENV_PATH] msg = ["No custom virtual environments detected in:", settings.BASE_VENV_PATH]