diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2011-05-05 18:37:15 -0400 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2011-05-05 18:37:15 -0400 |
commit | 4e02abb7a303ad96fb406b61108e2261a81c81de (patch) | |
tree | 3fe45f258dbe44efe4761012719082fea8826f5d /CachePath.py | |
parent | Little bugs and status output. (diff) | |
download | PhotoFloat-4e02abb7a303ad96fb406b61108e2261a81c81de.tar.xz PhotoFloat-4e02abb7a303ad96fb406b61108e2261a81c81de.zip |
Fix caching errors.
Diffstat (limited to '')
-rw-r--r-- | CachePath.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/CachePath.py b/CachePath.py new file mode 100644 index 0000000..c9c19fc --- /dev/null +++ b/CachePath.py @@ -0,0 +1,30 @@ +import os.path +from datetime import datetime + +def set_cache_path_base(base): + trim_base.base = base +def untrim_base(path): + return os.path.join(trim_base.base, path) +def trim_base_custom(path, base): + if path.startswith(base): + path = path[len(base):] + if path.startswith('/'): + path = path[1:] + return path +def trim_base(path): + return trim_base_custom(path, trim_base.base) +def cache_base(path): + path = trim_base(path).replace('/', '-').replace(' ', '_') + if len(path) == 0: + path = "root" + return path +def json_cache(path): + return cache_base(path) + ".json" +def image_cache(path, size, square=False): + if square: + suffix = str(size) + "s" + else: + suffix = str(size) + return cache_base(path) + "_" + suffix + ".jpg" +def file_mtime(path): + return datetime.fromtimestamp(int(os.path.getmtime(path))) |