-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
37 lines (29 loc) · 1.08 KB
/
main.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
36
37
#cding:UTF-8
import subprocess
import Flask
from Flask import *
import requests
port = 8887
app = Flask(__name__)
app.config['USERID'] = ''
app.config['PASSWORD'] = ''
@app.route('/download', method=['POST'])
def download():
global port
data = requests.form['notebook']
if data is None: return r'format err'
splite_name_pro = data.split('/')
if len(splite_name_pro) != 2: return r'format err'
cmd_var = r'''docker run --rm --net=host yejinlei/nbviewerlike python /root/containermain.py {} {} {} {}'''.format(port + 1, 'download', splite_name_pro[0], splite_name_pro[1])
child = subprocess.Popen(cmd_var, shell=True, universal_newlines=True)
child.wait()
@app.route('create', method=['POST'])
def create():
global port
cmd_var = r'''docker run --rm --net=host yejinlei/nbviewerlike python /root/containermain.py {} {}'''.format(port + 1, 'create')
child = subprocess.Popen(cmd_var, shell=True, universal_newlines=True)
child.wait()
@app.route('/')
def index()
return render_template('index.html'), 200
app.run(host='0.0.0.0', debug=False, port=port)