def bracket_link(link): m = re.search(r"^/(thread)/([^/]+)/([0-9a-f]{8})$", link) if m is not None: title = md5digest(file_encode(m.group(1), m.group(2))) id = m.group(3) uri = '/%s/%s.html' % (title, id) return '<a href="' + uri + '">[[' + link + ']]</a>' m = re.search(r"^/(thread)/([^/]+)$", link) if m is not None: title = md5digest(file_encode(m.group(1), m.group(2))) uri = '/%s/' % title return '<a href="' + uri + '">[[' + link + ']]</a>' m = re.search(r"^([^/]+)/([0-9a-f]{8})$", link) if m is not None: title = md5digest(file_encode('thread', m.group(1))) id = m.group(2) uri = '/%s/%s.html' % (title, id) return '<a href="' + uri + '">[[' + link + ']]</a>' m = re.search(r"^([^/]+)$", link) if m is not None: title = md5digest(file_encode('thread', m.group(1))) uri = '/%s/' % title return '<a href="' + uri + '">[[' + link + ']]</a>' return "[[" + link + "]]"
def copy_attach(cache): title = md5digest(cache.datfile) srcdir = os.path.join(shingetsu.config.cache_dir, cache.datfile) srcdir = os.path.join(srcdir, 'attach') dstdir = os.path.join(archive_dir, title) if not os.path.isdir(dstdir): os.makedirs(dstdir) for f in os.listdir(srcdir): m = re.search(r'([0-9]+)_([0-9a-f]{32})\.(.*)', f) stamp, id, suffix = m.groups() stamp = int(stamp) srcfile = os.path.join(srcdir, f) dstfile = os.path.join(dstdir, '%sx.%s' % (id[:8], suffix)) if not os.path.exists(dstfile): copy(srcfile, dstfile) os.utime(dstfile, (stamp, stamp))
def make_html(cache): title = md5digest(cache.datfile) dstdir = os.path.join(archive_dir, title) if not os.path.isdir(dstdir): os.makedirs(dstdir) count = 0 for rec in cache: sid = rec.id[:8] dstfile = '%s/%s/%s.html' % (archive_dir, title, sid) if not os.path.exists(dstfile): rec.load_body() f = opentext(dstfile, 'w') write_html(f, rec) f.close() os.utime(dstfile, (rec.stamp, rec.stamp)) rec.free() count += 1 return count