<commit_before>import os
import os.path as path
from collections import OrderedDict, deque
from functools import partial

import yaml

from conjureup import async, controllers, utils
from conjureup.app_config import app
from conjureup.controllers.steps import common
from conjureup.models.step import StepModel
from conjureup.ui.views.steps import StepsView
from conjureup.ui.widgets.step import StepWidget
from ubuntui.ev import EventLoop


class StepsController:

    def __init__(self):
        self.view = None
        self.bundle_scripts = path.join(
            app.config['spell-dir'], 'steps'
        )
        self.step_metas = common.get_step_metadata_filenames(
            self.bundle_scripts)

        self.results = OrderedDict()

    def __handle_exception(self, tag, exc):
        utils.pollinate(app.session_id, tag)
        EventLoop.remove_alarms()
        app.ui.show_exception_message(exc)

    def get_result(self, future):
        if future.exception():
            self.__handle_exception('E002', future.exception())

        step_model, step_widget = future.result()

        step_widget.set_icon_state('active')
        step_widget.set_description(
            "{}\n\nResult: {}".format(
                step_model.description,
                step_model.result),
            'info_context')
        step_widget.show_output = False
        step_widget.clear_output()

        app.log.debug("Storing step result for: {}={}".format(
            step_model.title, step_model.result))
        self.results[step_model.title] = step_model.result
        if len(self.view.steps) == 0:
            app.log.debug(
                "End of step list waiting for last step to complete "
                "then rendering summary.")

            self.view.step_pile.contents.append(
                (self.view.buttons(),
                 self.view.step_pile.options()))
            index = self.view.current_summary_button_index
            self.view.step_pile.focus_position = index

    def finish(self, step_model, step_widget, done=False):
        """ handles processing step with input data

        Arguments:
        step_model: step_model returned from widget
        done: if True continues on to the summary view
        """
        if done:
            EventLoop.remove_alarms()
            return controllers.use('summary').render(self.results)

        # Set next button focus here now that the step is complete.
        self.view.steps.popleft()

        if len(self.view.steps) > 0:
            next_step = self.view.steps[0]
            next_step.generate_additional_input()
            self.view.step_pile.focus_position = self.view.step_pile.focus_position + 1  # noqa

        future = async.submit(partial(common.do_step,
                                      step_model,<commit_msg>only show view summary button once<commit_after>import os
import os.path as path
from collections import OrderedDict, deque
from functools import partial

import yaml

from conjureup import async, controllers, utils
from conjureup.app_config import app
from conjureup.controllers.steps import common
from conjureup.models.step import StepModel
from conjureup.ui.views.steps import StepsView
from conjureup.ui.widgets.step import StepWidget
from ubuntui.ev import EventLoop


class StepsController:

    def __init__(self):
        self.view = None
        self.bundle_scripts = path.join(
            app.config['spell-dir'], 'steps'
        )
        self.step_metas = common.get_step_metadata_filenames(
            self.bundle_scripts)

        self.summary_button_exposed = False
        self.results = OrderedDict()

    def __handle_exception(self, tag, exc):
        utils.pollinate(app.session_id, tag)
        EventLoop.remove_alarms()
        app.ui.show_exception_message(exc)

    def get_result(self, future):
        if future.exception():
            self.__handle_exception('E002', future.exception())

        step_model, step_widget = future.result()

        step_widget.set_icon_state('active')
        step_widget.set_description(
            "{}\n\nResult: {}".format(
                step_model.description,
                step_model.result),
            'info_context')
        step_widget.show_output = False
        step_widget.clear_output()

        app.log.debug("Storing step result for: {}={}".format(
            step_model.title, step_model.result))
        self.results[step_model.title] = step_model.result
        if len(self.view.steps) == 0 and not self.summary_button_exposed:
            self.summary_button_exposed = True
            app.log.debug(
                "End of step list waiting for last step to complete "
                "then rendering summary.")

            self.view.step_pile.contents.append(
                (self.view.buttons(),
                 self.view.step_pile.options()))
            index = self.view.current_summary_button_index
            self.view.step_pile.focus_position = index

    def finish(self, step_model, step_widget, done=False):
        """ handles processing step with input data

        Arguments:
        step_model: step_model returned from widget
        done: if True continues on to the summary view
        """
        if done:
            EventLoop.remove_alarms()
            return controllers.use('summary').render(self.results)

        # Set next button focus here now that the step is complete.
        self.view.steps.popleft()

        if len(self.view.steps) > 0:
            next_step = self.view.steps[0]
            next_step.generate_additional_input()
            self.view.step_pile.focus_position = self.view.step_pile.focus_position + 1  # noqa

        future = async.submit(partial(common.do_step,
                                      step_model,
{'fraction_non_alphanumeric': 0.08743074792243767, 'fraction_numerical': 0.0024238227146814403, 'mean_word_length': 2.3163030998851895, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '909431', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1564, 'n_words': 369}