Exemplo n.º 1
0
 def _load(self, arguments):
     self.storage = DataStorage(
         Parser(self.file_system, arguments._file_name),
         FileLog(self.file_system.open_output_stream(arguments.log_file), Arguments.LOG_FORMAT),
         lambda name, format: CSVReport(self.file_system.open_output_stream(arguments.report_for(name)), format))
     self.display.model_loaded(arguments)
     expression = self.storage.model()
     return expression
Exemplo n.º 2
0
Arquivo: ui.py Projeto: fchauvel/MAD
 def _load(self, arguments):
     self.storage = DataStorage(
         Parser(self.file_system, arguments._file_name),
         FileLog(self.file_system.open_output_stream(arguments.log_file), Arguments.LOG_FORMAT),
         lambda name, format: CSVReport(self.file_system.open_output_stream(arguments.report_for(name)), format))
     self.display.model_loaded(arguments)
     expression = self.storage.model()
     self.copy_model(arguments)
     return expression
Exemplo n.º 3
0
Arquivo: ui.py Projeto: fchauvel/MAD
class Controller:
    def __init__(self, output, file_system):
        self.display = Display(output)
        self.file_system = file_system
        self.storage = None

    def execute(self, *command_line):
        try:
            self.display.boot_up()
            arguments = self._parse(command_line)
            expression = self._load(arguments)
            self._validate(expression)
            return self._simulate(expression, arguments)

        except MADSyntaxError as error:
            self._report_invalid_syntax(error)

        except InvalidModel as error:
            self._report_invalid_model(error)

        except InvalidCommandLine as error:
            self._report_invalid_command_line(error)

    def _report_invalid_syntax(self, error):
        self.display.invalid_model()
        self.display.invalid_syntax(error)

    def _report_invalid_model(self, error):
        self.display.invalid_model()
        for each_issue in error.issues:
            each_issue.accept(self.display)

    def _report_invalid_command_line(self, error):
        error.accept(self.display)

    def _parse(self, command_line):
        return Arguments(command_line)

    def _load(self, arguments):
        self.storage = DataStorage(
            Parser(self.file_system, arguments._file_name),
            FileLog(self.file_system.open_output_stream(arguments.log_file),
                    Arguments.LOG_FORMAT), lambda name, format: CSVReport(
                        self.file_system.open_output_stream(
                            arguments.report_for(name)), format))
        self.display.model_loaded(arguments)
        expression = self.storage.model()
        self.copy_model(arguments)
        return expression

    def copy_model(self, arguments):
        source = self.file_system.open_input_stream(arguments._file_name)
        copy = self.file_system.open_output_stream(arguments.model_copy)
        copy.write(source.read())
        self.display.model_copied(arguments)

    def _validate(self, expression):
        validator = Validator()
        validator.validate(expression)
        if validator.raised_warnings():
            for each_warning in validator.errors:
                each_warning.accept(self.display)

    def _simulate(self, expression, arguments):
        simulation = Simulation(self.storage)
        simulation.evaluate(expression)
        simulation.run_until(arguments._time_limit, self.display)
        self.display.simulation_complete(arguments)
        return simulation
Exemplo n.º 4
0
Arquivo: ui.py Projeto: fchauvel/MAD
class Controller:

    def __init__(self, output, file_system):
        self.display = Display(output)
        self.file_system = file_system
        self.storage = None

    def execute(self, *command_line):
        try:
            self.display.boot_up()
            arguments = self._parse(command_line)
            expression = self._load(arguments)
            self._validate(expression)
            return self._simulate(expression, arguments)

        except MADSyntaxError as error:
            self._report_invalid_syntax(error)

        except InvalidModel as error:
            self._report_invalid_model(error)

        except InvalidCommandLine as error:
            self._report_invalid_command_line(error)

    def _report_invalid_syntax(self, error):
        self.display.invalid_model()
        self.display.invalid_syntax(error)

    def _report_invalid_model(self, error):
        self.display.invalid_model()
        for each_issue in error.issues:
            each_issue.accept(self.display)

    def _report_invalid_command_line(self, error):
        error.accept(self.display)

    def _parse(self, command_line):
        return Arguments(command_line)

    def _load(self, arguments):
        self.storage = DataStorage(
            Parser(self.file_system, arguments._file_name),
            FileLog(self.file_system.open_output_stream(arguments.log_file), Arguments.LOG_FORMAT),
            lambda name, format: CSVReport(self.file_system.open_output_stream(arguments.report_for(name)), format))
        self.display.model_loaded(arguments)
        expression = self.storage.model()
        self.copy_model(arguments)
        return expression

    def copy_model(self, arguments):
        source = self.file_system.open_input_stream(arguments._file_name)
        copy = self.file_system.open_output_stream(arguments.model_copy)
        copy.write(source.read())
        self.display.model_copied(arguments)

    def _validate(self, expression):
        validator = Validator()
        validator.validate(expression)
        if validator.raised_warnings():
            for each_warning in validator.errors:
                each_warning.accept(self.display)

    def _simulate(self, expression, arguments):
        simulation = Simulation(self.storage)
        simulation.evaluate(expression)
        simulation.run_until(arguments._time_limit, self.display)
        self.display.simulation_complete(arguments)
        return simulation