Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
tornado works for dir / file
Browse files Browse the repository at this point in the history
  • Loading branch information
alswl committed Jul 4, 2014
1 parent 8eb8da3 commit c21c095
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 0 deletions.
41 changes: 41 additions & 0 deletions kuku/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# coding=utf-8

import tornado.ioloop
import tornado.web

from handlers import dir, file
import settings


re_safe_name_with_slash = ur'[ \w\u2e80-\u9fff\-_\.,/]'


class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")


application = tornado.web.Application([
(r'/_admin/', MainHandler),
(r'/_admin/login', MainHandler),
(r'/_admin/logout', MainHandler),
(r'/_admin/upload', MainHandler),
(r'/_admin/mkdir', MainHandler),
(r'/_admin/delete', MainHandler),
(r'/()', dir.DirHandler),
(r'/(%s+/)' % re_safe_name_with_slash, dir.DirHandler),
(r'/(%s+)' % re_safe_name_with_slash, tornado.web.StaticFileHandler, {'path': settings.UPLOAD_PATH}),
])


if __name__ == "__main__":
print """Kuku Start Work!
_ __ _ __
| | / / | | / /
| |/ / _ _| |/ / _ _
| \| | | | \| | | |
| |\ \ |_| | |\ \ |_| |
\_| \_/\__,_\_| \_/\__,_|
"""
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Empty file added kuku/handlers/__init__.py
Empty file.
Empty file added kuku/handlers/account.py
Empty file.
1 change: 1 addition & 0 deletions kuku/handlers/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

28 changes: 28 additions & 0 deletions kuku/handlers/dir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# coding=utf-8

import os

import tornado.ioloop
import tornado.web

import settings


class DirHandler(tornado.web.RequestHandler):

def get(self, path):
abs_path = os.path.abspath(os.path.join(settings.UPLOAD_PATH, path))
if settings.UPLOAD_PATH not in abs_path:
raise tornado.web.HTTPError(404)

dirs = []
files = []
l = os.listdir(abs_path)
for f in l:
if os.path.isdir(os.path.join(abs_path, f)):
dirs.append(f)
else:
files.append(f)

self.write(','.join(dirs) + '; ' + ','.join(files))

13 changes: 13 additions & 0 deletions kuku/handlers/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# coding=utf-8

import os

import tornado.ioloop
import tornado.web


class FileHandler(tornado.web.RequestHandler):

def get(self):
self.write('file')

21 changes: 21 additions & 0 deletions kuku/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# coding=utf-8

import os

DEBUG = True

ADMIN = 'alswl'
PASSWORD = '123456'

ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
TEMPLATES_PATH = os.path.abspath(os.path.join(ROOT_PATH, 'templates'))
UPLOAD_PATH = os.path.abspath(os.path.join(ROOT_PATH, '..', 'upload'))

MAX_FILE_SIZE = 5 * 1024 * 1024 # 3 * 1024 * 1024 bytes
ALLOWED_EXTENSIONS = ['jpg', 'png', 'gif', 'zip', 'rar', 'gz']

#DEFAULT_DIR_MODE = '755'
#DEFAULT_FILE_MODE = '644'

#NOT_ALLOWD_NAME = ['admin']

0 comments on commit c21c095

Please sign in to comment.