Example #1
0
def test_get_custom_venv_choices():
    bundled_venv = os.path.join(settings.BASE_VENV_PATH, 'ansible', '')
    assert common.get_custom_venv_choices() == [bundled_venv]

    with TemporaryDirectory(dir=settings.BASE_VENV_PATH,
                            prefix='tmp') as temp_dir:
        os.makedirs(os.path.join(temp_dir, 'bin', 'activate'))
        assert sorted(common.get_custom_venv_choices()) == [
            bundled_venv, os.path.join(temp_dir, '')
        ]
Example #2
0
    def handle(self, *args, **options):
        super(Command, self).__init__()
        venvs = get_custom_venv_choices()
        if venvs:
            if not options.get('q'):
                msg = [
                    '# Discovered Virtual Environments:',
                    '\n'.join(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 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',
                    '',
                    '- Run these commands with `-q` to remove tool tips.',
                    '',
                ]
                print('\n'.join(msg))
            else:
                print('\n'.join(venvs), '\n')
        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)
Example #3
0
    def handle(self, *args, **options):
        super(Command, self).__init__()
        if options.get('path'):
            path = options.get('path')
            all_venvs = get_custom_venv_choices()
            if path[0] in all_venvs:
                pip_data = get_custom_venv_pip_freeze(options.get('path')[0])
                if pip_data:
                    if not options.get('q'):
                        msg = [
                            '# Virtual environment contents:',
                            pip_data,
                            '- To list all (now deprecated) custom virtual environments run:',
                            '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:',
                            'awx-manage custom_venv_associations /path/to/venv',
                            '',
                            '- Run these commands with `-q` to remove tool tips.',
                            '',
                        ]
                        print('\n'.join(msg))
                    else:
                        print(pip_data)

            else:
                print(
                    '\n',
                    '# Incorrect path, verify your path is from the following list:'
                )
                print('\n'.join(all_venvs))
Example #4
0
    def handle(self, *args, **options):
        # look organiztions and unified job templates (which include JTs, workflows, and Inventory updates)
        super(Command, self).__init__()
        results = {}
        path = options.get('path')
        if path:
            all_venvs = get_custom_venv_choices()
            if path[0] in all_venvs:  # verify this is a valid path
                path = path[0]
                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)]
                proj = [{
                    "name": proj.name,
                    "id": proj.id
                } for proj in Project.objects.filter(custom_virtualenv=path)]
                invsrc = [{
                    "name": inv.name,
                    "id": inv.id
                } for inv in InventorySource.objects.filter(
                    custom_virtualenv=path)]
                results["organizations"] = orgs
                results["job_templates"] = jts
                results["projects"] = proj
                results["inventory_sources"] = invsrc
                if not options.get('q'):
                    msg = [
                        '# Virtual Environments Associations:',
                        yaml.dump(results),
                        '- 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',
                        '',
                        '- Run these commands with `-q` to remove tool tips.',
                        '',
                    ]
                    print('\n'.join(msg))
                else:
                    print(yaml.dump(results))

            else:
                print(
                    '\n',
                    '# Incorrect path, verify your path is from the following list:'
                )
                print('\n'.join(all_venvs), '\n')
Example #5
0
def test_get_custom_venv_choices():
    assert common.get_custom_venv_choices() == []

    with TemporaryDirectory(dir=settings.BASE_VENV_PATH) as temp_dir:
        os.makedirs(os.path.join(temp_dir, 'bin', 'activate'))
        assert common.get_custom_venv_choices() == [os.path.join(temp_dir, '')]