#!/usr/bin/env python3 # github_create_html.py # -John Taylor # Sept-11-2015 # Create an HTML file containing a table with filenames and descriptions # Example: github_create_html.py > gh-manifest.html import sys,configparser,os.path,datetime fname_ini = "gh-__REPO__.ini" ########################################################################## def header(repo_name=""): print("") print("Manifest") print("") print("

%s - Manifest

" %(repo_name)) print("

") print() print("") print("") print("") print("") print("") print() ########################################################################## def footer(fcount): print("
FileSizeDateDescription
") print("

") print("file count: %s" % (fcount)) print("

") print("") print("") print() ########################################################################## def url(fname): return "%s" % (fname,fname) ########################################################################## def table_add(fname, desc, bg=False): if not len(desc): desc=" " tmp = os.path.getsize(fname) sz = format(tmp, ',d') mtime = os.path.getmtime(fname) tmp = "%s" % (datetime.datetime.fromtimestamp(mtime)) last_modified_date = tmp[:19] desc = desc.replace("&","&").replace('"',""").replace("<","<").replace(">",">") if bg: print("") else: print("") print("%s" % (url(fname))) print("%s" % (sz)) print("%s" % (last_modified_date)) print("%s" % (desc)) print("") print() ########################################################################## def main(): global fname_ini if len(sys.argv) == 1: tmp1 = os.path.dirname(os.path.realpath(__file__)) repo_name = tmp1.split(os.sep)[-1:][0] fname_ini = fname_ini.replace("__REPO__",repo_name) elif len(sys.argv) == 2: repo_name = sys.argv[1] fname_ini = fname_ini.replace("__REPO__",repo_name) else: print(); print("Usage: %s [ repo ]" % (sys.argv[0])); print() return 1 #print(); print("ini file: %s" % (fname_ini)); print() config = configparser.ConfigParser() if os.path.exists(fname_ini): config.read(fname_ini) header(repo_name) count = 0 for section in sorted(config.sections(), key=lambda s:s.lower()): if "desc" not in config[section]: continue bg = True if (count%2) else False table_add(section,config[section]["desc"], bg) count += 1 footer(count) return 0 ########################################################################## if "__main__" == __name__: sys.exit( main() )