diff index_app.py @ 55:0fbe37b56e84

update index_app to use _indexroot files
author paulo
date Thu, 22 Aug 2013 23:53:56 -0700
parents 637a4470363b
children 259a484f691b
line diff
     1.1 --- a/index_app.py	Mon Jun 03 00:30:24 2013 -0700
     1.2 +++ b/index_app.py	Thu Aug 22 23:53:56 2013 -0700
     1.3 @@ -5,51 +5,46 @@
     1.4  import html
     1.5  
     1.6  
     1.7 -def _get_cwd(environ):
     1.8 -	ROOTPATH = "pauloang.com"
     1.9 -	path_info = environ.get("PATH_INFO", '')
    1.10 -	return [ROOTPATH] + [i for i in path_info.split('/') if len(i) > 0]
    1.11 -
    1.12 -
    1.13 -def _get_breadcrumb(cwd):
    1.14 -	h = html.HTML()
    1.15 -	for (i, d) in enumerate(cwd[:-1]):
    1.16 -		h.a(d, href='/' + '/'.join(cwd[1:i+1]))
    1.17 -		h.text('/')
    1.18 -	h.text(cwd[-1])
    1.19 -	return h
    1.20 +def read_indexroot(indexroot_fn):
    1.21 +	ret = ''
    1.22 +	with open(indexroot_fn) as f:
    1.23 +		try:
    1.24 +			ret = f.next().strip()
    1.25 +		except StopIteration:
    1.26 +			pass
    1.27 +	return ret
    1.28  
    1.29  
    1.30  def main(environ):
    1.31 -	cwd = _get_cwd(environ)
    1.32  	dirs = []
    1.33  	
    1.34  	for i in os.listdir("."):
    1.35 -		if i[0] != '.' and os.path.isdir(i):
    1.36 +		indexroot_fn = os.path.join(i, "_indexroot")
    1.37 +		if i[0] != '.' and os.path.isdir(i) and os.path.exists(indexroot_fn):
    1.38  			statobj = os.stat(i)
    1.39 -			mtime = datetime.datetime.fromtimestamp(statobj.st_mtime)
    1.40 -			modeok = (statobj.st_mode & stat.S_IXOTH) and (statobj.st_mode & stat.S_IROTH)
    1.41 -			dirs.append((i, modeok, mtime))
    1.42 +			if not (statobj.st_mode & stat.S_IXOTH) and (statobj.st_mode & stat.S_IROTH):
    1.43 +				continue
    1.44 +			indexroot_statobj = os.stat(indexroot_fn)
    1.45 +			mtime = datetime.datetime.fromtimestamp(indexroot_statobj.st_mtime)
    1.46 +			indexroot = read_indexroot(indexroot_fn)
    1.47 +			dirs.append((i, mtime, indexroot))
    1.48  	
    1.49  	root = html.HTML("html")
    1.50 -	TITLE_FMT = "-[%s]-" 
    1.51 -	title = TITLE_FMT % '/'.join(cwd)
    1.52 +	title = "-[pauloang.com]-"
    1.53  	
    1.54  	header = root.header
    1.55  	header.title(title)
    1.56  	header.link(rel="stylesheet", type="text/css", href="index.css")
    1.57  	
    1.58 -	body = root.body
    1.59 -	body.h1(TITLE_FMT % str(_get_breadcrumb(cwd)), escape=False)
    1.60 +	body = root.body(klass="body")
    1.61 +	body.h1(title, escape=False)
    1.62  	
    1.63 -	body_table = body.table(klass="index")
    1.64 +	for (i, mtime, indexroot) in sorted(dirs, key=lambda x: x[1], reverse=True):
    1.65 +		body.a(i, href=os.path.join(i, indexroot))
    1.66 +		body.br
    1.67  	
    1.68 -	for (i, modeok, mtime) in sorted(dirs, key=lambda x: x[2], reverse=True):
    1.69 -		if modeok:
    1.70 -			r = body_table.tr
    1.71 -			r.td.div(mtime.isoformat(), klass="index_date")
    1.72 -			r.td.a(i, href=i)
    1.73 -	
    1.74 +	body.div(klass="email").p.a("pbba13@gmail.com", href="mailto:pbba13@gmail.com")
    1.75 +
    1.76  	return unicode(root).encode("utf-8")
    1.77  
    1.78