Last active
August 20, 2021 20:52
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assuming a path convention of something like
where
wedge_
is the{prefix}