From 8d66a56b9169f0ad8fe67e68a030e7c121bdb88f Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 5 May 2011 20:03:47 -0400 Subject: Add stump of web project. --- scanner/CachePath.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 scanner/CachePath.py (limited to 'scanner/CachePath.py') diff --git a/scanner/CachePath.py b/scanner/CachePath.py new file mode 100644 index 0000000..c9c19fc --- /dev/null +++ b/scanner/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))) -- cgit v1.2.3-59-g8ed1b