Skip to content

Instantly share code, notes, and snippets.

@batok
Created January 28, 2009 15:22
Show Gist options
  • Save batok/54004 to your computer and use it in GitHub Desktop.
Save batok/54004 to your computer and use it in GitHub Desktop.
import wx
from breve.tags.html import tags as T
from breve.flatten import flatten
import os
from stat import *
"""
This is now a wxpython version.
Builds an show in browser and html file showing directories and files in selected PATH
"""
def bunch( mpath, type = "f" ):
function = S_ISDIR
if type == "f":
function = S_ISREG
result = []
for x in os.listdir(mpath):
mfile = "%s/%s" % ( mpath, x )
if function( os.stat( mfile )[ST_MODE] ):
result.append(x)
return result
def gen_and_show( mpath ):
colors = ["blue", "red"]
c = T.html[ T.body[
T.h1(style = "color: black")[mpath], T.h3(style = "color: black")["Directories"], T.ol[
[T.li(style="color: %s" % colors[i % 2] )[x] for i,x in enumerate( bunch( mpath, "d" ) ) ],
T.h3( style = "color: black")["Files"],
[T.li(style="color: %s" % colors[i % 2] )[x] for i,x in enumerate( bunch( mpath ) ) ]
]
]
]
f = open("foo.html", "w")
f.write(flatten(c))
f.close()
os.system( "open foo.html")
if __name__ == "__main__":
app = wx.PySimpleApp()
dlg = wx.DirDialog( None, "Choose a Directory", style = wx.DD_DEFAULT_STYLE)
if dlg.ShowModal() == wx.ID_OK:
gen_and_show( dlg.GetPath() )
dlg.Destroy()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment