Advertisement
Guest User

dviglo

a guest
Oct 21st, 2015
210
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os, bottle, subprocess as sp
  2.  
  3.  
  4. @bottle.route('/')
  5. def root():
  6.     yield '<!DOCTYPE html>\n<html>\n'
  7.    
  8.     for walk in os.walk('.'):
  9.         yield '    <h2>%s</h2>\n' % walk[0]
  10.         for file in walk[2]:
  11.             p = walk[0] + '/' + file
  12.             yield '''    <a href="/edit/%s">✎</a>
  13.            <a href="/show/%s" name="%s">%s</a> <br>\n
  14.            ''' % (p, p, p, file)
  15.         yield '    <br><hr>\n'
  16.     yield '</html>'
  17.  
  18.  
  19.  
  20. @bottle.route('/show/<file:path>')
  21. def show(file):
  22.     yield '<!DOCTYPE html>\n<html>\n'
  23.    
  24.     yield '<h3>%s</h3>\n' % file
  25.     yield '''    <a href="/#./%s">☰ </a>
  26.    <a href="/edit/%s">✎</a><hr>\n''' % (file, file)
  27.    
  28.     yield sp.check_output(['markdown', file]).decode()
  29.    
  30.     yield '</html>'
  31.  
  32.  
  33.  
  34. @bottle.route('/edit/<file:path>')
  35. def edit(file):
  36.     yield '<!DOCTYPE html>\n<html>\n'
  37.    
  38.     yield '<h3><a href="/show/%s">%s</a></h3>\n' % (file, file)
  39.     yield '''    <a href="/#./%s">☰ </a><hr>\n''' % file
  40.    
  41.     yield '''    <form action="/write/%s" method="post">
  42.        <textarea rows="25" cols="120" name="text">%s</textarea><br>
  43.        <input type="submit" value="Write">
  44.    </form>\n''' % (file, open(file).read())
  45.    
  46.     yield '</html>'
  47.  
  48.  
  49.  
  50. @bottle.route('/write/<file:path>', method='POST')
  51. def write(file):
  52.     text = bottle.request.forms.get('text')
  53.     open(file, 'w').write(text)
  54.    
  55.     yield '<!DOCTYPE html>\n<html>\n'
  56.     yield '''File <a href="/show/%s">%s</a> was written.\n''' % (file, file)
  57.     yield '</html>'
  58.  
  59.  
  60.  
  61. @bottle.route('/static/<path:path>')
  62. def static(path):
  63.     return bottle.static_file(path, root='./static')
  64.  
  65.  
  66. bottle.run(host='0.0.0.0')
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement