snek5000.util.files#
Functions
|
Bisect Nek5000 field files by the simulation time metadata. |
|
Creates a session and write the path to a SESSION.NAME file. |
|
Generate a new path with an integer suffix |
Classes
|
A small data stucture to assist bisection sort by simulation time, |
- snek5000.util.files.next_path(old_path, force_suffix=False, return_suffix=False)[source]#
Generate a new path with an integer suffix
- Parameters
old_path (str or path-like) – Path to check for existence
force_suffix – If true, will not check if the old_path can be used and adds a suffix in the end.
return_suffix – If true, returns the integer suffix along with the path/
- Returns
(i, new_path) (tuple[int, Path]) – If return_suffix is True.
new_path (Path) – A path (with an integer suffix) which does not yet exist in the filesystem.
Examples
>>> import os >>> os.chdir("/tmp")
>>> next_path("test.txt") # path does not exist PosixPath('test.txt')
>>> next_path("test.txt", force_suffix=True) # path does not exists PosixPath('test_00.txt')
>>> Path("test.txt").touch() >>> next_path("test.txt") # path exists PosixPath('test_00.txt')
>>> Path("test_00.txt").touch() >>> next_path("test.txt") # path and the next one both exists PosixPath('test_01.txt')
>>> Path("test.txt").unlink() # cleanup >>> Path("test_00.txt").unlink()
- snek5000.util.files.create_session(case, re2, ma2, par)[source]#
Creates a session and write the path to a SESSION.NAME file. Then, symlinks re2 and ma2 files, and copies the par file.
- class snek5000.util.files.LazyNekFile(path)[source]#
A small data stucture to assist bisection sort by simulation time,
bisect_nek_files_by_time()
- property time#
- snek5000.util.files.bisect_nek_files_by_time(files, time)[source]#
Bisect Nek5000 field files by the simulation time metadata. The bisection search is done using
bisect.bisect_left()
- Parameters
files (iterable of str or path-like) – List of file names / paths.
time (float) – Approximate simulation time. Finds
file
such thatread_header(file).time
<time
.
- Returns
file – Path to field file.
- Return type
str or path-like