Skip to content

Commit

Permalink
Added disk info to web page
Browse files Browse the repository at this point in the history
  • Loading branch information
pageauc committed Jul 21, 2020
1 parent 72ba667 commit 3774ec2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions watch-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ echo "$progName $ver written by Claude Pageau"
#==================================

watch_config_on=false # true= Remotely Manage Files from Remote Storage false=off
watch_app_on=false # true= Monitor watch_app_fname and attempt restart false=off
watch_reboot_on=false # true= Reboot RPI If watch_app_fname Down false=0ff
watch_app_on=true # true= Monitor watch_app_fname and attempt restart false=off
watch_reboot_on=true # true= Reboot RPI If watch_app_fname Down false=0ff

watch_app_fname="speed-cam.py" # Filename of Program to Monitor for Run Status

Expand Down
24 changes: 22 additions & 2 deletions webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cgi
import os
import subprocess
import socket
import SocketServer
import sys
Expand All @@ -10,7 +11,7 @@
from SimpleHTTPServer import SimpleHTTPRequestHandler
from StringIO import StringIO

PROG_VER = "ver 7.6 written by Claude Pageau"
PROG_VER = "ver 7.7 written by Claude Pageau"
'''
SimpleHTTPServer python program to allow selection of images from right panel and display in an iframe left panel
Use for local network use only since this is not guaranteed to be a secure web server.
Expand Down Expand Up @@ -54,6 +55,7 @@
os.chdir(web_server_root)
web_root = os.getcwd()
os.chdir(BASE_DIR)
MNT_POINT = "./"

try:
myip = ([l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1],
Expand All @@ -77,6 +79,22 @@

list_title = "%s %s" % (dir_sort, dir_order)

def df(drive_mnt):
'''
function to read disk drive data using unix df command
for the specified mount point.
Returns a formatted string of Disk Status
'''
try:
df = subprocess.Popen(["df", "-h", drive_mnt], stdout=subprocess.PIPE)
output = df.communicate()[0]
device, size, used, available, percent, mountpoint = output.split("\n")[1].split()
drive_status = ("Disk Info: %s Mount Point: %s Used: %s %s of %s Avail: %s" %
(device, mountpoint, percent, used, size, available))
except:
drive_status = "df command Error. No drive status avail"
return drive_status

class DirectoryHandler(SimpleHTTPRequestHandler):

def list_directory(self, path):
Expand Down Expand Up @@ -168,7 +186,9 @@ def list_directory(self, path):
if (not self.path is "/") and display_entries > 35: # Display folder Back arrow navigation if not in web root
f.write('<li><a href="%s" >%s</a></li>\n' % (urllib.quote(".."), cgi.escape("< BACK")))
f.write('</ul></div><p><b>')
f.write('<div style="float: left; padding-left: 40px;">Web Root = %s</div>' % web_server_root)
drive_status = df(MNT_POINT)
f.write('<div style="float: left; padding-left: 40px;">Web Root is [ %s ] %s</div>' %
(web_server_root, drive_status))
f.write('<div style="text-align: center;">%s</div>' % web_page_title)

if web_page_refresh_on:
Expand Down

0 comments on commit 3774ec2

Please sign in to comment.