<commit_before>import petname

from conjureup import async, controllers, juju, utils
from conjureup.app_config import app
from conjureup.ui.views.ControllerListView import ControllerListView


class ControllerPicker:

    def __init__(self):
        self.view = None

    def __handle_exception(self, exc):
        utils.pollinate(app.session_id, "E004")
        app.ui.show_exception_message(exc)

    def __add_model(self):
        juju.switch_controller(app.current_controller)
        juju.add_model(app.current_model)
        juju.switch_model(app.current_model)

    def finish(self, controller):
        utils.pollinate(app.session_id, 'CS')
        if controller is None:
            return controllers.use('clouds').render()

        app.current_controller = controller
        app.current_model = petname.Name()
        async.submit(self.__add_model,
                     self.__handle_exception,
                     queue_name=juju.JUJU_ASYNC_QUEUE)

        return controllers.use('deploy').render()

    def render(self):
        existing_controllers = juju.get_controllers()['controllers']
        if len(existing_controllers) == 0:
            return controllers.use('clouds').render()

        excerpt = app.config.get(
            'description',
            "Please select an existing controller,"
            " or choose to bootstrap a new one.")
        view = ControllerListView(app,
                                  existing_controllers,<commit_msg>Only show controllers matching white/blacklist (#416)<commit_after>import petname

from conjureup import async, controllers, juju, utils
from conjureup.app_config import app
from conjureup.ui.views.ControllerListView import ControllerListView


class ControllerPicker:

    def __init__(self):
        self.view = None

    def __handle_exception(self, exc):
        utils.pollinate(app.session_id, "E004")
        app.ui.show_exception_message(exc)

    def __add_model(self):
        juju.switch_controller(app.current_controller)
        juju.add_model(app.current_model)
        juju.switch_model(app.current_model)

    def finish(self, controller):
        utils.pollinate(app.session_id, 'CS')
        if controller is None:
            return controllers.use('clouds').render()

        app.current_controller = controller
        app.current_model = petname.Name()
        async.submit(self.__add_model,
                     self.__handle_exception,
                     queue_name=juju.JUJU_ASYNC_QUEUE)

        return controllers.use('deploy').render()

    def render(self):
        existing_controllers = juju.get_controllers()['controllers']
        if len(existing_controllers) == 0:
            return controllers.use('clouds').render()

        metadata = app.config['metadata']
        whitelisted_clouds = [c for c in metadata.get('cloud-whitelist', [])]
        blacklisted_clouds = [c for c in metadata.get('cloud-blacklist', [])]
        if len(whitelisted_clouds) > 0:
            filtered_controllers = {n: d for n, d
                                    in existing_controllers.items()
                                    if d['cloud'] in whitelisted_clouds}
        elif len(blacklisted_clouds) > 0:
            filtered_controllers = {n: d for n, d
                                    in existing_controllers.items()
                                    if d['cloud'] not in blacklisted_clouds}
        else:
            filtered_controllers = existing_controllers

        if len(filtered_controllers) == 0:
            return controllers.use('clouds').render()

        excerpt = app.config.get(
            'description',
            "Please select an existing controller,"
            " or choose to bootstrap a new one.")
        view = ControllerListView(app,
                                  filtered_controllers,
{'fraction_non_alphanumeric': 0.09033778476040849, 'fraction_numerical': 0.003665881120712228, 'mean_word_length': 2.281786941580756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6029302', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1014, 'n_words': 219}