Skip to content

Commit

Permalink
Button changes, attempted to add pausing, doesn't work yet
Browse files Browse the repository at this point in the history
  • Loading branch information
R2Boyo25 committed Dec 20, 2021
1 parent 1ba5396 commit e90da28
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
39 changes: 31 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
from fcntl import fcntl, F_GETFL, F_SETFL
from os import O_NONBLOCK, read
import signal

app = Flask('ProgramManager')

Expand All @@ -16,6 +17,7 @@ def __init__(self, name, dct):
self.dct = dct
self.process = None
self.env = os.environ.copy()
self.paused = False
if "start" in self.dct:
if self.dct["start"]:
self.start()
Expand Down Expand Up @@ -63,10 +65,13 @@ def out(self):

@property
def running(self):
if self.process is not None:
return self.process.poll() is None
if not self.paused:
if self.process is not None:
return self.process.poll() is None
else:
return False
else:
return False
return True


class Procs:
Expand Down Expand Up @@ -139,6 +144,20 @@ def startProc(proc):

return redirect("/proc/" + proc)

@app.route("/pause/<proc>")
def pauseProc(proc):
procs.proc(proc).paused = True
os.kill(procs.proc(proc).process.pid, signal.SIGSTOP)

return redirect("/proc/" + proc)

@app.route("/unpause/<proc>")
def unpauseProc(proc):
procs.proc(proc).paused = False
os.kill(procs.proc(proc).process.pid, signal.SIGCONT)

return redirect("/proc/" + proc)

@app.route("/out/<proc>")
def statTest(proc):
return str(procs.proc(proc).out).replace("\n", "<br>\n")
Expand All @@ -155,17 +174,21 @@ def reloadAll():
def jsonStatus():
if len(procs.dct.keys()) > 0:
running = 0
paused = 0
for proc in procs.dct.keys():
prc = procs.proc(proc)
if prc.running:
if prc.running and not prc.paused:
running += 1
if prc.paused:
paused += 1

runningpercent = running / len(procs.dct.keys())
crashedpercent = 1-runningpercent
pausedpercent = paused / len(procs.dct.keys())
crashedpercent = 1-runningpercent-pausedpercent

return json.dumps({
"running": f"{round(runningpercent*100)}%",
"paused": "0%",
"paused": f"{round(pausedpercent*100)}%",
"killed": f"{round(crashedpercent*100)}%"
})
else:
Expand All @@ -181,11 +204,11 @@ def home():

@app.route("/list")
def listProcs():
return render_template("list.html", procs = [[procs.dct[i].running, i] for i in procs.dct])
return render_template("list.html", procs = [[procs.dct[i].running, i, i.paused] for i in procs.dct])

@app.route("/proc/<proc>")
def procShow(proc):
return render_template("proc.html", proc = proc, procdata = procs.proc(proc).dct)
return render_template("proc.html", proc = proc, procdata = procs.proc(proc).dct, running = procs.proc(proc).running, paused = procs.proc(proc).paused)

@app.route('/source/<path:filename>')
def returnSourceFile(filename):
Expand Down
6 changes: 3 additions & 3 deletions source/play.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion templates/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
<tr>
<td><a href = "/proc/{{proc[1]}}">{{ proc[1] }}</a></td>
<td>{{ "Not Running" if not proc[0] else "Running" }}</td>
<td><a href = /start/{{proc[1]}} ><img src = "/source/play.svg"/></a></td>
<td>
{% if proc[0] %}
<a href = "/restart/{{proc[1]}}"><img src="/source/restart.svg"/></a>
<a href = "/kill/{{proc[1]}}"><img src="/source/kill.svg"></a>
{% else %}
<a href = /start/{{proc[1]}} ><img src = "/source/play.svg"/></a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
Expand Down
14 changes: 11 additions & 3 deletions templates/proc.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@
{% endblock %}

{% block sidebuttons %}
<a href = "/start/{{proc}}"><img src="/source/play.svg"/></a>
<a href = "/restart/{{proc}}"><img src="/source/restart.svg"/></a>
<a href = "/kill/{{proc}}"><img src="/source/kill.svg"></a>
{% if running %}
<a href = "/restart/{{proc}}"><img src="/source/restart.svg"/></a>
<a href = "/kill/{{proc}}"><img src="/source/kill.svg"></a>
{% if paused %}
<a href = "/unpause/{{proc}}"><img src="/source/play.svg"></a>
{% else %}
<a href = "/pause/{{proc}}"><img src="/source/pause.svg"></a>
{% endif %}
{% else %}
<a href = "/start/{{proc}}"><img src="/source/play.svg"/></a>
{% endif %}
{% endblock %}

0 comments on commit e90da28

Please sign in to comment.