Skip to content

Commit

Permalink
Quick and dirty progress bar for the firmware upgrade
Browse files Browse the repository at this point in the history
TODO: E.T.A., numbered steps, console output
  • Loading branch information
william-gr committed Jun 28, 2013
1 parent ba01141 commit 81f421b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions gui/system/urls.py
Expand Up @@ -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'),
Expand Down
45 changes: 45 additions & 0 deletions gui/system/views.py
Expand Up @@ -27,7 +27,9 @@

import logging
import os
import re
import shutil
import signal
import socket
import string
import subprocess
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 81f421b

Please sign in to comment.