From 6e845d250630104daa5a25bb6644b8b0779deb7b Mon Sep 17 00:00:00 2001 From: Stefan Krulj Date: Sun, 25 Mar 2012 13:41:43 +0200 Subject: [PATCH] Comments in the config section added, some encoding bugs fixed, now using mtime for the post dates --- pylog.py | 28 ++++++++--------- pylog_action_impl.py | 25 ++++++++-------- pylog_config.py | 25 ++++++++++------ style.css | 66 +++++++++++++++++++++++++++++++++++++---- mimetex.cgi => tex.cgi | Bin 5 files changed, 103 insertions(+), 41 deletions(-) rename mimetex.cgi => tex.cgi (100%) diff --git a/pylog.py b/pylog.py index 40fe60a..254b270 100755 --- a/pylog.py +++ b/pylog.py @@ -72,10 +72,10 @@ def disp_list(path): for f in os.listdir(path): f = os.path.normpath(os.path.join(path,f)) if not os.path.isdir(f): - if not os.path.getctime(f) in files: - files[os.path.getctime(f)]=[f] + if not os.path.getmtime(f) in files: + files[os.path.getmtime(f)]=[f] else: - files[os.path.getctime(f)].append(f) + files[os.path.getmtime(f)].append(f) keys = files.keys() keys.sort() keys.reverse() @@ -134,10 +134,10 @@ 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] + if not os.path.getmtime(f) in files: + files[os.path.getmtime(f)]=[f] else: - files[os.path.getctime(f)].append(f) + files[os.path.getmtime(f)].append(f) keys = files.keys() keys.sort() keys.reverse() @@ -146,7 +146,7 @@ def get_newest(n): def get_valid_path(path): if '..' in path or os.path.normpath(path)=='.': return cfg.contentdir - valid_chars='.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/_0123456789' + valid_chars='. abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/_0123456789' for c in path: if not c in valid_chars: return cfg.contentdir @@ -170,8 +170,8 @@ else: ' - print " "+cfg.blogtitle+"" - print " "+cfg.subtitle+"" + print (" "+cfg.blogtitle+"").encode(cfg.encoding) + print (" "+cfg.subtitle+"").encode(cfg.encoding) print " "+cfg.topurl+script+"" print " Pylog "+__version+"" if len(keys)>0: @@ -221,13 +221,13 @@ print '' print '' print '' print '' -print ''+cfg.title+'' +print (''+cfg.title+'').encode(cfg.encoding) print '' -print cfg.header +print cfg.header.encode(cfg.encoding) print '' print '' -print '

'+cfg.blogtitle+'

' -print '

'+cfg.subtitle+'

' +print ('

'+cfg.blogtitle+'

').encode(cfg.encoding) +print ('

'+cfg.subtitle+'

').encode(cfg.encoding) print '' @@ -249,7 +249,7 @@ try: sys.stdout.write('

') print name+' -

' diff --git a/pylog_action_impl.py b/pylog_action_impl.py index 103f864..8b62e90 100644 --- a/pylog_action_impl.py +++ b/pylog_action_impl.py @@ -1,5 +1,5 @@ import os, os.path, stat, sys -import urllib, hashlib +import urllib, hashlib, codecs from datetime import datetime import pylog_config as cfg import subprocess,tempfile @@ -37,8 +37,9 @@ def file_link(name,f,depth,hidden): def disp_txt(path): print '
' - f = open(path) - print markdown.markdown(f.read(),extensions=['math']) + f = codecs.open(path, mode="r", encoding=cfg.encoding) + txt=f.read() + print markdown.markdown(txt,extensions=['math']).encode(cfg.encoding) f.close() print '
' @@ -80,7 +81,7 @@ def get_source_html(path): s.st_mode & stat.S_IRWXG == 0 and \ s.st_mode & stat.S_IRWXO == 0 and \ os.path.isdir(tmpdir): - f=open(path,'r') + f=codecs.open(path, mode='r', encoding=cfg.encoding) tmpfile=os.path.join(tmpdir,hashlib.sha256(f.read()).hexdigest()) f.close() cache=True @@ -107,7 +108,7 @@ def get_source_html(path): p.stderr.close() p.wait() #wait for child to terminate - f=open(tmpfile,"r") + f=codecs.open(tmpfile, mode="r", encoding=cfg.encoding) bp=BodyParser() bp.feed(f.read()) src = bp.src @@ -119,14 +120,14 @@ def get_source_html(path): def disp_source(path): print '
' - print get_source_html(path) + print get_source_html(path).encode(cfg.encoding) #print source print '
' def disp(path): print '
' - f = open(path) - print f.read() + f = codecs.open(path, mode="r", encoding=cfg.encoding)(path) + print f.read().encode(cfg.encoding) f.close() print '
' @@ -149,18 +150,18 @@ def get_n_words(fi,n): return (txt,False) def prev(path): - fi = open(path) + fi = codecs.open(path, mode="r", encoding=cfg.encoding) txt=get_n_words(fi,40) - print '
'+txt[0] + print '
'+txt[0].encode(cfg.encoding) if txt[1]: print ' ...' print '
' fi.close() def prev_txt(path): - fi = open(path) + fi = codecs.open(path, mode="r", encoding=cfg.encoding) txt=get_n_words(fi,40) - print '
'+markdown.markdown(txt[0],extensions=['math']) + print '
'+markdown.markdown(txt[0],extensions=['math']).encode(cfg.encoding) if txt[1]: print ' ...' print '
' diff --git a/pylog_config.py b/pylog_config.py index 13f16e7..9169a3b 100644 --- a/pylog_config.py +++ b/pylog_config.py @@ -1,14 +1,21 @@ -title = 'Title of destruction' -blogtitle= 'Le Blog' -subtitle='Some subtitle... and cats!' +title = 'PyLog' # Title displayed on the browser window +blogtitle= 'Plog' # The blog's title +subtitle=u'produced py Powertomato \xb0\u0DF4\xb0' # The text to be displayed under the blog title header=""" -""" -datefmt='%Y-%m-%d' -contentdir="cnt" -numofposts=5 #number of previews on the base site -numfeed=5 #number of previews in the feed +""" # This header will be printed in the section of the html file -topurl="http://n0g.at/~powertomato/pylog/" +datefmt='%Y-%m-%d' # format of the date which is displayed next to the entry + # See pythons manual reference for time.strptime for details +contentdir="cnt" # directory where the content is located +numofposts=5 # number of previews on the base site +numfeed=5 # number of previews in the feed + +topurl="http://n0g.at/~powertomato/pylog/" # The URL which specifies the scripts location + # if someone knows how to obtain it using CGI + # please let me know +encoding="utf-8" # The content files should be encoded using this + # format. See manual reference for codecs.open for + # details diff --git a/style.css b/style.css index 6e8277b..4059310 100644 --- a/style.css +++ b/style.css @@ -2,15 +2,38 @@ .hidden { display: none } +li { + list-style-type:disc; +} a { color:#aa6735; text-decoration:underline; font-weight:bold; } -a:hover{ +a:hover { text-decoration:none; } +code { + font-size:10pt; + font-family:monospace; + background-color:#dddddd; + border:1px solid #aaaaaa; + padding-left:4px; + padding-right:4px; +} + +pre code{ + display:block; + margin-left: 20px; + font-size:10pt; + font-family:monospace; + background-color:#dddddd; + border:1px solid #aaaaaa; + padding-left:4px; + padding-right:4px; +} + /* header */ h1#blogtitle, h1#blogtitle a{ text-decoration:none; @@ -22,6 +45,10 @@ h1#blogtitle, h1#blogtitle a{ background-color:#dddddd; height:35px; background-image:url(_img/tbg.png); + border-width:0px; +} +h2#subtitle:before { + content:none; } h2#subtitle { font-size:10pt; @@ -41,7 +68,7 @@ h2#subtitle { width:15%; margin-left:1%; } -#menu ul,li{ +#menu ul, #menu li{ margin:0; padding:0; list-style-type:none; @@ -50,7 +77,6 @@ h2#subtitle { padding-left:15px; border-collapse:collapse; } - #menu ul, #menu ul ul ul{ } @@ -102,21 +128,49 @@ body { } h1 { font-size:14pt; - margin:15px 0 0 0; + padding:10px 0 0 0; font-weight:bold; color:#5598ca; + border-bottom:1px solid #5598ca; + counter-reset: kap; +} +h1 a { + text-decoration:none; +} +h2:before { + content: counter(kap) ' '; } h2 { font-size:12pt; - margin:20px 0 0 0; + padding:10px 0 0 10px; font-weight:bold; color:#5598ca; + + counter-increment: kap; + counter-reset: subkap; +} +h3:before { + content: counter(kap) '.' counter(subkap) ' '; } h3 { font-size:10pt; - margin:25px 0 0 0; + padding:10px 0 0 20px; font-weight:bold; color:#5598ca; + + counter-increment: subkap; + counter-reset: subsubkap; +} +h4:before { + content: counter(kap) '.' counter(subkap) '.' counter(subsubkap) ' '; +} +h4 { + font-size:9pt; + padding:10px 0 0 30px; + font-weight:bold; + color:#5598ca; + + counter-increment: subsubkap; } .entryheader { color:#5598ca; diff --git a/mimetex.cgi b/tex.cgi similarity index 100% rename from mimetex.cgi rename to tex.cgi