def _import_projects_from_folder(self, temp_folder): """ Process each project from the uploaded pack, to extract names. """ project_roots = [] for root, _, files in os.walk(temp_folder): if FilesHelper.TVB_PROJECT_FILE in files: project_roots.append(root) for temp_project_path in project_roots: update_manager = ProjectUpdateManager(temp_project_path) update_manager.run_all_updates() project = self.__populate_project(temp_project_path) # Populate the internal list of create projects so far, for cleaning up folders, in case of failure self.created_projects.append(project) # Ensure project final folder exists on disk project_path = self.files_helper.get_project_folder(project) shutil.move( os.path.join(temp_project_path, FilesHelper.TVB_PROJECT_FILE), project_path) # Now import project operations with their results self.import_project_operations(project, temp_project_path) # Import images and move them from temp into target self._store_imported_images(project, temp_project_path, project.name)
def update(): """ Move images previously stored in TVB operation folders, in a single folder/project. """ projects_count = dao.get_all_projects(is_count=True) for page_start in range(0, projects_count, PAGE_SIZE): projects_page = dao.get_all_projects(page_start=page_start, page_size=PAGE_SIZE) for project in projects_page: figures = _figures_in_project(project.id) for figure in figures: figure.file_path = "%s-%s" % (figure.operation.id, figure.file_path) dao.store_entities(figures) project_path = FilesHelper().get_project_folder(project) update_manager = ProjectUpdateManager(project_path) update_manager.run_all_updates() project.version = TvbProfile.current.version.PROJECT_VERSION dao.store_entity(project)
def _import_projects_from_folder(self, temp_folder): """ Process each project from the uploaded pack, to extract names. """ project_roots = [] for root, _, files in os.walk(temp_folder): if FilesHelper.TVB_PROJECT_FILE in files: project_roots.append(root) for project_path in project_roots: update_manager = ProjectUpdateManager(project_path) update_manager.run_all_updates() project_entity = self.__populate_project(project_path) # Compute the path where to store files of the imported project new_project_path = os.path.join(TvbProfile.current.TVB_STORAGE, FilesHelper.PROJECTS_FOLDER, project_entity.name) if project_path != new_project_path: shutil.move(project_path, new_project_path) self.created_projects.append(project_entity) # Keep a list with all burst that were imported since we will want to also add the workflow # steps after we are finished with importing the operations and datatypes. We need to first # stored bursts since we need to know which new id's they have for operations parent_burst. # bursts_dict, dt_mappings_dict = self._load_burst_info_from_json(new_project_path) # burst_ids_mapping = self._import_bursts(project_entity, bursts_dict) # Now import project operations self.import_project_operations(project_entity, new_project_path) # Import images self._store_imported_images(project_entity)
def _import_projects_from_folder(self, temp_folder): """ Process each project from the uploaded pack, to extract names. """ project_roots = [] for root, _, files in os.walk(temp_folder): if FilesHelper.TVB_PROJECT_FILE in files: project_roots.append(root) for project_path in project_roots: update_manager = ProjectUpdateManager(project_path) update_manager.run_all_updates() project_entity = self.__populate_project(project_path) # Compute the path where to store files of the imported project new_project_path = os.path.join(TvbProfile.current.TVB_STORAGE, FilesHelper.PROJECTS_FOLDER, project_entity.name) if project_path != new_project_path: shutil.move(project_path, new_project_path) self.created_projects.append(project_entity) # Keep a list with all burst that were imported since we will want to also add the workflow # steps after we are finished with importing the operations and datatypes. We need to first # stored bursts since we need to know which new id's they have for operations parent_burst. bursts_dict, dt_mappings_dict = self._load_burst_info_from_json(new_project_path) burst_ids_mapping = self._import_bursts(project_entity, bursts_dict) # Now import project operations self.import_project_operations(project_entity, new_project_path, dt_mappings_dict, burst_ids_mapping) # Import images self._store_imported_images(project_entity) # Now we can finally import workflow related entities self.import_workflows(project_entity, bursts_dict, burst_ids_mapping)
def update(): """ Move images previously stored in TVB operation folders, in a single folder/project. """ projects_count = dao.get_all_projects(is_count=True) for page_start in range(0, projects_count, PAGE_SIZE): projects_page = dao.get_all_projects(page_start=page_start, page_end=min(page_start + PAGE_SIZE, projects_count)) for project in projects_page: figures = _figures_in_project(project.id) for figure in figures: figure.file_path = "%s-%s" % (figure.operation.id, figure.file_path) dao.store_entities(figures) project_path = FilesHelper().get_project_folder(project) update_manager = ProjectUpdateManager(project_path) update_manager.run_all_updates() project.version = TvbProfile.current.version.PROJECT_VERSION dao.store_entity(project)
def update(): """ Cleanup Projections from disk (make sure Projection Regions are being removed). """ projects_count = dao.get_all_projects(is_count=True) for page_start in range(0, projects_count, PAGE_SIZE): projects_page = dao.get_all_projects(page_start=page_start, page_size=PAGE_SIZE) for project in projects_page: project_path = FilesHelper().get_project_folder(project) update_manager = ProjectUpdateManager(project_path) update_manager.run_all_updates() project.version = TvbProfile.current.version.PROJECT_VERSION dao.store_entity(project)
def _import_project_from_folder(self, temp_folder): """ Process each project from the uploaded pack, to extract names. """ temp_project_path = None for root, _, files in os.walk(temp_folder): if StorageInterface.TVB_PROJECT_FILE in files: temp_project_path = root break if temp_project_path is not None: update_manager = ProjectUpdateManager(temp_project_path) if update_manager.checked_version < 3: raise ImportException( 'Importing projects with versions older than 3 is not supported in TVB 2! ' 'Please import the project in TVB 1.5.8 and then launch the current version of ' 'TVB in order to upgrade this project!') update_manager.run_all_updates() project = self.__populate_project(temp_project_path) # Populate the internal list of create projects so far, for cleaning up folders, in case of failure self.created_projects.append(project) # Ensure project final folder exists on disk project_path = self.storage_interface.get_project_folder( project.name) shutil.move( os.path.join(temp_project_path, StorageInterface.TVB_PROJECT_FILE), project_path) # Now import project operations with their results self.import_list_of_operations(project, temp_project_path) # Import images and move them from temp into target self._store_imported_images(project, temp_project_path, project.name) if StorageInterface.encryption_enabled(): self.storage_interface.remove_project(project, True)