]>
Commit | Line | Data |
---|---|---|
25a66962 MF |
1 | #!/usr/bin/env python3 |
2 | import os | |
3 | import tornado.ioloop | |
4 | import tornado.web | |
5 | ||
6 | class MainHandler(tornado.web.RequestHandler): | |
7 | def get(self, path): | |
8 | base_path="/mnt/data2/" | |
9 | fp = os.path.join(base_path, path) | |
10 | if not os.path.exists(fp): | |
11 | return self.write("Not found") | |
12 | if os.path.isdir(fp): | |
13 | items = os.listdir(fp) | |
14 | items2 = [] | |
15 | for item in items: | |
16 | if os.path.isdir(os.path.join(fp,item)): | |
17 | item = item+"/" | |
18 | items2.append(item) | |
19 | self.render("dir.html",items=items2, title=path) | |
20 | return | |
21 | self.set_header("Content-Type", "binary/octet-stream") | |
22 | self.write(open(fp,"rb").read()) | |
23 | ||
24 | application = tornado.web.Application([ | |
25 | (r"/(.*)", MainHandler), | |
26 | ], debug=True) | |
27 | ||
28 | if __name__ == "__main__": | |
29 | application.listen(1234) | |
30 | tornado.ioloop.IOLoop.instance().start() |