#!/usr/bin/env python # pylint: disable=too-many-statements, line-too-long, W0703 import os import sys import subprocess import time from datetime import datetime startupinfo = None def filecheck(fname): if fname.startswith(('./.git', './.cache')): return None args = ['git', 'log', '-1', '--pretty="%ci"', fname] try: b = subprocess.check_output(args, startupinfo=startupinfo) data = b.decode()[:-1] x = datetime.strptime(data, '\"%Y-%m-%d %H:%M:%S %z\"') f = x.strftime('%d-%b-%Y %H:%M') except : return None return f def _get_date_size(filename): """return file date and size""" stat_result = os.stat(filename) date = filecheck(filename) print(date, filename) size = stat_result.st_size for unit in ['', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB']: if abs(size) < 1024.0: break size /= 1024.0 return date, '%d%s' % (int(size), unit) def index(): """generate index.html for current folder""" with open(os.path.splitext(os.path.abspath(__file__))[0]+'.html', 'rb') as file, open('meta.html', 'rb') as meta: meta = meta.read().decode('utf-8') autoindex_html = file.read().decode('utf-8') for root, dirs, files in os.walk(u'.', topdown=True, followlinks=True): html = u'