Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Quick and dirty progress bar for the firmware upgrade

TODO: E.T.A., numbered steps, console output
  • Loading branch information...
commit 81f421ba0b88bc7c5722393081f12239172a2fe2 1 parent ba01141
@williambr williambr authored
Showing with 46 additions and 0 deletions.
  1. +1 −0  gui/system/urls.py
  2. +45 −0 gui/system/views.py
View
1  gui/system/urls.py
@@ -42,6 +42,7 @@
url(r'^firmwizard/$', FirmwareWizard.as_view(
[FirmwareTemporaryLocationForm,FirmwareUploadForm]
), name='system_firmwizard'),
+ url(r'^firmwizard/progress/$', "firmware_progress", name="system_firmware_progress"),
url(r'^config/restore/$', 'config_restore', name='system_configrestore'),
url(r'^config/save/$', 'config_save', name='system_configsave'),
url(r'^config/upload/$', 'config_upload', name='system_configupload'),
View
45 gui/system/views.py
@@ -27,7 +27,9 @@
import logging
import os
+import re
import shutil
+import signal
import socket
import string
import subprocess
@@ -59,6 +61,9 @@
GRAPHS_DIR = '/var/db/graphs'
VERSION_FILE = '/etc/version'
DEBUG_TEMP = '/tmp/debug.txt'
+PGFILE = '/tmp/.extract_progress'
+DDFILE = '/tmp/.upgrade_dd'
+RE_DD = re.compile(r"^(\d+) bytes", re.M | re.S)
log = logging.getLogger('system.views')
@@ -464,6 +469,46 @@ def file_browser(request, path='/'):
return HttpResponse(content, mimetype='application/json')
+def firmware_progress(request):
+
+ data = {}
+ if os.path.exists(PGFILE):
+ with open(PGFILE, 'r') as f:
+ last = f.readlines()
+ if last:
+ step, percent = last[-1].split("|")
+ data['step'] = int(step)
+ percent = percent.strip()
+ if percent:
+ data['percent'] = int(percent)
+ else:
+ data['indeterminate'] = True
+ elif os.path.exists(DDFILE):
+ with open(DDFILE, 'r') as f:
+ pid = f.readline()
+ if pid:
+ pid = int(pid.strip())
+ try:
+ os.kill(pid, signal.SIGINFO)
+ time.sleep(0.5)
+ with open(DDFILE, 'r') as f2:
+ line = f2.read()
+ reg = RE_DD.findall(line)
+ if reg:
+ current = int(reg[-1])
+ size = os.stat("/var/tmp/firmware/firmware.img").st_size
+ percent = int((current / size) * 100)
+ data = {
+ 'step': 3,
+ 'percent': percent,
+ }
+ except OSError:
+ pass
+
+ content = simplejson.dumps(data)
+ return HttpResponse(content, mimetype='application/json')
+
+
def restart_httpd(request):
""" restart httpd """
notifier().restart("http")
Please sign in to comment.
Something went wrong with that request. Please try again.