move flaskapp
This commit is contained in:
35
__init__.py
35
__init__.py
@@ -1,35 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
from flask import Flask,jsonify,send_from_directory, render_template
|
|
||||||
import subprocess
|
|
||||||
import os
|
|
||||||
from config import Config
|
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__, template_folder="templates", static_folder="static")
|
|
||||||
def run_cmd(cmd):
|
|
||||||
p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE,
|
|
||||||
stdin=subprocess.PIPE)
|
|
||||||
out,err = p.communicate()
|
|
||||||
return render_template("index.html",out=out+"\nErrorLog\n"+err,keys=keys, title=cfg.title.decode("utf8"))
|
|
||||||
|
|
||||||
package_directory = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
cfg = Config(file(os.path.join(package_directory, 'config.cfg')))
|
|
||||||
cmds = Config(file(os.path.join(package_directory, 'cmds.cfg')))
|
|
||||||
keys=cmds.keys()
|
|
||||||
@app.route("/")
|
|
||||||
def hello():
|
|
||||||
return render_template("index.html",out="Hello",keys=keys, title=cfg.title.decode("utf8"))
|
|
||||||
|
|
||||||
@app.route("/reload")
|
|
||||||
def reload():
|
|
||||||
cmds = Config(file(os.path.join(package_directory, 'cmds.cfg')))
|
|
||||||
return render_template("index.html",out="",keys=keys, title=cfg.title.decode("utf8"))
|
|
||||||
|
|
||||||
@app.route("/<string:cmd>")
|
|
||||||
def cm(cmd):
|
|
||||||
if cmd in cmds.keys():
|
|
||||||
c=cmds[cmd]
|
|
||||||
return run_cmd(c)
|
|
||||||
else:
|
|
||||||
return render_template("index.html", out="Command not found",keys=keys, title=cfg.title.decode("utf8")), 404
|
|
||||||
69
flaskapp/__init__.py
Normal file
69
flaskapp/__init__.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from flask import Flask,jsonify,send_from_directory, render_template
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
from config import Config
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
app = Flask(__name__, template_folder="templates", static_folder="static")
|
||||||
|
package_directory = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
cfg = Config(file(os.path.join(package_directory, 'config.cfg')))
|
||||||
|
if not "vers" in cfg:
|
||||||
|
cfg.vers=1
|
||||||
|
|
||||||
|
global cmds
|
||||||
|
if "vers" in cfg and cfg.vers == 2:
|
||||||
|
f=open(os.path.join(package_directory, 'cmds.cfg'),"r")
|
||||||
|
cmds=yaml.safe_load(f)
|
||||||
|
f.close()
|
||||||
|
keys=cmds.keys()
|
||||||
|
else:
|
||||||
|
cmds = Config(file(os.path.join(package_directory, 'cmds.cfg')))
|
||||||
|
keys=cmds.keys()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def render_index(out,code=200):
|
||||||
|
return render_template("index.html",
|
||||||
|
out=out,keys=keys,
|
||||||
|
title=cfg.title.decode("utf8"),
|
||||||
|
cmds=cmds,
|
||||||
|
vers=cfg.vers), code
|
||||||
|
|
||||||
|
|
||||||
|
def run_cmd(cmd):
|
||||||
|
p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
stdin=subprocess.PIPE)
|
||||||
|
out,err = p.communicate()
|
||||||
|
return render_index(out+"\nErrorLog\n"+err)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def hello():
|
||||||
|
return render_index(str(cmds))
|
||||||
|
|
||||||
|
@app.route("/reload")
|
||||||
|
def reload():
|
||||||
|
global cmds
|
||||||
|
if "vers" in cfg and cfg.vers == 2:
|
||||||
|
f=open(os.path.join(package_directory, 'cmds.cfg'),"r")
|
||||||
|
cmds=yaml.safe_load(f)
|
||||||
|
f.close()
|
||||||
|
keys=cmds.keys()
|
||||||
|
else:
|
||||||
|
cmds = Config(file(os.path.join(package_directory, 'cmds.cfg')))
|
||||||
|
keys=cmds.keys()
|
||||||
|
|
||||||
|
return render_index("Commands in cmds.cfg reloaded")
|
||||||
|
|
||||||
|
@app.route("/<string:cmd>")
|
||||||
|
def cm(cmd):
|
||||||
|
if cmd in keys:
|
||||||
|
if "vers" in cfg and cfg.vers == 2:
|
||||||
|
c=cmds[cmd].cmd
|
||||||
|
else:
|
||||||
|
c=cmds[cmd]
|
||||||
|
return run_cmd(c)
|
||||||
|
else:
|
||||||
|
return render_template("index.html", out="Command not found", cmds=cmds, keys=keys, title=cfg.title.decode("utf8"), vers=cfg.vers), 404
|
||||||
3
run
3
run
@@ -1,7 +1,6 @@
|
|||||||
#!./env/bin/python
|
#!./env/bin/python
|
||||||
from management import app
|
from flaskapp import app
|
||||||
|
|
||||||
#print("sdf2")
|
|
||||||
#app.run(debug=True)
|
#app.run(debug=True)
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# if len(sys.argv) > 1 and sys.argv[1] == "build":
|
# if len(sys.argv) > 1 and sys.argv[1] == "build":
|
||||||
|
|||||||
Reference in New Issue
Block a user