当前位置: 首页>>代码示例>>Python>>正文


Python project_service.ProjectService类代码示例

本文整理汇总了Python中tvb.core.services.project_service.ProjectService的典型用法代码示例。如果您正苦于以下问题:Python ProjectService类的具体用法?Python ProjectService怎么用?Python ProjectService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ProjectService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self):
        micro_postfix = "_%d" % int(time.time() * 1000000)

        # Here create all structures needed later for data types creation
        self.files_helper = FilesHelper()

        # First create user 
        user = model.User("datatype_factory_user" + micro_postfix, "test_pass",
                          "[email protected]" + micro_postfix, True, "user")
        self.user = dao.store_entity(user)

        # Now create a project
        project_service = ProjectService()
        data = dict(name='DatatypesFactoryProject' + micro_postfix, description='test_desc', users=[])
        self.project = project_service.store_project(self.user, True, None, **data)

        # Create algorithm
        alg_category = model.AlgorithmCategory('one', True)
        dao.store_entity(alg_category)
        ad = model.Algorithm(SIMULATOR_MODULE, SIMULATOR_CLASS, alg_category.id)
        self.algorithm = dao.get_algorithm_by_module(SIMULATOR_MODULE, SIMULATOR_CLASS)
        if self.algorithm is None:
            self.algorithm = dao.store_entity(ad)

        # Create an operation
        self.meta = {DataTypeMetaData.KEY_SUBJECT: self.USER_FULL_NAME,
                     DataTypeMetaData.KEY_STATE: self.DATATYPE_STATE}
        operation = model.Operation(self.user.id, self.project.id, self.algorithm.id, 'test parameters',
                                    meta=json.dumps(self.meta), status=model.STATUS_FINISHED)
        self.operation = dao.store_entity(operation)
开发者ID:maedoc,项目名称:tvb-framework,代码行数:30,代码来源:datatypes_factory.py

示例2: __init__

    def __init__(self):
        micro_postfix = "_%d" % int(time.time() * 1000000)

        # Here create all structures needed later for data types creation
        self.files_helper = FilesHelper()

        # First create user 
        user = model.User("datatype_factory_user" + micro_postfix, "test_pass",
                          "[email protected]" + micro_postfix, True, "user")
        self.user = dao.store_entity(user)

        # Now create a project
        project_service = ProjectService()
        data = dict(name='DatatypesFactoryProject' + micro_postfix, description='test_desc', users=[])
        self.project = project_service.store_project(self.user, True, None, **data)

        # Create algorithm
        alg_category = model.AlgorithmCategory('one', True)
        dao.store_entity(alg_category)
        alg_group = model.AlgorithmGroup("test_module1", "classname1", alg_category.id)
        dao.store_entity(alg_group)
        algorithm = model.Algorithm(alg_group.id, 'id', name='', req_data='', param_name='', output='')
        self.algorithm = dao.store_entity(algorithm)

        #Create an operation
        self.meta = {DataTypeMetaData.KEY_SUBJECT: self.USER_FULL_NAME,
                     DataTypeMetaData.KEY_STATE: self.DATATYPE_STATE}
        operation = model.Operation(self.user.id, self.project.id, self.algorithm.id, 'test parameters',
                                    meta=json.dumps(self.meta), status=model.STATUS_FINISHED,
                                    method_name=ABCAdapter.LAUNCH_METHOD)
        self.operation = dao.store_entity(operation)
开发者ID:sdiazpier,项目名称:tvb-framework,代码行数:31,代码来源:datatypes_factory.py

示例3: stop_burst_operation

    def stop_burst_operation(self, operation_id, is_group, remove_after_stop=False):
        """
        For a given operation id that is part of a burst just stop the given burst.
        :returns True when stopped operation was successfully.
        """
        operation_id = int(operation_id)
        if int(is_group) == 0:
            operation = self.flow_service.load_operation(operation_id)
        else:
            op_group = ProjectService.get_operation_group_by_id(operation_id)
            first_op = ProjectService.get_operations_in_group(op_group)[0]
            operation = self.flow_service.load_operation(int(first_op.id))

        try:
            burst_service = BurstService()
            result = burst_service.stop_burst(operation.burst)
            if remove_after_stop:
                current_burst = common.get_from_session(common.KEY_BURST_CONFIG)
                if current_burst and current_burst.id == operation.burst.id:
                    common.remove_from_session(common.KEY_BURST_CONFIG)
                result = burst_service.cancel_or_remove_burst(operation.burst.id) or result

            return result
        except Exception, ex:
            self.logger.exception(ex)
            return False
开发者ID:transpersonify,项目名称:tvb-framework,代码行数:26,代码来源:flow_controller.py

示例4: run_export

def run_export(project_id, loose_irrelevant=False):

    s = ProjectService()
    mng = ExportManager()

    project = s.find_project(project_id)
    export_file = mng.export_project(project, loose_irrelevant)
    print("Check the exported file: %s" % export_file)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:8,代码来源:project_export.py

示例5: import_project_structure

    def import_project_structure(self, uploaded, user_id):
        """
        Execute import operations:
         
        1. check if ZIP or folder 
        2. find all project nodes
        3. for each project node:
            - create project
            - create all operations
            - import all images
            - create all dataTypes
        """

        self.user_id = user_id
        self.created_projects = []

        # Now we compute the name of the file where to store uploaded project
        now = datetime.now()
        date_str = "%d-%d-%d_%d-%d-%d_%d" % (now.year, now.month, now.day, now.hour,
                                             now.minute, now.second, now.microsecond)
        uq_name = "%s-ImportProject" % date_str
        uq_file_name = os.path.join(cfg.TVB_TEMP_FOLDER, uq_name + ".zip")

        temp_folder = None
        try:
            if isinstance(uploaded, FieldStorage) or isinstance(uploaded, Part):
                if uploaded.file:
                    file_obj = open(uq_file_name, 'wb')
                    file_obj.write(uploaded.file.read())
                    file_obj.close()
                else:
                    raise ProjectImportException("Please select the archive which contains the project structure.")
            else:
                shutil.copyfile(uploaded, uq_file_name)

            # Now compute the name of the folder where to explode uploaded ZIP file
            temp_folder = os.path.join(cfg.TVB_TEMP_FOLDER, uq_name)
            try:
                self.files_helper.unpack_zip(uq_file_name, temp_folder)
            except FileStructureException, excep:
                self.logger.exception(excep)
                raise ProjectImportException("Bad ZIP archive provided. A TVB exported project is expected!")

            try:
                self._import_project_from_folder(temp_folder)
            except Exception, excep:
                self.logger.exception(excep)
                self.logger.debug("Error encountered during import. Deleting projects created during this operation.")

                # Roll back projects created so far
                project_service = ProjectService()
                for project in self.created_projects:
                    project_service.remove_project(project.id)

                raise ProjectImportException(str(excep))
开发者ID:HuifangWang,项目名称:the-virtual-brain-website,代码行数:55,代码来源:import_service.py

示例6: reload_burst_operation

 def reload_burst_operation(self, operation_id, is_group, **_):
     """
     Find out from which burst was this operation launched. Set that burst as the selected one and 
     redirect to the burst page.
     """
     is_group = int(is_group)
     if not is_group:
         operation = self.flow_service.load_operation(int(operation_id))
     else:
         op_group = ProjectService.get_operation_group_by_id(operation_id)
         first_op = ProjectService.get_operations_in_group(op_group)[0]
         operation = self.flow_service.load_operation(int(first_op.id))
     operation.burst.prepare_after_load()
     common.add2session(common.KEY_BURST_CONFIG, operation.burst)
     raise cherrypy.HTTPRedirect("/burst/")
开发者ID:transpersonify,项目名称:tvb-framework,代码行数:15,代码来源:flow_controller.py

示例7: transactional_setup_method

 def transactional_setup_method(self):
     """
     Reset the database before each test.
     """
     self.project_service = ProjectService()
     self.structure_helper = FilesHelper()
     self.test_user = TestFactory.create_user()
开发者ID:maedoc,项目名称:tvb-framework,代码行数:7,代码来源:project_service_test.py

示例8: cancel_or_remove_burst

    def cancel_or_remove_burst(self, burst_id):
        """
        Cancel (if burst is still running) or Remove the burst given by burst_id.
        :returns True when Remove operation was done and False when Cancel
        """
        burst_entity = dao.get_burst_by_id(burst_id)
        if burst_entity.status == burst_entity.BURST_RUNNING:
            self.stop_burst(burst_entity)
            return False

        service = ProjectService()
        ## Remove each DataType in current burst.
        ## We can not leave all on cascade, because it won't work on SQLite for mapped dataTypes.
        datatypes = dao.get_all_datatypes_in_burst(burst_id)
        ## Get operations linked to current burst before removing the burst or else
        ##    the burst won't be there to identify operations any more.
        remaining_ops = dao.get_operations_in_burst(burst_id)

        # Remove burst first to delete work-flow steps which still hold foreign keys to operations.
        correct = dao.remove_entity(burst_entity.__class__, burst_id)
        if not correct:
            raise RemoveDataTypeException("Could not remove Burst entity!")

        for datatype in datatypes:
            service.remove_datatype(burst_entity.fk_project, datatype.gid, False)

        ## Remove all Operations remained.
        correct = True
        remaining_op_groups = set()
        project = dao.get_project_by_id(burst_entity.fk_project)

        for oper in remaining_ops:
            is_remaining = dao.get_generic_entity(oper.__class__, oper.id)
            if len(is_remaining) == 0:
                ### Operation removed cascaded.
                continue
            if oper.fk_operation_group is not None and oper.fk_operation_group not in remaining_op_groups:
                is_remaining = dao.get_generic_entity(model.OperationGroup, oper.fk_operation_group)
                if len(is_remaining) > 0:
                    remaining_op_groups.add(oper.fk_operation_group)
                    correct = correct and dao.remove_entity(model.OperationGroup, oper.fk_operation_group)
            correct = correct and dao.remove_entity(oper.__class__, oper.id)
            service.structure_helper.remove_operation_data(project.name, oper.id)

        if not correct:
            raise RemoveDataTypeException("Could not remove Burst because a linked operation could not be dropped!!")
        return True
开发者ID:lcosters,项目名称:tvb-framework,代码行数:47,代码来源:burst_service.py

示例9: prepare_group_launch

 def prepare_group_launch(self, group_gid, step_key, algorithm_id, **data):
     """
     Receives as input a group gid and an algorithm given by category and id, along
     with data that gives the name of the required input parameter for the algorithm.
     Having these generate a range of GID's for all the DataTypes in the group and
     launch a new operation group.
     """
     prj_service = ProjectService()
     dt_group = prj_service.get_datatypegroup_by_gid(group_gid)
     datatypes = prj_service.get_datatypes_from_datatype_group(dt_group.id)
     range_param_name = data.pop('range_param_name')
     data[RANGE_PARAMETER_1] = range_param_name
     data[range_param_name] = ','.join(dt.gid for dt in datatypes)
     OperationService().group_operation_launch(common.get_logged_user().id, common.get_current_project().id,
                                               int(algorithm_id), int(step_key), **data)
     redirect_url = self._compute_back_link('operations', common.get_current_project())
     raise cherrypy.HTTPRedirect(redirect_url)
开发者ID:transpersonify,项目名称:tvb-framework,代码行数:17,代码来源:flow_controller.py

示例10: setUp

 def setUp(self):
     """
     Reset the database before each test.
     """
     config.EVENTS_FOLDER = ''
     self.project_service = ProjectService()
     self.structure_helper = FilesHelper()
     self.test_user = TestFactory.create_user()
开发者ID:sdiazpier,项目名称:tvb-framework,代码行数:8,代码来源:project_service_test.py

示例11: stop_operation

 def stop_operation(self, operation_id, is_group, remove_after_stop=False):
     """
     Stop the operation given by operation_id. If is_group is true stop all the
     operations from that group.
     """
     operation_service = OperationService()
     result = False
     if int(is_group) == 0:
         result = operation_service.stop_operation(operation_id)
         if remove_after_stop:
             ProjectService().remove_operation(operation_id)
     else:
         op_group = ProjectService.get_operation_group_by_id(operation_id)
         operations_in_group = ProjectService.get_operations_in_group(op_group)
         for operation in operations_in_group:
             tmp_res = operation_service.stop_operation(operation.id)
             if remove_after_stop:
                 ProjectService().remove_operation(operation.id)
             result = result or tmp_res
     return result
开发者ID:transpersonify,项目名称:tvb-framework,代码行数:20,代码来源:flow_controller.py

示例12: ProjectController

class ProjectController(BaseController):
    """
    Displays pages which deals with Project data management.
    """

    PRROJECTS_FOR_LINK_KEY = "projectsforlink"
    PRROJECTS_LINKED_KEY = "projectslinked"
    KEY_OPERATION_FILTERS = "operationfilters"

    def __init__(self):
        super(ProjectController, self).__init__()
        self.project_service = ProjectService()


    @expose_page
    @settings
    def index(self):
        """
        Display project main-menu. Choose one project to work with.
        """
        current_project = common.get_current_project()
        if current_project is None:
            raise cherrypy.HTTPRedirect("/project/viewall")
        template_specification = dict(mainContent="project_submenu", title="TVB Project Menu")
        return self.fill_default_attributes(template_specification)


    @expose_page
    @settings
    def viewall(self, create=False, page=1, selected_project_id=None, **_):
        """
        Display all existent projects. Choose one project to work with.
        """
        page = int(page)
        if cherrypy.request.method == 'POST' and create:
            raise cherrypy.HTTPRedirect('/project/editone')
        current_user_id = common.get_logged_user().id

        ## Select project if user choose one.
        if selected_project_id is not None:
            try:
                selected_project = self.project_service.find_project(selected_project_id)
                self._mark_selected(selected_project)
            except ProjectServiceException, excep:
                self.logger.error(excep)
                self.logger.warning("Could not select project: " + str(selected_project_id))
                common.set_error_message("Could not select project: " + str(selected_project_id))

        #Prepare template response
        prjs, pages_no = self.project_service.retrieve_projects_for_user(current_user_id, page)
        template_specification = dict(mainContent="project/viewall", title="Available TVB Projects",
                                      projectsList=prjs, page_number=page, total_pages=pages_no)
        return self.fill_default_attributes(template_specification, 'list')
开发者ID:unimauro,项目名称:tvb-framework,代码行数:53,代码来源:project_controller.py

示例13: setUp

    def setUp(self):
        """
        Prepare before each test.
        """
        self.project_service = ProjectService()
        self.flow_service = FlowService()
        self.structure_helper = FilesHelper()

        self.test_user = TestFactory.create_user()
        self.test_project = TestFactory.create_project(self.test_user, "ProjectStructure")

        self.relevant_filter = StaticFiltersFactory.build_datatype_filters(single_filter=StaticFiltersFactory.RELEVANT_VIEW)
        self.full_filter = StaticFiltersFactory.build_datatype_filters(single_filter=StaticFiltersFactory.FULL_VIEW)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:13,代码来源:project_structure_test.py

示例14: EventHandlerTest

class EventHandlerTest(BaseTestCase):
    """
    This class contains tests for the tvb.core.services.event_handler module.
    """ 
       
    def setUp(self):
        """
        Reset the database before each test.
        """
        self.project_service = ProjectService()
        self.test_user = TestFactory.create_user()
        
        
    def tearDown(self):
        """
        Cleans the environment after testing (database and executors dictionary)
        """
        self.clean_database()
        event_handlers.EXECUTORS_DICT = {}
        
        
    def test_handle_event(self):
        """
        Test a defined handler for the store project method.
        """
        path_to_events = os.path.dirname(__file__)
        event_handlers.read_events([path_to_events])
        data = dict(name="test_project", description="test_description", users=[])
        initial_projects = dao.get_projects_for_user(self.test_user.id)
        self.assertEqual(len(initial_projects), 0, "Database reset probably failed!")
        test_project = self.project_service.store_project(self.test_user, True, None, **data)
        # Operations will start asynchronously; Give them time.
        time.sleep(1)
        gid = dao.get_last_data_with_uid("test_uid")
        self.assertTrue(gid is not None, "Nothing was stored in database!")
        datatype = dao.get_datatype_by_gid(gid)
        self.assertEqual(datatype.type, "Datatype1", "Wrong data stored!")
        self.project_service._remove_project_node_files(test_project.id, gid)
开发者ID:sdiazpier,项目名称:tvb-framework,代码行数:38,代码来源:event_handler_test.py

示例15: setUp

 def setUp(self):
     """
     Reset the database before each test.
     """
     self.import_service = ImportService()
     self.flow_service = FlowService()
     self.project_service = ProjectService()
     
     self.test_user = TestFactory.create_user()
     self.test_project = TestFactory.create_project(self.test_user, name="GeneratedProject", description="test_desc")
     self.operation = TestFactory.create_operation(test_user=self.test_user, test_project=self.test_project)
     self.adapter_instance = TestFactory.create_adapter(test_project=self.test_project)
     TestFactory.import_cff(test_user=self.test_user, test_project=self.test_project)
     self.zip_path = None 
开发者ID:amitsaroj001,项目名称:tvb-framework,代码行数:14,代码来源:import_service_test.py


注:本文中的tvb.core.services.project_service.ProjectService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。