|
|
|
|
@ -14,12 +14,12 @@ import pylog_config as cfg |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print 'Content-type: text/html\n\n' |
|
|
|
|
|
|
|
|
|
def header(): |
|
|
|
|
script = sys.argv[0][sys.argv[0].rindex('/')+1:] |
|
|
|
|
print '<head>' |
|
|
|
|
print '<title>'+cfg.title+'</title>' |
|
|
|
|
print '<h1 id="blogtitle">'+cfg.blogtitle+'</h1>' |
|
|
|
|
print '<h1 id="blogtitle"><a href="'+script+'">'+cfg.blogtitle+'</a></h1>' |
|
|
|
|
print '<h2 id="subtitle">'+cfg.subtitle+'</h2>' |
|
|
|
|
print cfg.header |
|
|
|
|
print '</head>' |
|
|
|
|
@ -73,33 +73,85 @@ def process_dirs(path='.',disppath='.',depth=0,hidden=False): |
|
|
|
|
dir_end(disppath,hidden) |
|
|
|
|
|
|
|
|
|
def disp_list(path): |
|
|
|
|
script = sys.argv[0][sys.argv[0].rindex('/')+1:] |
|
|
|
|
if path==cfg.contentdir: |
|
|
|
|
files,keys=get_newest(cfg.numofposts) |
|
|
|
|
disp_file_dict(files,keys) |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
files = {} |
|
|
|
|
for f in os.listdir(path): |
|
|
|
|
f = os.path.normpath(os.path.join(path,f)) |
|
|
|
|
if not os.path.isdir(f): |
|
|
|
|
files[os.path.getctime(f)]=f |
|
|
|
|
if not os.path.getctime(f) in files: |
|
|
|
|
files[os.path.getctime(f)]=[f] |
|
|
|
|
else: |
|
|
|
|
files[os.path.getctime(f)].append(f) |
|
|
|
|
keys = files.keys() |
|
|
|
|
keys.sort() |
|
|
|
|
keys.reverse() |
|
|
|
|
disp_file_dict(files,keys) |
|
|
|
|
|
|
|
|
|
def disp_file_dict(d,keys): |
|
|
|
|
|
|
|
|
|
script = sys.argv[0][sys.argv[0].rindex('/')+1:] |
|
|
|
|
for k in keys: |
|
|
|
|
f=files[k] |
|
|
|
|
if '.' in os.path.basename(f): |
|
|
|
|
typ = f[f.rindex('.')+1:] |
|
|
|
|
name = os.path.basename(f)[:-(len(typ)+1)] |
|
|
|
|
for f in d[k]: |
|
|
|
|
if '.' in os.path.basename(f): |
|
|
|
|
typ = f[f.rindex('.')+1:] |
|
|
|
|
name = os.path.basename(f)[:-(len(typ)+1)] |
|
|
|
|
else: |
|
|
|
|
typ = '' |
|
|
|
|
name = os.path.basename(f) |
|
|
|
|
if typ in prev_actions and not os.path.isdir(f): |
|
|
|
|
sys.stdout.write('<h1><a class="entryheader" href="'+script+'?') |
|
|
|
|
sys.stdout.write(urllib.urlencode({'path': os.path.normpath(os.path.dirname(f)), \ |
|
|
|
|
'disp':os.path.normpath(f)})+'">') |
|
|
|
|
print name+'</a> - <span class="entrydate">', |
|
|
|
|
print datetime.fromtimestamp(int(k)).strftime(cfg.datefmt), |
|
|
|
|
print '</span></h1>' |
|
|
|
|
prev_actions[typ](f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_all(path=cfg.contentdir): |
|
|
|
|
dicts = [] |
|
|
|
|
files = [] |
|
|
|
|
for f in os.listdir(path): |
|
|
|
|
f = os.path.normpath(os.path.join(path,f)) |
|
|
|
|
if not os.path.isdir(f): |
|
|
|
|
if '.' in os.path.basename(f): |
|
|
|
|
typ = f[f.rindex('.')+1:] |
|
|
|
|
name = os.path.basename(f)[:-(len(typ)+1)] |
|
|
|
|
else: |
|
|
|
|
typ = '' |
|
|
|
|
name = os.path.basename(f) |
|
|
|
|
if typ in prev_actions: |
|
|
|
|
files.append(f) |
|
|
|
|
else: |
|
|
|
|
typ = '' |
|
|
|
|
name = os.path.basename(f) |
|
|
|
|
if typ in prev_actions and not os.path.isdir(f): |
|
|
|
|
sys.stdout.write('<h1><a class="entryheader" href="'+script+'?') |
|
|
|
|
sys.stdout.write(urllib.urlencode({'path': os.path.normpath(os.path.dirname(f)), \ |
|
|
|
|
'disp':os.path.normpath(f)})+'">') |
|
|
|
|
print name+'</a> - <span class="entrydate">', |
|
|
|
|
print datetime.fromtimestamp(int(k)).strftime(cfg.datefmt), |
|
|
|
|
print '</span></h1>' |
|
|
|
|
prev_actions[typ](f) |
|
|
|
|
|
|
|
|
|
if '_' in os.path.basename(f): |
|
|
|
|
typ = f[f.rindex('_')+1:] |
|
|
|
|
name = os.path.basename(f)[:-(len(typ)+1)] |
|
|
|
|
else: |
|
|
|
|
typ = '' |
|
|
|
|
name = os.path.basename(f) |
|
|
|
|
if typ in dir_actions: |
|
|
|
|
dicts.append(f) |
|
|
|
|
|
|
|
|
|
for d in dicts: |
|
|
|
|
files+=get_all(d) |
|
|
|
|
return files |
|
|
|
|
|
|
|
|
|
def get_newest(n): |
|
|
|
|
allfiles=get_all() |
|
|
|
|
files = {} |
|
|
|
|
for f in allfiles: |
|
|
|
|
if not os.path.getctime(f) in files: |
|
|
|
|
files[os.path.getctime(f)]=[f] |
|
|
|
|
else: |
|
|
|
|
files[os.path.getctime(f)].append(f) |
|
|
|
|
keys = files.keys() |
|
|
|
|
keys.sort() |
|
|
|
|
keys.reverse() |
|
|
|
|
return files,keys[0:n] |
|
|
|
|
|
|
|
|
|
def get_valid_path(path): |
|
|
|
|
if '..' in path or os.path.normpath(path)=='.': |
|
|
|
|
@ -110,13 +162,16 @@ def get_valid_path(path): |
|
|
|
|
return cfg.contentdir |
|
|
|
|
return os.path.normpath(path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print 'Content-type: text/html\n\n' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
path = cfg.contentdir |
|
|
|
|
if 'path' in form: |
|
|
|
|
path=form['path'].value |
|
|
|
|
|
|
|
|
|
path=get_valid_path(path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print '<html>' |
|
|
|
|
header() |
|
|
|
|
print '<body>' |
|
|
|
|
|