def load_with_links_from_dir(base_dir, gid): # type: (str, typing.Union[uuid.UUID, str]) -> HasTraits dir_loader = DirLoader(base_dir, REGISTRY, False) fname = dir_loader.find_file_name(gid) fname = os.path.join(base_dir, fname) tvb_loader = TVBLoader(REGISTRY) return tvb_loader.load_with_links(fname)
def determine_filepath(gid, base_dir): """ Find the file path containing a datatype with the given GID within the directory specified by base_dir """ dir_loader = DirLoader(base_dir, REGISTRY, False) fname = dir_loader.find_file_by_gid(gid) return fname
def store_to_dir(datatype, base_dir, recursive=False): # type: (HasTraits, str, bool) -> None """ Stores the given datatype in the given directory. The name and location of the stored file(s) is chosen for you by this function. If recursive is true than datatypes referenced by this one are stored as well. """ loader = DirLoader(base_dir, REGISTRY, recursive) loader.store(datatype)
def load_with_references_from_dir(base_dir, gid): # type: (str, typing.Union[uuid.UUID, str]) -> HasTraits dir_loader = DirLoader(base_dir, REGISTRY, False) fname = dir_loader.find_file_by_gid(gid) tvb_loader = TVBLoader(REGISTRY) def load_ht_function(sub_gid, traited_attr): return dir_loader.load(sub_gid) return tvb_loader.load_complete_by_function(fname, load_ht_function)
def load_view_model(gid, base_dir): # type: (uuid.UUID, str) -> ViewModel """ Load a ViewModel object by reading the H5 file with the given GID, from the directory specified by base_dir. """ dir_loader = DirLoader(base_dir, REGISTRY, False) fname = dir_loader.find_file_name(gid) h5_path = os.path.join(base_dir, fname) return load_view_model_from_file(h5_path)
def load(source_path, with_references=False): # type: (str, bool) -> HasTraits """ Load a datatype stored in the tvb h5 file found at the given path """ if with_references: loader = DirLoader(os.path.dirname(source_path), REGISTRY, with_references) return loader.load(fname=os.path.basename(source_path)) else: loader = Loader(REGISTRY) return loader.load(source_path)
def load_from_dir(base_dir, gid, recursive=False): # type: (str, typing.Union[str, uuid.UUID], bool) -> HasTraits """ Loads a datatype with the requested gid from the given directory. The datatype should have been written with store_to_dir The name and location of the file is chosen for you. :param base_dir: The h5 storage directory :param gid: the gid of the to be loaded datatype :param recursive: if datatypes contained in this datatype should be loaded as well """ loader = DirLoader(base_dir, REGISTRY, recursive) return loader.load(gid)
def store(datatype, destination, recursive=False): # type: (HasTraits, str, bool) -> None """ Stores the given datatype in a tvb h5 file at the given path """ if recursive: loader = DirLoader(os.path.dirname(destination), REGISTRY, recursive) loader.store(datatype, os.path.basename(destination)) else: loader = Loader(REGISTRY) loader.store(datatype, destination)
def post(self, project_gid): """ :start a simulation using a project id and a zip archive with the simulator data serialized """ file = self.extract_file_from_request( request_file_key=RequestFileKey.SIMULATION_FILE_KEY.value, file_extension=FilesHelper.TVB_ZIP_FILE_EXTENSION) destination_folder = RestResource.get_destination_folder() zip_path = RestResource.save_temporary_file(file, destination_folder) try: project = self.project_service.find_project_lazy_by_gid( project_gid) except ProjectServiceException: raise InvalidIdentifierException(INVALID_PROJECT_GID_MESSAGE % project_gid) result = FilesHelper().unpack_zip(zip_path, os.path.dirname(zip_path)) if len(result) == 0: raise InvalidInputException("Empty zip archive") folder_path = os.path.dirname(result[0]) simulator_algorithm = FlowService().get_algorithm_by_module_and_class( SimulatorAdapter.__module__, SimulatorAdapter.__name__) try: simulator_h5_name = DirLoader( folder_path, None).find_file_for_has_traits_type(Simulator) simulator_file = os.path.join(folder_path, simulator_h5_name) except IOError: raise InvalidInputException( 'No Simulator h5 file found in the archive') try: current_user = get_current_user() operation = self.simulator_service.prepare_simulation_on_server( user_id=current_user.id, project=project, algorithm=simulator_algorithm, zip_folder_path=folder_path, simulator_file=simulator_file) except Exception as excep: self.logger.error(excep, exc_info=True) raise ServiceException(str(excep)) return operation.gid, HTTP_STATUS_CREATED
def determine_filepath(gid, base_dir): dir_loader = DirLoader(base_dir, REGISTRY, False) fname = dir_loader.find_file_name(gid) h5_path = os.path.join(base_dir, fname) return h5_path