Skip to content
Permalink
Browse files

Cache various things that will never change for a device after the da…

…ta/info has been fetched.

Signed-off-by: Volker Theile <votdev@gmx.de>
  • Loading branch information...
votdev committed Nov 8, 2019
1 parent 6326014 commit 3b931346f1ae36c8adcb3770e44ca585e3084c59
@@ -18,13 +18,16 @@
#
# You should have received a copy of the GNU General Public License
# along with OpenMediaVault. If not, see <http://www.gnu.org/licenses/>.
import functools
import re

from .block import BlockDevice

import openmediavault.string


class StorageDevice(BlockDevice):
@functools.lru_cache()
def get_model(self):
"""
Get the device model.
@@ -35,6 +38,7 @@ def get_model(self):
self.get_udev_property('ID_MODEL_ENC', '')
)

@functools.lru_cache()
def get_vendor(self):
"""
Get the device vendor.
@@ -45,6 +49,7 @@ def get_vendor(self):
self.get_udev_property('ID_VENDOR_ENC', '')
)

@functools.lru_cache()
def get_serial(self):
"""
Get the device serial number.
@@ -54,6 +59,7 @@ def get_serial(self):
serial = self.get_udev_property('ID_SERIAL_SHORT', '')
return serial.replace('_', ' ')

@functools.lru_cache()
def is_rotational(self):
"""
Check if the device is of rotational or non-rotational type.
@@ -81,6 +87,7 @@ def is_rotational(self):
# Use heuristic.
return 'SSD' not in self.get_model()

@functools.lru_cache()
def is_removable(self):
"""
Check if the device is removable.
@@ -96,6 +103,7 @@ def is_removable(self):
pass
return False

@functools.lru_cache()
def is_usb(self):
"""
Check if the given device is an USB device.

0 comments on commit 3b93134

Please sign in to comment.
You can’t perform that action at this time.