import os, string, time #takes a alml string arg, returns a html string arg def convertarg(arg): s=arg.find(' ') if arg[1:s]=='/link': return '' elif arg[1:s]=='link': #PLZ dont send link anything but a URL if arg[s+1]!='\"': #has no " if arg[s+1:].find('http://') == -1: #no http:// if arg[s+1]!='/': #not local return '' else: return '' else: return '' else: #has ": if arg[s+2:].find('http://') == -1: #no http if arg[s+2]!='/': #not local return ' return '': return '
  • ' elif arg=='': return '
  • '; else: return arg #takes a string entry in alml, returns a list of strings in html def convertent(test): markups=['.\\', '<', '\n'] max=len(test) lst=[] i=0 last=0 setpre=0 previ='' #ital prevm='' #other markup while i < max-1: markfinds=[] for j in markups: markfinds.append(test.find(j, i)) tmp=filter(lambda x: x!=-1, markfinds) if tmp==[]: break else: i=min(tmp) #print `i` if test[i]=='.': # italics lst.append(test[last:i]) if previ=='': lst.append('') previ='i' else: lst.append('') previ='' last=i+2 i+=1 elif test[i]=='<': end=test.find('>',i) if end==-1: break #this is a stray < at the end lst.append(test[last:i]) #to deal with
    's. we don't want \n\n's working here
                if test[i:end+1]=='
    ': setpre=1
                elif test[end+1-6:end+1]=='
    ': setpre=0 if end-i != 1: # <...> lst.append( convertarg(test[i:end+1]) ) prevm=test[i:end+1] else: # <> lst.append( convertarg( '') prevm='' last=end+1 i=end+1 elif test[i]=='\n' and setpre==0: if i') last=i+2 i+=2 else: #\n if string.whitespace.find( test[i+1] ) is -1: lst.append(test[last:i]) lst.append('\n
    ') last=i+1 i+=1 else: i+=1 elif setpre != 0: i+=1 if last!=max: lst.append(test[last:]) if lst[-1]=='\n\n

    ' or lst[-1]=='\n
    ': return lst[:-1] return lst def printf(format, *args): sys.stdout.write (format % args) def append(req,a, oldnew='yes'): s=append_all(req, a, oldnew) #do special parenthesis stfs # try a better way s = s.replace('(','(').replace(')',')') return s def append_all(req,a, oldnew='yes'): starttime=time.time() cwd="/apache"+a[:a.rfind('/')]+'/.entries/' #efiles = os.popen('ls -1 '+ cwd +'/*.entry').read().split('\n')[:-1] efiles=os.listdir(cwd) efiles=filter(lambda x: x[-6:]=='.entry', efiles) if oldnew != 'yes': efiles.sort() efiles.reverse() else: efiles.sort() for i in range(len(efiles)): efiles[i]=cwd+efiles[i] s='' ### BUILD ent entries=[] for e in efiles: title=e[e.rfind('/')+1 : e.rfind('.')] filecontents=open(e).read() #deal with :(X( ::: sloooow! .3 to .7sec! :( #filecontents=filecontents.replace('(','(').replace(')',')') #paren=filecontents.count('(')-filecontents.count(')') #if paren > 0: #more (s than )s # filecontents+=''*paren #stuff to put quoted things in a special div splitcontents=filecontents.split('\"') if splitcontents[0]=='': #started with quote, replace all odds 1 3 evens=1 else: evens=1 #started with regular, replace evens 0 2 go=len(splitcontents) while (evens < go): if (splitcontents[evens-1] != '' and splitcontents[evens-1][-1]=='\\'): evens+=1; continue #if string.whitespace.find(splitcontents[evens]) is -1: # evens+=2 # continue splitcontents[evens]='\"' + splitcontents[evens] + '\"' evens+=2 send='' for i in splitcontents: send+=i lst=convertent(send) s+='\n\n

    \n' s+='' s+=title s+=' | modified: ' s+=time.ctime(os.path.getmtime(e)).lower() s+='\n

    ' for x in lst: #print this entry s+=x #s+=string.join(lst) s+='
    \n\n' s+='\n\n\n' s+='\n\n\n' return s def onefile(req, a): s='' file='/apache'+a lst=convertent(open(file).read()) for x in lst: s+=x return s def test(req,a): s ="

    greetz from pytone

    " s+="Passed arguments: " + a s+="
    "+a[:a.rfind('/')] return s #if this is running from the cli in python if __name__=='__main__': #print append(1,'/html/dreamthoughts/index.html', 'no') print onefile(1, '/html/entries/mindfluid')