Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, bottle, subprocess as sp
- @bottle.route('/')
- def root():
- yield '<!DOCTYPE html>\n<html>\n'
- for walk in os.walk('.'):
- yield ' <h2>%s</h2>\n' % walk[0]
- for file in walk[2]:
- p = walk[0] + '/' + file
- yield ''' <a href="/edit/%s">✎</a>
- <a href="/show/%s" name="%s">%s</a> <br>\n
- ''' % (p, p, p, file)
- yield ' <br><hr>\n'
- yield '</html>'
- @bottle.route('/show/<file:path>')
- def show(file):
- yield '<!DOCTYPE html>\n<html>\n'
- yield '<h3>%s</h3>\n' % file
- yield ''' <a href="/#./%s">☰ </a>
- <a href="/edit/%s">✎</a><hr>\n''' % (file, file)
- yield sp.check_output(['markdown', file]).decode()
- yield '</html>'
- @bottle.route('/edit/<file:path>')
- def edit(file):
- yield '<!DOCTYPE html>\n<html>\n'
- yield '<h3><a href="/show/%s">%s</a></h3>\n' % (file, file)
- yield ''' <a href="/#./%s">☰ </a><hr>\n''' % file
- yield ''' <form action="/write/%s" method="post">
- <textarea rows="25" cols="120" name="text">%s</textarea><br>
- <input type="submit" value="Write">
- </form>\n''' % (file, open(file).read())
- yield '</html>'
- @bottle.route('/write/<file:path>', method='POST')
- def write(file):
- text = bottle.request.forms.get('text')
- open(file, 'w').write(text)
- yield '<!DOCTYPE html>\n<html>\n'
- yield '''File <a href="/show/%s">%s</a> was written.\n''' % (file, file)
- yield '</html>'
- @bottle.route('/static/<path:path>')
- def static(path):
- return bottle.static_file(path, root='./static')
- bottle.run(host='0.0.0.0')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement