From e3f10be918dc266847131192f123d2087581cd9e Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Thu, 14 Nov 2013 15:33:50 +0200 Subject: [PATCH] target dir is now created if it doesn't exist upon saving the settings --- doc/todo.txt | 2 ++ src/config.py | 16 ++++++++++++++-- static/js/main.js | 5 ++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/todo.txt b/doc/todo.txt index ca23fec..0b11b32 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,4 +1,6 @@ -> add support for picture resizing +-> add a loading progress for media previews +-> add a pager for media files -> add a download option in media list -> add a previewer for movies -> make camera frames positions configurable diff --git a/src/config.py b/src/config.py index 657ba3a..d53d77f 100644 --- a/src/config.py +++ b/src/config.py @@ -250,12 +250,19 @@ def set_camera(camera_id, data): elif not data['@enabled']: threads = [t for t in threads if t != config_file_name] - + main_config['thread'] = threads data['@id'] = camera_id set_main(main_config) + + # try to create the target_dir + try: + os.makedirs(data['target_dir']) + + except Exception as e: + logging.warn('failed to create target directory: %(msg)s' % {'msg': unicode(e)}) # read the actual configuration from file config_file_path = _CAMERA_CONFIG_FILE_PATH % {'id': camera_id} @@ -561,7 +568,12 @@ def camera_ui_to_dict(ui): 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']) + usage = utils.get_disk_usage(data['target_dir']) + if usage: + disk_used, disk_total = usage + + else: + disk_used, disk_total = 0, 0 else: device_uri = '%(host)s:%(port)s/config/%(camera_id)s' % { diff --git a/static/js/main.js b/static/js/main.js index e58c674..2973190 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -621,7 +621,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']); + var percent = 0; + if (dict['disk_total'] != 0) { + 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 + '%)'); -- 2.39.5