/
storage.py
45 lines (39 loc) · 1.44 KB
/
storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# vim:sw=4:ts=4:et
class Storage(object):
@property
def storage_device_info(self):
ret = self.command(
'storageDevice.cgi?action=getDeviceAllInfo'
)
return ret.content.decode('utf-8')
@property
def storage_device_names(self):
ret = self.command(
'storageDevice.cgi?action=factory.getCollect'
)
return ret.content.decode('utf-8')
@property
def storage_used(self, dev='/dev/mmc0', unit='GB'):
ret = self.storage_device_info
# TODO
# Use regex to enhance the filter
status = [s for s in ret.split() if '.UsedBytes=' in s][0]
return self.to_unit(status.split('=')[-1], unit)
@property
def storage_total(self, dev='/dev/mmc0', unit='GB'):
ret = self.storage_device_info
# TODO
# Use regex to enhance the filter
status = [s for s in ret.split() if '.TotalBytes=' in s][0]
return self.to_unit(status.split('=')[-1], unit)