Skip to content

Instantly share code, notes, and snippets.

@jamesrobinsonvfx
Last active August 20, 2021 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesrobinsonvfx/27bbdd97777f7b80400b90d809066471 to your computer and use it in GitHub Desktop.
Save jamesrobinsonvfx/27bbdd97777f7b80400b90d809066471 to your computer and use it in GitHub Desktop.
Quick 'n' dirty script to include as part of a custom cache node, or a shelf tool to calculate cache times for frame sequences (Python 3)
import math
import os
import re
def timedelta(file1, file2):
t1 = os.path.getmtime(file1)
t2 = os.path.getmtime(file2)
time = abs(t2 - t1) / 60.0
min = math.floor(time)
sec = round((time - min) * 60.0)
return f"{min}m {sec}s"
def wedge_files(searchdir, prefix, wedgenum):
basename = f"{prefix}_{wedgenum}"
files = []
for file_ in os.listdir(searchdir):
if re.match(basename, file_):
files.append(os.path.join(searchdir, file_))
if len(files) < 2:
return
return files
def find_wedge_numbers(searchdir, prefix):
wedges = [re.match(rf"{prefix}(\d+)", x).group(1) for x in os.listdir(searchdir)]
wedges = list(set([x for x in wedges if x]))
return wedges
def report(cachedir, prefix):
report = ""
# Find all the different groups of files per match
for wnum in find_wedge_numbers(cachedir, prefix):
files = wedge_files(cachedir, "wedge", wnum)
if files:
report += f"Wedge {wnum}: {timedelta(files[0], files[-1])}\n"
return report
# r = report("C:/Users/James/Projects/dev/houdini/geo/cachedev/geo1/particles/001", "wedge")
# print(r)
@jamesrobinsonvfx
Copy link
Author

jamesrobinsonvfx commented Aug 20, 2021

Assuming a path convention of something like

/path/to/cache/dir/wedge_0.$F.bgeo.sc
/path/to/cache/dir/wedge_1.$F.bgeo.sc
/path/to/cache/dir/wedge_2.$F.bgeo.sc
...

where wedge_ is the {prefix}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment