-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapk_installer_script.py
executable file
·38 lines (31 loc) · 1.16 KB
/
apk_installer_script.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
38
import subprocess
from flask import Flask, request, render_template, Response
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import BashLexer
from jinja2 import Environment
from jinja2.loaders import FileSystemLoader
import io
app = Flask(__name__)
@app.route('/')
def render_index_page():
return render_template('apk_installer.html')
@app.route('/apk-result', methods =["POST", "GET"])
def process_html_input():
result = None
git_url = request.form.get("giturl")
def inner():
command = ['sh', 'apk_installer_from_git.sh', git_url]
subprocess.call(command)
proc = subprocess.Popen(
command,
stdout=subprocess.PIPE,
)
for line in io.TextIOWrapper(proc.stdout, encoding="utf-8"):
yield highlight(line, BashLexer(), HtmlFormatter())
result = inner
env = Environment(loader=FileSystemLoader('templates'))
tmpl = env.get_template('apk_installer.html')
return Response(tmpl.generate(result=result if result is None else result()))
if __name__=='__main__':
app.run(host='0.0.0.0')