commit 2ac5bce8a96277f11a9c56551d2428a1e0480243 Author: Stefan Krulj Date: Sun Mar 11 08:23:10 2012 +0100 Initial commit diff --git a/_img/back.png b/_img/back.png new file mode 100644 index 0000000..0f90a40 Binary files /dev/null and b/_img/back.png differ diff --git a/pylog.py b/pylog.py new file mode 100755 index 0000000..5b0f153 --- /dev/null +++ b/pylog.py @@ -0,0 +1,159 @@ +#!/usr/bin/python + +import os,os.path, sys +import urllib, cgi + +from datetime import datetime + +from pylog_action import * +import pylog_config as cfg + +form = {} +def init(): + global form + import cgitb + cgitb.enable() + form = cgi.FieldStorage() + +print 'Content-type: text/html\n\n' + +def header(): + print '' + print ''+cfg.title+'' + print '

'+cfg.blogtitle+'

' + print '

'+cfg.subtitle+'

' + print cfg.header + print '' + +def dir_entry(f,path,depth,hidden): + 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: + dir_actions[typ](name,f,depth,hidden) + +def file_entry(f,path,depth,hidden): + 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 disp_actions: + file_link(name,f,depth,hidden) + +def process_dirs(path='.',disppath='.',depth=0,hidden=False): + dirlist = os.listdir(path) + if len(dirlist)!=0: + dir_begin(disppath,hidden) + dirs = [] + files = [] + for f in dirlist: + f = os.path.normpath(os.path.join(path,f)) + if os.path.isdir(f): + dirs.append(f) + else: + files.append(f) + + dirs.sort() + files.sort() + for f in dirs+files: + if os.path.isdir(f): + dir_entry(f,disppath,depth,hidden) + if disppath[:len(f)]==f: + process_dirs(f,disppath,depth+1,False) + else: + process_dirs(f,disppath,depth+1,True) + else: + file_entry(f,disppath,depth,hidden) + + dir_end(disppath,hidden) + +def disp_list(path): + script = sys.argv[0][sys.argv[0].rindex('/')+1:] + + 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 + keys = files.keys() + keys.sort() + keys.reverse() + 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)] + else: + typ = '' + name = os.path.basename(f) + if typ in prev_actions and not os.path.isdir(f): + sys.stdout.write('

') + print name+' -

' + prev_actions[typ](f) + + +def get_valid_path(path): + if '..' in path or os.path.normpath(path)=='.': + return cfg.contentdir + valid_chars='.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/_0123456789' + for c in path: + if not c in valid_chars: + return cfg.contentdir + return os.path.normpath(path) + +init() +path = cfg.contentdir +if 'path' in form: + path=form['path'].value + +path=get_valid_path(path) + + +print '' +header() +print '' + +print '' +print '
' +try: + if 'disp' in form: + validdisp = get_valid_path(form['disp'].value) + disp=os.path.basename(validdisp) + + if not os.path.isdir(disp): + + if '.' in disp: + typ = disp[disp.rindex('.')+1:] + name = disp[:-(len(typ)+1)] + else: + typ = '' + name = disp + if typ in disp_actions: + sys.stdout.write('

') + print name+' -

' + + disp_actions[typ](validdisp) + else: + disp_list(path) +except OSError: + pass + +print '
' +print '' +print '' diff --git a/pylog_action.py b/pylog_action.py new file mode 100644 index 0000000..d42c175 --- /dev/null +++ b/pylog_action.py @@ -0,0 +1,25 @@ +import os, os.path, sys +import urllib +from datetime import datetime + +import pylog_config as cfg +from pylog_action_impl import * + +dir_actions = { + '': dir_link +} + +disp_actions = { + 'txt': disp_txt, + 'html': disp, + 'c':disp_source, + 'py':disp_source +} + +prev_actions = { + 'txt': prev_txt, + 'html': prev, + 'c':prev_source, + 'py':prev_source +} + diff --git a/pylog_action_impl.py b/pylog_action_impl.py new file mode 100644 index 0000000..0774edc --- /dev/null +++ b/pylog_action_impl.py @@ -0,0 +1,142 @@ +import os, os.path, sys +import urllib +from datetime import datetime +import pylog_config as cfg +import subprocess,tempfile + +from HTMLParser import HTMLParser + +def dir_begin(path,hidden): + print '' +def dir_end(path,hidden): + print '' +def dir_link(name,f,depth,hidden): + script = sys.argv[0][sys.argv[0].rindex('/')+1:] + print ' ' +def file_link(name,f,depth,hidden): + script = sys.argv[0][sys.argv[0].rindex('/')+1:] + print '
  • ' + print ' '+name+'' + print '
  • ' + +def disp_txt(path): + print '
    ' + f = open(path) + print f.read() + f.close() + print '
    ' + +class BodyParser(HTMLParser): + body=False + src='' + def handle_starttag(self, tag, attrs): + if self.body: + self.src+='<'+tag + for attr in attrs: + self.src+=' '+attr[0]+'="'+attr[1]+'"' + self.src+='>' + if tag=='body': + self.body=True + def handle_endtag(self, tag): + if tag=='body': + self.body=False + if self.body: + self.src+='' + def handle_data(self, data): + if self.body: + self.src+=data + def handle_entityref(self,ref): + self.handle_charref(ref) + def handle_charref(self,ref): + if self.body: + self.src += '&'+ref+';' + + +def get_source_html(path): + tmpfile=tempfile.mkstemp(prefix="pylog")[1] + #we use a fork of vim to generate a nice syntax highlighted html file + #TODO this requires further testing + p=subprocess.Popen(["/usr/bin/vim",path,\ + "-n",\ + "-cTOhtml",\ + "-cw! "+tmpfile,\ + "-cq!",\ + "-cq!"],\ + bufsize=2**16,stdout=subprocess.PIPE,stderr=subprocess.PIPE,env={"HOME":os.getcwd()}) + p.stdout.close() + p.stderr.close() +# p.stdin.close() + p.wait() #wait for child to terminate + + f=open(tmpfile,"r") + bp=BodyParser() + bp.feed(f.read()) + src = bp.src + f.close() + #delete tmp file + os.remove(tmpfile) + return src + +def disp_source(path): + print '
    ' + print get_source_html(path) + #print source + print '
    ' + +def disp(path): + print '
    ' + f = open(path) + print f.read() + f.close() + print '
    ' + +def get_n_words(fi,n): + i=0 + txt="" + c=" " + space=False + while i<40 and len(c)==1: + c = fi.read(1) + txt+=c + if c==" " and not space: + i+=1 + space=True + else: + space=False + + if i==40: + return (txt,True) + return (txt,False) + +def prev(path): + fi = open(path) + txt=get_n_words(fi,40) + print '
    '+txt[0] + if txt[1]: + print ' ...' + print '
    ' + fi.close() + +def prev_txt(path): + fi = open(path) + txt=get_n_words(fi,40) + print '
    '+txt[0] + if txt[1]: + print ' ...' + print '
    ' + fi.close() + +def prev_source(path): + return + diff --git a/pylog_config.py b/pylog_config.py new file mode 100644 index 0000000..6e352b5 --- /dev/null +++ b/pylog_config.py @@ -0,0 +1,10 @@ +title = 'Title of destruction' +blogtitle= 'Le Blog' +subtitle='Some subtitle... and cats!' + +header=""" + + +""" +datefmt='%Y-%m-%d' +contentdir="cnt" diff --git a/source.css b/source.css new file mode 100644 index 0000000..d87fcf7 --- /dev/null +++ b/source.css @@ -0,0 +1,20 @@ +.Type { color: #00ff00; } +.Special { color: #ff40ff; } +.Constant { color: #ff6060; } +.Statement { color: #ffff00; } +.Identifier { color: #00ffff; } +.Comment { color: #8080ff; } + +.sourcecode { + white-space:wrap; + font-family:monospace; + color:#cccccc; + background-color:#222222; + padding:8px; +} + +.lnr { + display:inline; + color:#666666; +} + diff --git a/style.css b/style.css new file mode 100644 index 0000000..e47d467 --- /dev/null +++ b/style.css @@ -0,0 +1,126 @@ +/* generall */ +.hidden { + display: none +} +a { + color:#aa6735; + text-decoration:underline; + font-weight:bold; +a:hover{ +} + text-decoration:none; +} + +/* header */ +h1 { + font-size:18pt; + font-weight:bold; + padding:20px 0 0 15px; + margin:0; + color:#5598ca; + background-color:#eeeeee; + height:35px; + background-image:url(_img/tbg.png); +} +h2 { + font-size:10pt; + font-weight:bold; + padding:0 0 10px 40px; + margin:0; + color:#aa6735; + background-color:#eeeeee; + background-position:0 -55px; + background-image:url(_img/tbg.png); + height:15px; +} + +/* menu */ +#menu { + float:left; + width:15%; +} +#menu ul,li{ + margin:0; + padding:0; + list-style-type:none; +} +#menu ul{ + padding-left:10px; + border-collapse:collapse; + border-left:2px solid #ffffff; +} + +#menu ul, #menu ul ul ul{ + background-color:#ffffff; +} + +#menu ul ul, #menu ul ul ul ul{ + background-color:#eeeeee; +} + + +#menu li{ + +} +a.menulink { + padding:5px 0 5px 0; + display:block; + color:#5598ca; + font-weight:bold; + text-decoration:none; + font-size:11pt; + width:100%; +} +a.menulink:hover{ + color:white; + background-color:#777777; + text-decoration:underline; +} + +/* content */ +body { + margin:0; + background-color:#ffffff; + padding:0; + font-family:sans-serif; + color:black; +} +h3 { + font-size:14pt; + font-weight:bold; + margin:0 0 30px 20px; + color:#5598ca; +} +.entryheader { + color:#5598ca; +} + +.entrydate { + font-size:9pt; + color:#cccccc; +} + +#content { + padding:5px; + background-color:#f6f6f6; + margin-left:22%; + width:70%; + box-shadow: 6px 6px 5px #444444; + border: #f6f6f6 solid 15px; + border-radius: 15px; + margin-bottom:40px; + color:black; +} + +span.pre { + white-space:pre-wrap; + font-family:monospace; +} + + + + + + + +