jacinle.io.fs#
Classes
Functions
|
Convert a file descriptor or a file name to a file descriptor. |
|
Dump a file with automatic file type detection. |
|
Dump a matlab file. |
|
Dump a npy numpy file. |
|
Dump a npz numpy file. |
|
Dump a pickle file. |
|
Dump a gziped pickle file. |
|
Dump a PyTorch file. |
|
A context manager to enable/disable verbose mode in file system operations. |
|
Create a symbolic link to a file or directory. |
|
Load a file with automatic file type detection. |
|
Load a HDF5 file. |
|
Load a matlab file. |
|
Load a npy numpy file. |
|
Load a npz numpy file. |
|
Load a pickle file. |
|
Load a gziped pickle file. |
|
Load a PyTorch file. |
|
Load a text file. |
|
Locate the newest file in a directory. |
|
List all files in a directory. |
|
Create a directory if it does not exist without raising errors when the directory already exists. |
|
Open a file. |
|
Open a gzip file. |
|
Open a HDF5 file. |
|
Open a text file. |
|
Remove a file or directory. |
|
Dump data to a file in a safe way. |
|
Enable/disable verbose mode in file system operations. |
|
A context manager that creates a temporary file and deletes it after use. |
Class LSDirectoryReturnType
- class LSDirectoryReturnType[source]#
Bases:
JacEnum
- __new__(value)#
- classmethod assert_valid(value)#
Assert if the value is a valid choice.
- classmethod choice_names()#
Returns the list of the name of all possible choices.
- classmethod choice_objs()#
Returns the list of the object of all possible choices.
- classmethod choice_values()#
Returns the list of the value of all possible choices.
- classmethod is_valid(value)#
Check if the value is a valid choice.
- classmethod type_name()#
Return the type name of the enum.
- BASE = 'base'#
- FULL = 'full'#
- NAME = 'name'#
- REAL = 'real'#
- REL = 'rel'#
Functions
- as_file_descriptor(fd_or_fname, mode='r')[source]#
Convert a file descriptor or a file name to a file descriptor.
- fs_verbose(mode=True)[source]#
A context manager to enable/disable verbose mode in file system operations.
- link(path_origin, *paths, use_relative_path=True)[source]#
Create a symbolic link to a file or directory.
- load(filename, **kwargs)[source]#
Load a file with automatic file type detection.
- Parameters:
filename (str)
- locate_newest_file(dirname, pattern)[source]#
Locate the newest file in a directory. If there is no file matching the pattern, return None.
- lsdir(dirname, pattern=None, return_type='full', sort=True)[source]#
List all files in a directory.
- Parameters:
dirname (str) – the directory name.
pattern (str | None) – the file name pattern in glob format.
return_type (str | LSDirectoryReturnType) – the return type. Can be one of the following: ‘base’: return the base name of the file. ‘name’: return the file name. ‘rel’: return the relative path of the file. ‘full’: return the full path of the file. ‘real’: return the real path of the file.
sort (bool) – whether to sort the file names.
- Returns:
a list of file names.
- Return type:
- mkdir(path)[source]#
Create a directory if it does not exist without raising errors when the directory already exists.
- safe_dump(filename, data, use_lock=True, use_temp=True, lock_timeout=10)[source]#
Dump data to a file in a safe way. Basically, it will dump the data to a temporary file and then move it to the target file. This is to avoid the case that the target file is corrupted when the program is interrupted during the dumping process. It also supports file locking to avoid the case that multiple processes are dumping data to the same file at the same time.
- Parameters:
filename (str) – the target file name.
data – the data to be dumped.
use_lock – whether to use file locking.
use_temp – whether to use a temporary file.
lock_timeout – the timeout for file locking.
- Returns:
If uses temp file, return True if the data is dumped to the temp file successfully, otherwise False. If not use temp file, return the result of the dump operation.
- Return type:
- set_fs_verbose(mode=True)[source]#
Enable/disable verbose mode in file system operations.
- Parameters:
mode (bool)