def create_stimulus(self):
        """
        Creates a stimulus from the given data.
        """
        try:
            current_surface_stim = common.get_from_session(KEY_SURFACE_STIMULI)
            surface_stimulus_creator = ABCAdapter.build_adapter_from_class(
                SurfaceStimulusCreator)
            self.operation_service.fire_operation(
                surface_stimulus_creator,
                common.get_logged_user(),
                common.get_current_project().id,
                view_model=current_surface_stim)
            common.set_important_message(
                "The operation for creating the stimulus was successfully launched."
            )

        except (NameError, ValueError, SyntaxError):
            common.set_error_message(
                "The operation failed due to invalid parameter input.")
            return False
        except Exception as ex:
            common.set_error_message(ex)
            return False
        return True
Esempio n. 2
0
 def settings(self, save_settings=False, **data):
     """Main settings page submit and get"""
     template_specification = dict(mainContent="settings/system_settings", title="System Settings")
     if save_settings:
         try:
             form = SettingsForm()
             data = form.to_python(data)
             isrestart, isreset = self.settingsservice.save_settings(**data)
             if isrestart:
                 thread = threading.Thread(target=self._restart_services, kwargs={'should_reset': isreset})
                 thread.start()
                 common.add2session(common.KEY_IS_RESTART, True)
                 common.set_important_message('Please wait until TVB is restarted properly!')
                 raise cherrypy.HTTPRedirect('/tvb')
             # Here we will leave the same settings page to be displayed.
             # It will continue reloading when CherryPy restarts.
         except formencode.Invalid as excep:
             template_specification[common.KEY_ERRORS] = excep.unpack_errors()
         except InvalidSettingsException as excep:
             self.logger.error('Invalid settings!  Exception %s was raised' % (str(excep)))
             common.set_error_message(excep.message)
     template_specification.update({'keys_order': self.settingsservice.KEYS_DISPLAY_ORDER,
                                    'config_data': self.settingsservice.configurable_keys,
                                    common.KEY_FIRST_RUN: TvbProfile.is_first_run()})
     return self.fill_default_attributes(template_specification)
Esempio n. 3
0
 def settings(self, save_settings=False, **data):
     """Main settings page submit and get"""
     template_specification = dict(
         mainContent="../settings/system_settings", title="System Settings")
     if save_settings:
         try:
             form = SettingsForm()
             data = form.to_python(data)
             isrestart, isreset = self.settingsservice.save_settings(**data)
             if isrestart:
                 thread = threading.Thread(target=self._restart_services,
                                           kwargs={'should_reset': isreset})
                 thread.start()
                 common.add2session(common.KEY_IS_RESTART, True)
                 common.set_important_message(
                     'Please wait until TVB is restarted properly!')
                 raise cherrypy.HTTPRedirect('/tvb')
             # Here we will leave the same settings page to be displayed.
             # It will continue reloading when CherryPy restarts.
         except formencode.Invalid, excep:
             template_specification[
                 common.KEY_ERRORS] = excep.unpack_errors()
         except InvalidSettingsException, excep:
             self.logger.error(
                 'Invalid settings!  Exception %s was raised' %
                 (str(excep)))
             common.set_error_message(excep.message)
 def settings(self, save_settings=False, **data):
     """Main settings page submit and get"""
     template_specification = dict(mainContent="../settings/system_settings", title="System Settings")
     if save_settings:
         try:
             form = SettingsForm()
             data = form.to_python(data)
             isrestart, isreset = self.settingsservice.save_settings(**data)
             if isrestart:
                 thread = threading.Thread(target=self._restart_services, kwargs={'should_reset': isreset})
                 thread.start()
                 common.add2session(common.KEY_IS_RESTART, True)
                 common.set_important_message('Please wait until TVB is restarted properly!')
                 raise cherrypy.HTTPRedirect('/tvb')
             # Here we will leave the same settings page to be displayed.
             # It will continue reloading when CherryPy restarts.
         except formencode.Invalid as excep:
             template_specification[common.KEY_ERRORS] = excep.unpack_errors()
         except InvalidSettingsException as excep:
             self.logger.error('Invalid settings!  Exception %s was raised' % (str(excep)))
             common.set_error_message(excep.message)
     template_specification.update({'keys_order': self.settingsservice.KEYS_DISPLAY_ORDER,
                                    'config_data': self.settingsservice.configurable_keys,
                                    common.KEY_FIRST_RUN: TvbProfile.is_first_run()})
     return self.fill_default_attributes(template_specification)
    def execute_post(self, project_id, submit_url, step_key, algorithm, **data):
        """ Execute HTTP POST on a generic step."""
        errors = None
        adapter_instance = ABCAdapter.build_adapter(algorithm)

        try:
            result = self.flow_service.fire_operation(adapter_instance, common.get_logged_user(), project_id, **data)

            # Store input data in session, for informing user of it.
            step = self.flow_service.get_category_by_id(step_key)
            if not step.rawinput:
                self.context.add_adapter_to_session(None, None, copy.deepcopy(data))

            if isinstance(adapter_instance, ABCDisplayer):
                if isinstance(result, dict):
                    result[common.KEY_OPERATION_ID] = adapter_instance.operation_id
                    return result
                else:
                    common.set_error_message("Invalid result returned from Displayer! Dictionary is expected!")
            else:
                if isinstance(result, list):
                    result = "Launched %s operations." % len(result)
                common.set_important_message(str(result))
        except formencode.Invalid, excep:
            errors = excep.unpack_errors()
Esempio n. 6
0
    def execute_post(self, project_id, submit_url, step_key, algorithm,
                     **data):
        """ Execute HTTP POST on a generic step."""
        errors = None
        adapter_instance = ABCAdapter.build_adapter(algorithm)

        try:
            result = self.flow_service.fire_operation(adapter_instance,
                                                      common.get_logged_user(),
                                                      project_id, **data)

            # Store input data in session, for informing user of it.
            step = self.flow_service.get_category_by_id(step_key)
            if not step.rawinput:
                self.context.add_adapter_to_session(None, None,
                                                    copy.deepcopy(data))

            if isinstance(adapter_instance, ABCDisplayer):
                if isinstance(result, dict):
                    result[common.
                           KEY_OPERATION_ID] = adapter_instance.operation_id
                    return result
                else:
                    common.set_error_message(
                        "Invalid result returned from Displayer! Dictionary is expected!"
                    )
            else:
                if isinstance(result, list):
                    result = "Launched %s operations." % len(result)
                common.set_important_message(str(result))
        except formencode.Invalid, excep:
            errors = excep.unpack_errors()
Esempio n. 7
0
    def execute_post(self, project_id, submit_url, step_key, algorithm,
                     **data):
        """ Execute HTTP POST on a generic step."""
        errors = None
        adapter_instance = ABCAdapter.build_adapter(algorithm)

        try:
            form = adapter_instance.get_form()(project_id=project_id)
            form.fill_from_post(data)
            dt_dict = None
            if form.validate():
                dt_dict = form.get_dict()
            if dt_dict is None:
                raise formencode.Invalid(
                    "Could not build a dict out of this form!", {},
                    None,
                    error_dict=form.get_errors_dict())
            adapter_instance.submit_form(form)
            result = self.flow_service.fire_operation(adapter_instance,
                                                      common.get_logged_user(),
                                                      project_id, **dt_dict)

            # Store input data in session, for informing user of it.
            step = self.flow_service.get_category_by_id(step_key)
            if not step.rawinput:
                self.context.add_adapter_to_session(None, None,
                                                    copy.deepcopy(data))

            if isinstance(adapter_instance, ABCDisplayer):
                if isinstance(result, dict):
                    result[common.
                           KEY_OPERATION_ID] = adapter_instance.operation_id
                    return result
                else:
                    common.set_error_message(
                        "Invalid result returned from Displayer! Dictionary is expected!"
                    )
            else:
                if isinstance(result, list):
                    result = "Launched %s operations." % len(result)
                common.set_important_message(str(result))
        except formencode.Invalid as excep:
            errors = excep.unpack_errors()
            common.set_error_message("Invalid form inputs")
            self.logger.warning("Invalid form inputs %s" % errors)
        except OperationException as excep1:
            self.logger.exception("Error while executing a Launch procedure:" +
                                  excep1.message)
            common.set_error_message(excep1.message)

        previous_step = self.context.get_current_substep()
        should_reset = previous_step is None or data.get(
            common.KEY_ADAPTER) != previous_step
        template_specification = self.get_template_for_adapter(
            project_id, step_key, algorithm, submit_url, should_reset)
        if (errors is not None) and (template_specification is not None):
            template_specification[common.KEY_ERRORS] = errors
        template_specification[
            common.KEY_OPERATION_ID] = adapter_instance.operation_id
        return template_specification
Esempio n. 8
0
    def execute_post(self, project_id, submit_url, step_key, algorithm, **data):
        """ Execute HTTP POST on a generic step."""
        errors = None
        adapter_instance = ABCAdapter.build_adapter(algorithm)

        try:
            form = adapter_instance.get_form()(project_id=project_id)
            if 'fill_defaults' in data:
                form.fill_from_post_plus_defaults(data)
            else:
                form.fill_from_post(data)
            view_model = None
            if form.validate():
                try:
                    view_model = form.get_view_model()()
                    form.fill_trait(view_model)
                    self.context.add_view_model_to_session(view_model)
                except NotImplementedError:
                    self.logger.exception("Form and/or ViewModel not fully implemented for " + str(form))
                    raise InvalidFormValues("Invalid form inputs! Could not find a model for this form!",
                                            error_dict=form.get_errors_dict())
            else:
                raise InvalidFormValues("Invalid form inputs! Could not fill algorithm from the given inputs!",
                                        error_dict=form.get_errors_dict())

            adapter_instance.submit_form(form)

            if issubclass(type(adapter_instance), ABCDisplayer):
                adapter_instance.current_project_id = project_id
                adapter_instance.user_id = common.get_logged_user().id
                result = adapter_instance.launch(view_model)
                if isinstance(result, dict):
                    return result
                else:
                    common.set_error_message("Invalid result returned from Displayer! Dictionary is expected!")
                return {}

            result = self.operation_services.fire_operation(adapter_instance, common.get_logged_user(),
                                                            project_id, view_model=view_model)
            if isinstance(result, list):
                result = "Launched %s operations." % len(result)
            common.set_important_message(str(result))

        except formencode.Invalid as excep:
            errors = excep.unpack_errors()
            common.set_error_message("Invalid form inputs")
            self.logger.warning("Invalid form inputs %s" % errors)
        except (OperationException, LaunchException, TraitValueError) as excep1:
            self.logger.exception("Error while executing a Launch procedure:" + excep1.message)
            common.set_error_message(excep1.message)
        except InvalidFormValues as excep2:
            message, errors = excep2.display_full_errors()
            common.set_error_message(message)
            self.logger.warning("%s \n %s" % (message, errors))

        template_specification = self.get_template_for_adapter(project_id, step_key, algorithm, submit_url)
        if (errors is not None) and (template_specification is not None):
            template_specification[common.KEY_ERRORS] = errors
        return template_specification
 def create_stimulus(self):
     """
     Creates a stimulus from the given data.
     """
     current_stimulus_region = common.get_from_session(KEY_REGION_STIMULUS)
     region_stimulus_creator = ABCAdapter.build_adapter_from_class(RegionStimulusCreator)
     self.flow_service.fire_operation(region_stimulus_creator, common.get_logged_user(),
                                      common.get_current_project().id, view_model=current_stimulus_region)
     common.set_important_message("The operation for creating the stimulus was successfully launched.")
Esempio n. 10
0
 def create_local_connectivity(self, **kwargs):
     """
     Used for creating and storing a local connectivity.
     """
     current_lconn = common.get_from_session(KEY_LCONN)
     local_connectivity_creator = ABCAdapter.build_adapter_from_class(LocalConnectivityCreator)
     self.operation_service.fire_operation(local_connectivity_creator, common.get_logged_user(),
                                           common.get_current_project().id, view_model=current_lconn)
     common.set_important_message("The operation for creating the local connectivity was successfully launched.")
     return self.step_1()
 def create_stimulus(self):
     """
     Creates a stimulus from the given data.
     """
     context = common.get_from_session(KEY_REGION_CONTEXT)
     local_connectivity_creator = self.get_creator_and_interface(REGION_STIMULUS_CREATOR_MODULE,
                                                                 REGION_STIMULUS_CREATOR_CLASS, StimuliRegion())[0]
     context.equation_kwargs.update({'weight': json.dumps(context.get_weights())})
     self.flow_service.fire_operation(local_connectivity_creator, common.get_logged_user(),
                                      common.get_current_project().id, **context.equation_kwargs)
     common.set_important_message("The operation for creating the stimulus was successfully launched.")
 def create_local_connectivity(self, **kwargs):
     """
     Used for creating and storing a local connectivity.
     """
     context = common.get_from_session(KEY_LCONN_CONTEXT)
     local_connectivity_creator = self.get_creator_and_interface(LOCAL_CONN_CREATOR_MODULE,
                                                                 LOCAL_CONN_CREATOR_CLASS, LocalConnectivity())[0]
     self.flow_service.fire_operation(local_connectivity_creator, common.get_logged_user(),
                                      common.get_current_project().id, **kwargs)
     common.set_important_message("The operation for creating the local connectivity was successfully launched.")
     context.reset()
     return self.step_1()
Esempio n. 13
0
 def create_local_connectivity(self, **kwargs):
     """
     Used for creating and storing a local connectivity.
     """
     context = common.get_from_session(KEY_LCONN_CONTEXT)
     local_connectivity_creator = self.get_creator_and_interface(LOCAL_CONN_CREATOR_MODULE,
                                                                 LOCAL_CONN_CREATOR_CLASS, LocalConnectivity())[0]
     self.flow_service.fire_operation(local_connectivity_creator, common.get_logged_user(),
                                      common.get_current_project().id, **kwargs)
     common.set_important_message("The operation for creating the local connectivity was successfully launched.")
     context.reset()
     return self.step_1()
    def create_stimulus(self):
        """
        Creates a stimulus from the given data.
        """
        try:
            context = common.get_from_session(KEY_SURFACE_CONTEXT)
            surface_stimulus_creator = self.get_creator_and_interface(SURFACE_STIMULUS_CREATOR_MODULE,
                                                                      SURFACE_STIMULUS_CREATOR_CLASS,
                                                                      StimuliSurface())[0]
            self.flow_service.fire_operation(surface_stimulus_creator, common.get_logged_user(),
                                             common.get_current_project().id, **context.equation_kwargs)
            common.set_important_message("The operation for creating the stimulus was successfully launched.")
            context.selected_stimulus = None

        except (NameError, ValueError, SyntaxError), _:
            common.set_error_message("The operation failed due to invalid parameter input.")
            return False
Esempio n. 15
0
 def create_stimulus(self):
     """
     Creates a stimulus from the given data.
     """
     context = common.get_from_session(KEY_REGION_CONTEXT)
     local_connectivity_creator = self.get_creator_and_interface(
         REGION_STIMULUS_CREATOR_MODULE, REGION_STIMULUS_CREATOR_CLASS,
         StimuliRegion())[0]
     context.equation_kwargs.update(
         {'weight': json.dumps(context.get_weights())})
     self.flow_service.fire_operation(local_connectivity_creator,
                                      common.get_logged_user(),
                                      common.get_current_project().id,
                                      **context.equation_kwargs)
     common.set_important_message(
         "The operation for creating the stimulus was successfully launched."
     )
Esempio n. 16
0
    def create_stimulus(self):
        """
        Creates a stimulus from the given data.
        """
        try:
            context = common.get_from_session(KEY_SURFACE_CONTEXT)
            surface_stimulus_creator = self.get_creator_and_interface(SURFACE_STIMULUS_CREATOR_MODULE,
                                                                      SURFACE_STIMULUS_CREATOR_CLASS,
                                                                      StimuliSurface())[0]
            self.flow_service.fire_operation(surface_stimulus_creator, common.get_logged_user(),
                                             common.get_current_project().id, **context.equation_kwargs)
            common.set_important_message("The operation for creating the stimulus was successfully launched.")
            context.selected_stimulus = None

        except (NameError, ValueError, SyntaxError), _:
            common.set_error_message("The operation failed due to invalid parameter input.")
            return False
 def settings(self, save_settings=False, **data):
     """Main settings page submit and get"""
     template_specification = dict(mainContent="../settings/system_settings", title="System Settings")
     if save_settings:
         try:
             form = SettingsForm()
             data = form.to_python(data)
             isrestart, isreset = self.settingsservice.save_settings(**data)
             if isrestart:
                 thread = threading.Thread(target=self._restart_services, kwargs={'should_reset': isreset})
                 thread.start()
                 common.add2session(common.KEY_IS_RESTART, True)
                 common.set_important_message('Please wait until TVB is restarted properly!')
                 raise cherrypy.HTTPRedirect('/tvb')
             # Here we will leave the same settings page to be displayed.
             # It will continue reloading when CherryPy restarts.
         except formencode.Invalid, excep:
             template_specification[common.KEY_ERRORS] = excep.unpack_errors()
         except InvalidSettingsException, excep:
             self.logger.error('Invalid settings!  Exception %s was raised' % (str(excep)))
             common.set_error_message(excep.message)
    def execute_post(self, project_id, submit_url, step_key, algorithm, **data):
        """ Execute HTTP POST on a generic step."""
        errors = None
        adapter_instance = ABCAdapter.build_adapter(algorithm)

        try:
            result = self.flow_service.fire_operation(adapter_instance, common.get_logged_user(), project_id, **data)

            # Store input data in session, for informing user of it.
            step = self.flow_service.get_category_by_id(step_key)
            if not step.rawinput:
                self.context.add_adapter_to_session(None, None, copy.deepcopy(data))

            if isinstance(adapter_instance, ABCDisplayer):
                if isinstance(result, dict):
                    result[common.KEY_OPERATION_ID] = adapter_instance.operation_id
                    return result
                else:
                    common.set_error_message("Invalid result returned from Displayer! Dictionary is expected!")
            else:
                if isinstance(result, list):
                    result = "Launched %s operations." % len(result)
                common.set_important_message(str(result))
        except formencode.Invalid as excep:
            errors = excep.unpack_errors()
        except OperationException as excep1:
            self.logger.exception("Error while executing a Launch procedure:" + excep1.message)
            common.set_error_message(excep1.message)

        previous_step = self.context.get_current_substep()
        should_reset = previous_step is None or data.get(common.KEY_ADAPTER) != previous_step
        template_specification = self.get_template_for_adapter(project_id, step_key, algorithm,
                                                               submit_url, should_reset)
        if (errors is not None) and (template_specification is not None):
            template_specification[common.KEY_ERRORS] = errors
        template_specification[common.KEY_OPERATION_ID] = adapter_instance.operation_id
        return template_specification
Esempio n. 19
0
    def execute_post(self, project_id, submit_url, step_key, algorithm,
                     **data):
        """ Execute HTTP POST on a generic step."""
        errors = None
        adapter_instance = ABCAdapter.build_adapter(algorithm)

        try:
            form = adapter_instance.get_form()(project_id=project_id)
            form.fill_from_post(data)
            view_model = None
            if form.validate():
                try:
                    view_model = form.get_view_model()()
                    form.fill_trait(view_model)
                except NotImplementedError:
                    raise InvalidFormValues(
                        "Invalid form inputs! Could not find a model for this form!",
                        error_dict=form.get_errors_dict())
            else:
                raise InvalidFormValues(
                    "Invalid form inputs! Could not fill algorithm from the given inputs!",
                    error_dict=form.get_errors_dict())

            adapter_instance.submit_form(form)

            if issubclass(type(adapter_instance), ABCDisplayer):
                adapter_instance.current_project_id = project_id
                adapter_instance.user_id = common.get_logged_user().id
                result = adapter_instance.launch(view_model)
                if isinstance(result, dict):
                    return result
                else:
                    common.set_error_message(
                        "Invalid result returned from Displayer! Dictionary is expected!"
                    )
                return {}

            result = self.flow_service.fire_operation(adapter_instance,
                                                      common.get_logged_user(),
                                                      project_id,
                                                      view_model=view_model)
            # Store input data in session, for informing user of it.
            step = self.flow_service.get_category_by_id(step_key)
            if not step.rawinput:
                self.context.add_adapter_to_session(None, None,
                                                    copy.deepcopy(data))
            if isinstance(result, list):
                result = "Launched %s operations." % len(result)
            common.set_important_message(str(result))

        except formencode.Invalid as excep:
            errors = excep.unpack_errors()
            common.set_error_message("Invalid form inputs")
            self.logger.warning("Invalid form inputs %s" % errors)
        except OperationException as excep1:
            self.logger.exception("Error while executing a Launch procedure:" +
                                  excep1.message)
            common.set_error_message(excep1.message)
        except InvalidFormValues as excep2:
            message, errors = excep2.display_full_errors()
            common.set_error_message(message)
            self.logger.warning("%s \n %s" % (message, errors))

        previous_step = self.context.get_current_substep()
        should_reset = previous_step is None or data.get(
            common.KEY_ADAPTER) != previous_step
        template_specification = self.get_template_for_adapter(
            project_id, step_key, algorithm, submit_url, should_reset)
        if (errors is not None) and (template_specification is not None):
            template_specification[common.KEY_ERRORS] = errors
        template_specification[
            common.KEY_OPERATION_ID] = adapter_instance.operation_id
        return template_specification