from piki_conf import * import os, time, stat, re def getpath(wikiword): return os.path.join(text_dir, wikiword) def getimagepath(wikiword, type): extension = re.search("image/([a-zA-Z]+)$", type).group(1) return os.path.join(image_dir, wikiword + "." + extension) def report_status(status_code, status_msg, body): return (status_code, """Content-type: text/plain \nStatus: %(status_code)d %(status_msg)s\n\n%(body)s """ % vars()) def currentISOTime(): "Current time in ISO format" import time tz = time.timezone/3600 return time.strftime("%Y-%m-%dT%H:%M:%S-", time.localtime()) + ("%(tz)02d:00" % vars()) def last_modified_iso(filename): """Time a file was last modified, in ISO format. Returns None if the file does not exist.""" if not path.exists(filename): return None modtime = time.localtime(os.stat(filename)[stat.ST_MTIME]) tz = time.timezone/3600 return time.strftime("%Y-%m-%dT%H:%M:%S-", modtime) + ("%(tz)02d:00" % vars())