Add free disk space on /storage

This commit is contained in:
Dmitri Popov
2018-03-28 19:12:21 +02:00
parent b1f68f3244
commit 2f8ea00ec3
2 changed files with 11 additions and 4 deletions

View File

@@ -19,8 +19,14 @@ import os
@route('/') @route('/')
@route('/', method='POST') @route('/', method='POST')
def remote_control(): def remote_control():
st = os.statvfs("/home") st_home = os.statvfs("/home")
free = "%.2f" % float((st.f_bavail * st.f_frsize)/1.073741824e9) free_home = "%.2f" % float((st_home.f_bavail * st_home.f_frsize)/1.073741824e9)
if os.path.isdir("/media/storage"):
st_storage = os.statvfs("/media/storage")
free_storage = "%.2f" % float((st_storage.f_bavail * st_storage.f_frsize)/1.073741824e9)
else:
free_storage="N/A"
if (request.POST.get("cardbackup")): if (request.POST.get("cardbackup")):
os.system("sudo /home/pi/little-backup-box/scripts/card-backup.sh") os.system("sudo /home/pi/little-backup-box/scripts/card-backup.sh")
return ('Backup started. You can close this page.') return ('Backup started. You can close this page.')
@@ -34,7 +40,7 @@ def remote_control():
if (request.POST.get("shutdown")): if (request.POST.get("shutdown")):
os.system("sudo shutdown -h now") os.system("sudo shutdown -h now")
return ('Shutdown request sent. You can close this page.') return ('Shutdown request sent. You can close this page.')
return template('rc.tpl', freespace=free) return template('rc.tpl', freespace_home=free_home, freespace_storage=free_storage)
@route('/static/:path#.+#', name='static') @route('/static/:path#.+#', name='static')
def static(path): def static(path):

View File

@@ -46,7 +46,8 @@
<form method="POST" action="/"> <form method="POST" action="/">
<div id="content"> <div id="content">
<div id="header"><img src="static/ichigo.svg" height="39px" alt="Ichigo" align=""> Little Backup Box</div> <div id="header"><img src="static/ichigo.svg" height="39px" alt="Ichigo" align=""> Little Backup Box</div>
<p class="center">Free disk space on <i>/home</i>: <b>{{freespace}}</b> GB</p> <p class="center">Free disk space on <i>/home</i>: <b>{{freespace_home}}</b> GB</p>
<p class="center">Free disk space on <i>/storage</i>: <b>{{freespace_storage}}</b> GB</p>
<hr> <hr>
<p class="left">Back up a storage card connected via a card reader</p> <p class="left">Back up a storage card connected via a card reader</p>
<p><input id="btn" name="cardbackup" type="submit" value="Card backup"></p> <p><input id="btn" name="cardbackup" type="submit" value="Card backup"></p>