From: Calin Crisan Date: Sat, 9 Nov 2013 15:15:45 +0000 (+0200) Subject: added disk usage support X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=91d51c7ca948323e6bbeedec5c8e551e1ebd3ea7;p=motioneye-debian added disk usage support --- diff --git a/doc/todo.txt b/doc/todo.txt index f231b0a..ae41efb 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,4 +1,3 @@ --> disk usage at bottom -> make camera frames positions configurable -> add a view log functionality -> add a previewer for snapshots diff --git a/src/config.py b/src/config.py index ed255b8..851e64a 100644 --- a/src/config.py +++ b/src/config.py @@ -23,6 +23,7 @@ import re from collections import OrderedDict import settings +import utils import v4l2ctl @@ -556,9 +557,11 @@ def camera_ui_to_dict(ui): return data + def camera_dict_to_ui(data): if data['@proto'] == 'v4l2': device_uri = data['videodevice'] + disk_used, disk_total = utils.get_disk_usage(data['target_dir']) else: device_uri = '%(host)s:%(port)s/config/%(camera_id)s' % { @@ -567,6 +570,8 @@ def camera_dict_to_ui(data): 'host': data['@host'], 'port': data['@port'], 'camera_id': data['@remote_camera_id']} + + disk_used, disk_total = data['disk_used'], data['disk_total'] ui = { # device @@ -588,6 +593,8 @@ def camera_dict_to_ui(data): 'network_username': data['@network_username'], 'network_password': data['@network_password'], 'root_directory': data.get('target_dir'), + 'disk_used': disk_used, + 'disk_total': disk_total, # text overlay 'text_overlay': False, diff --git a/src/handlers.py b/src/handlers.py index d8a04e6..309ceae 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -486,6 +486,8 @@ class ConfigHandler(BaseHandler): tmp_config = config.camera_ui_to_dict(remote_ui_config) tmp_config.update(camera_config) + tmp_config['disk_used'] = remote_ui_config['disk_used'] + tmp_config['disk_total'] = remote_ui_config['disk_total'] ui_config = config.camera_dict_to_ui(tmp_config) ui_config['available_resolutions'] = remote_ui_config['available_resolutions'] @@ -509,7 +511,8 @@ class ConfigHandler(BaseHandler): motionctl.restart() self.finish_json() - + + class SnapshotHandler(BaseHandler): @asynchronous def get(self, camera_id, op, filename=None): diff --git a/src/utils.py b/src/utils.py index c059e94..4fad4d8 100644 --- a/src/utils.py +++ b/src/utils.py @@ -16,6 +16,8 @@ # along with this program. If not, see . import datetime +import logging +import os def pretty_date_time(date_time, tzinfo=None): @@ -165,3 +167,26 @@ def pretty_duration(duration): format = '-' + format return format.format(d=days, h=hours, m=minutes, s=seconds) + + +def get_disk_usage(path): + logging.debug('getting disk usage for path %(path)s...' % { + 'path': path}) + + try: + result = os.statvfs(path) + + except OSError as e: + logging.error('failed to execute statvfs: %(msg)s' % {'msg': unicode(e)}) + + return None + + block_size = result.f_frsize + free_blocks = result.f_bfree + total_blocks = result.f_blocks + + free_size = free_blocks * block_size + total_size = total_blocks * block_size + used_size = total_size - free_size + + return (used_size, total_size) diff --git a/static/css/main.css b/static/css/main.css index ae0c251..a559729 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -63,15 +63,21 @@ div.footer { position: absolute; bottom: 5px; width: 100%; - height: 2.2em; + height: 3em; font-size: 0.7em; color: #aaa; text-align: center; } +div.copyright-note { + border-top: 1px solid #333; + padding-top: 0.2em; + margin: 0px 15%; +} + div.page-container { transition: all 0.2s linear; - padding: 55px 5px 2.2em 5px; + padding: 55px 5px 3em 5px; } div.page-container.stretched { @@ -304,6 +310,35 @@ input[type=text].working-schedule.number { width: 50px; } +span.disk-usage-text { + vertical-align: middle; +} + +div.disk-usage-bar-container { + position: relative; + width: 90%; + height: 1em; + border: 1px solid #555; + vertical-align: middle; + margin: 0px 0.2em; + text-align: center; + line-height: 1em; +} + +div.disk-usage-bar-fill { + position: absolute; + left: 0px; + top: 0px; + bottom: 0px; + width: 0%; + background-color: #555; +} + +span.disk-usage-percent { + font-size: 0.8em; + position: relative; +} + div.rpi, tr.rpi { display: none; diff --git a/static/js/main.js b/static/js/main.js index 172dcb8..a210093 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -604,6 +604,10 @@ function dict2CameraUi(dict) { $('#networkUsernameEntry').val(dict['network_username']); $('#networkPasswordEntry').val(dict['network_password']); $('#rootDirectoryEntry').val(dict['root_directory']); + var percent = parseInt(dict['disk_used'] * 100 / dict['disk_total']); + $('#diskUsageBarFill').css('width', percent + '%'); + $('#diskUsageText').html( + (dict['disk_used'] / 1073741824).toFixed(1) + '/' + (dict['disk_total'] / 1073741824).toFixed(1) + ' GB (' + percent + '%)'); /* text overlay */ $('#textOverlaySwitch')[0].checked = dict['text_overlay']; diff --git a/static/js/ui.js b/static/js/ui.js index 43a5d85..b4d2d5c 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -561,8 +561,8 @@ function updateModalDialogPosition() { var modalWidth = container.width(); var modalHeight = container.height(); - container.css('left', (windowWidth - modalWidth) / 2); - container.css('top', (windowHeight - modalHeight) / 2); + container.css('left', Math.floor((windowWidth - modalWidth) / 2)); + container.css('top', Math.floor((windowHeight - modalHeight) / 2)); } function makeModalDialogButtons(buttonsInfo) { diff --git a/templates/main.html b/templates/main.html index bced036..25a05a7 100644 --- a/templates/main.html +++ b/templates/main.html @@ -187,6 +187,19 @@ ? + +
+ + + Disk Usage + +
+
+ +
+ + ? +
Text Overlay
@@ -436,7 +449,6 @@