Fixed a bug where directories with unknown type would show up in the menu

master
Stefan Krulj 14 years ago
parent 5fb51bb00d
commit 0df01800cf
  1. 18
      pylog.py
  2. 150
      pylog_action_impl.py
  3. 2
      pylog_config.py

@ -15,14 +15,18 @@ import comment_section
__version = "v0.1-(2012-03-15)"
def dir_entry(f,path,depth,hidden):
def get_dir_name_type(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)
name = os.path.basename(f)
return (name,typ)
def dir_entry(f,path,depth,hidden):
name,typ = get_dir_name_type(f)
if typ in dir_actions:
dir_actions[typ](name,f,depth,hidden)
@ -39,6 +43,12 @@ def file_entry(f,path,depth,hidden):
def process_dirs(path='.',disppath='.',depth=0,hidden=False):
dirlist = os.listdir(path)
if len(dirlist)!=0:
# don't list directories with unknown action
name,typ = get_dir_name_type(path)
if not typ in dir_actions:
return
dir_begin(disppath,hidden,depth)
dirs = []
files = []
@ -54,6 +64,8 @@ def process_dirs(path='.',disppath='.',depth=0,hidden=False):
for f in dirs+files:
if os.path.isdir(f):
dir_entry(f,disppath,depth,hidden)
# if the directory is a part of the path we want
# to show -> show it, if not -> hide it's contents
if disppath[:len(f)]==f:
process_dirs(f,disppath,depth+1,False)
else:

@ -42,7 +42,84 @@ def disp_txt(path):
print markdown.markdown(txt,extensions=cfg.markdown_extensions).encode(cfg.encoding)
f.close()
print '</div>'
def disp_python(path):
disp_source(path,"python",True)
def disp_c(path):
disp_source(path,"c",True)
def disp_source(path,lang,line_numbers):
print '<div class="entrytext">'
f = codecs.open(path, mode="r", encoding=cfg.encoding)
if line_numbers:
txt="\t#!"+lang+'\n'
else:
txt="\t:::"+lang+'\n'
for line in f.read().split('\n'):
txt += "\t"+line+'\n'
print markdown.markdown(txt,extensions=cfg.markdown_extensions).encode(cfg.encoding)
f.close()
print '</div>'
def disp(path):
print '<div class="entrytext">'
f = codecs.open(path, mode="r", encoding=cfg.encoding)(path)
print f.read().encode(cfg.encoding)
f.close()
print '</div>'
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 = codecs.open(path, mode="r", encoding=cfg.encoding)
txt=get_n_words(fi,40)
print '<div class="preview">'+txt[0].encode(cfg.encoding)
if txt[1]:
print '<i>&nbsp;...</i>'
print '</div>'
fi.close()
def prev_txt(path):
fi = codecs.open(path, mode="r", encoding=cfg.encoding)
txt=get_n_words(fi,40)
print '<div class="preview">'+markdown.markdown(txt[0],extensions=cfg.markdown_extensions).encode(cfg.encoding)
if txt[1]:
print '<i>&nbsp;...</i>'
print '</div>'
fi.close()
def prev_source(path):
return
# Legacy code ------------------------
# using vim for syntax highlighting,could be usefull,
# old disp_source using vim
#def disp_source(path):
# print '<div class="sourcecode">'
# print get_source_html(path).encode(cfg.encoding)
# #print source
# print '</div>'
class BodyParser(HTMLParser):
body=False
src=''
@ -69,14 +146,6 @@ class BodyParser(HTMLParser):
if self.body:
self.src += '&'+ref+';'
# Legacy code used vim for syntax highlighting, as this could be usefull,
# I'll keep it here
# old disp_source using vim
#def disp_source(path):
# print '<div class="sourcecode">'
# print get_source_html(path).encode(cfg.encoding)
# #print source
# print '</div>'
def get_source_html(path):
tmpdir = os.path.join(tempfile.gettempdir(),"pylog")
cache=False
@ -125,69 +194,4 @@ def get_source_html(path):
if not cache:
os.remove(tmpfile)
return src
def disp_python(path):
disp_source(path,"python",True)
def disp_c(path):
disp_source(path,"c",True)
def disp_source(path,lang,line_numbers):
print '<div class="entrytext">'
f = codecs.open(path, mode="r", encoding=cfg.encoding)
if line_numbers:
txt="\t#!"+lang+'\n'
else:
txt="\t:::"+lang+'\n'
for line in f.read().split('\n'):
txt += "\t"+line+'\n'
print markdown.markdown(txt,extensions=cfg.markdown_extensions).encode(cfg.encoding)
f.close()
print '</div>'
def disp(path):
print '<div class="entrytext">'
f = codecs.open(path, mode="r", encoding=cfg.encoding)(path)
print f.read().encode(cfg.encoding)
f.close()
print '</div>'
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 = codecs.open(path, mode="r", encoding=cfg.encoding)
txt=get_n_words(fi,40)
print '<div class="preview">'+txt[0].encode(cfg.encoding)
if txt[1]:
print '<i>&nbsp;...</i>'
print '</div>'
fi.close()
def prev_txt(path):
fi = codecs.open(path, mode="r", encoding=cfg.encoding)
txt=get_n_words(fi,40)
print '<div class="preview">'+markdown.markdown(txt[0],extensions=cfg.markdown_extensions).encode(cfg.encoding)
if txt[1]:
print '<i>&nbsp;...</i>'
print '</div>'
fi.close()
def prev_source(path):
return

@ -38,7 +38,7 @@ encoding="utf-8"
# format. See manual reference for codecs.open for
# details
markdown_extensions = ['math','gallery','tables','footnotes','codehilite(guess_lang=False)','abbr']
markdown_extensions = ['math','gallery','extra','codehilite(guess_lang=False)',]
# Markdown extensions:
# math .......... rich subset of latex formulas between $$ c^2=a^2+b^2 $$
# gallery ....... galleries support:

Loading…
Cancel
Save