[Folders] Differentiate permission issue and non-existence of a directory (issue #828)

This commit is contained in:
nicolargo 2016-03-28 20:56:44 +02:00
parent fd2c2f28e8
commit ee471b9dd7
7 changed files with 20 additions and 10 deletions

6
NEWS
View File

@ -5,9 +5,13 @@ Glances Version 2
Version 2.7
===========
Enhancements and new features:
* [Folders] Differentiate permission issue and non-existence of a directory #828
Bugs corrected:
* Crash on launch when viewing temperature of laptop HDD in sleep mode (issue #824)
* Crash on launch when viewing temperature of laptop HDD in sleep mode (issue #824)
* [Web UI] Fix folders plugin never displayed (issue #829)
Version 2.6.1

View File

@ -101,7 +101,7 @@ critical=90
# Allow additional file system types (comma-separated FS type)
#allow=zfs
#[folders]
[folders]
# Define a folder list to monitor
# The list is composed of items (list_#nb <= 10)
# An item is defined by:
@ -117,6 +117,7 @@ critical=90
#folder_2_warning=17000
#folder_2_critical=20000
#folder_3_path=/nonexisting
#folder_4_path=/root
[sensors]
# Sensors core thresholds (in Celsius...)

View File

@ -8,7 +8,7 @@ monitor size of a predefined folders list.
.. image:: ../_static/folders.png
If the size can not be computed (non existing folder, read right error), a '?' is displayed.
If the size can not be computed, a '?' (non existing folder) or a '!' (read right error) is displayed.
Each item is defined by:

View File

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "GLANCES" "1" "March 26, 2016" "2.6.1" "Glances"
.TH "GLANCES" "1" "March 28, 2016" "2.7_BETA" "Glances"
.SH NAME
glances \- An eye on your system
.

View File

@ -154,8 +154,12 @@ class FolderList(object):
try:
self.__folder_list[i]['size'] = self.__folder_size(self.path(i))
except Exception as e:
self.__folder_list[i]['size'] = None
logger.debug('Can get folder size ({0}). Error: {1}'.format(self.path(i), e))
if e.errno == 13:
# Permission denied
self.__folder_list[i]['size'] = '!'
else:
self.__folder_list[i]['size'] = '?'
return self.__folder_list

View File

@ -2,7 +2,7 @@
#
# This file is part of Glances.
#
# Copyright (C) 2015 Nicolargo <nicolas@nicolargo.com>
# Copyright (C) 2016 Nicolargo <nicolas@nicolargo.com>
#
# Glances is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
@ -19,6 +19,8 @@
"""Folder plugin."""
import numbers
from glances.folder_list import FolderList as glancesFolderList
from glances.plugins.glances_plugin import GlancesPlugin
@ -74,7 +76,7 @@ class Plugin(GlancesPlugin):
def get_alert(self, stat):
"""Manage limits of the folder list"""
if stat['size'] is None:
if not isinstance(stat['size'], numbers.Number):
return 'DEFAULT'
else:
ret = 'OK'
@ -114,8 +116,8 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg))
try:
msg = '{0:>6}'.format(self.auto_unit(i['size']))
except TypeError:
msg = '{0:>6}'.format('?')
except (TypeError, ValueError):
msg = '{0:>6}'.format(i['size'])
ret.append(self.curse_add_line(msg, self.get_alert(i)))
return ret

View File

@ -21,7 +21,6 @@
import os
import socket
import numbers
from glances.compat import nativestr, range
from glances.logger import logger