Created
January 28, 2009 15:22
-
-
Save batok/54004 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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