reorganization, and output filename for SimpleWeb

This commit is contained in:
q
2015-12-20 12:31:29 +02:00
parent 810d485755
commit 9869257aaa
18 changed files with 16 additions and 15 deletions

View File

@@ -1,22 +1,23 @@
#!/usr/bin/python
# coding=utf-8
''' A script that creates index.html indexes for a folder.
''' A script that creates an index for a folder.
'''
import os,sys,time
import urllib
INDEXFILE='index.html'
def setup():
''' Setup the command line options '''
from argparse import ArgumentParser
parser=ArgumentParser()
parser.add_argument("-f",action="store_true",dest="overwrite",default=False,
help="Overwrite existing "+INDEXFILE)
help="Overwrite existing index file.")
parser.add_argument("-H",action="store_true",dest="hidden",default=False,
help="Show hidden files")
parser.add_argument("-t",type=str,dest="title",default=None,
help="Name for the title (Default: Folder name)")
parser.add_argument("-o",type=str,dest="filename",default="index.html",
help="Output filename (Default: index.html)")
parser.add_argument("-p",action="store_false",dest="parent",default=True,
help="Do no print .. link for parent folder.")
parser.add_argument("startpath",type=str,action="store",default=os.path.abspath('.'),nargs='?',
@@ -29,15 +30,15 @@ def setup():
def generate_index(opts):
for path,dirs,files in os.walk(opts.startpath):
if INDEXFILE in files:
if opts.filename in files:
if not opts.overwrite:
print(INDEXFILE+" exists")
print(opts.filename+" exists")
sys.exit(1)
files = [ f for f in files if f != INDEXFILE]
files = [ f for f in files if f != opts.filename]
if not opts.hidden:
files = [ f for f in files if not f.startswith(".")]
dirs = [ d for d in dirs if not d.startswith(".")]
f=open(os.path.join(path,INDEXFILE),'wt')
f=open(os.path.join(path,opts.filename),'wt')
dirs.sort()
files.sort()
f.write(get_header(opts.title))