From 3774ec261a900630599d8d6dd3ca63ada31111ea Mon Sep 17 00:00:00 2001 From: Claude Pageau Date: Tue, 21 Jul 2020 15:25:16 -0400 Subject: [PATCH] Added disk info to web page --- watch-app.sh | 4 ++-- webserver.py | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/watch-app.sh b/watch-app.sh index eec8ad9..cfafd67 100644 --- a/watch-app.sh +++ b/watch-app.sh @@ -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 diff --git a/webserver.py b/webserver.py index e19f507..b87228c 100644 --- a/webserver.py +++ b/webserver.py @@ -2,6 +2,7 @@ import cgi import os +import subprocess import socket import SocketServer import sys @@ -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. @@ -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], @@ -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): @@ -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('
  • %s
  • \n' % (urllib.quote(".."), cgi.escape("< BACK"))) f.write('

    ') - f.write('

    Web Root = %s
    ' % web_server_root) + drive_status = df(MNT_POINT) + f.write('
    Web Root is [ %s ] %s
    ' % + (web_server_root, drive_status)) f.write('
    %s
    ' % web_page_title) if web_page_refresh_on: