Created
November 23, 2012 08:15
-
-
Save se4c0met/4134490 to your computer and use it in GitHub Desktop.
Browse AppFog file system (Python WSGI instance)
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 os | |
from bottle import Bottle,route,static_file,run | |
from StringIO import StringIO | |
application = app = Bottle() | |
@app.route('/') | |
def hello(): | |
return "<pre>Usage: Browse http://<your domain>.aws.af.cm/ls//" | |
@app.route('/ls/<filename:path>') | |
def ls(filename): | |
output = StringIO() | |
print >>output, '<p>Input path: %s</p>\n' % (filename) | |
print >>output, '<p>Current path: %s</p>\n' % (os.getcwd()) | |
if os.path.isdir(filename): | |
print >>output, '<h3>Content</h3>\n' | |
try: | |
for dir in os.listdir(filename): | |
if os.path.isdir(filename + dir): | |
print >>output, '<div><a href="/ls/%s%s/">%s</a></div>\n' % (filename,dir,dir) | |
else: | |
#print >>output, '<div>%s</div>\n' % (dir) | |
print >>output, '<div><a href="/cat/%s%s">%s</a></div>\n' % (filename,dir,dir) | |
except: | |
print >>output, '<div>error listing %s</div>\n' % (filename) | |
else: | |
print >>output, '<div>%s is not a directory' % (filename) | |
return output.getvalue() | |
@app.route('/cat/<filename:path>') | |
def cat(filename): | |
output = StringIO() | |
print >>output, '<p>Input path: %s</p>\n' % (filename) | |
tgt_path = filename.replace('%20',' ') | |
print >>output, '<p>Target path: %s</p>\n' % (tgt_path) | |
if os.path.isfile(tgt_path): | |
#print >>output, '<pre>content of %s</pre>\n' % (filename) | |
dirname = os.path.dirname(tgt_path) | |
fname = os.path.basename(tgt_path) | |
print >>output, '<p>Dirname: %s</p>\n' % (dirname) | |
print >>output, '<p>Filename: %s</p>\n' % (fname) | |
try: | |
return static_file(fname, root=dirname) | |
except: | |
print >>output, '<p>unable to return static file</p>' | |
return output.getvalue() | |
if __name__ == '__main__': | |
run(app, host='localhost', port=5000, reloader=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment