/
server_git.py
executable file
·35 lines (29 loc) · 995 Bytes
/
server_git.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
import tornado.ioloop
import tornado.web
import git
from settings_git import *
class UploadHandler(tornado.web.RequestHandler):
def post(self, filename):
print(filename + ' upload')
print(DATA_DIR + filename)
git.repo(DATA_DIR)
with open(DATA_DIR + filename, 'wb') as f:
f.write(self.request.body)
git.add(DATA_DIR + filename)
git.commit(filename + ' added')
class DownloadHandler(tornado.web.RequestHandler):
def get(self, filename):
print(filename + ' download')
print(DATA_DIR + filename)
with open(DATA_DIR + filename, 'rb') as f:
self.write(f.read())
if __name__ == '__main__':
application = tornado.web.Application([
(r"/upload/(.*)", UploadHandler),
(r"/download/(.*)", DownloadHandler)
])
print('main starting...')
application.listen(PORT, '0.0.0.0')
tornado.ioloop.IOLoop.instance().start()
print('main finished')