检查python中的空闲分区空间

时间:2015-11-17 02:13:27

标签: python raspberry-pi raspberry-pi2

好吧,我在我的覆盆子pi上有一个chron工作,每15分钟拍一张照片,现在我想用我的Piglow板来表示分区中剩余的图片存储空间。所以我想要一个python脚本来检查分区上有多少空间以及使用了多少空间,然后将总空间使用的数量除以并根据它来点亮LED。除了获取分区信息外,我知道如何做所有事情。

1 个答案:

答案 0 :(得分:0)

>>> mnt = commands.getoutput("cat /proc/partitions")
>>> print mnt
major minor  #blocks  name

   3     0   19551168 hda
   3     1    6345675 hda1
   3     2   13205398 hda2
   3    64   19551168 hdb
   3    66          1 hdb2
   3    69     835348 hdb5
   3    70    9767425 hdb6
   3    71     192748 hdb7
   3    72    8755393 hdb8
  34     0   19551168 hdg
  34     1   19542568 hdg1
   8     0     992000 sda
   8     1     991747 sda1



import re
import commands

def get_size(device):
    '''
    Input  : Device name.
    Output : The devices size in 512-byte blocks.
    '''
    return commands.getoutput(
        'cat /sys/class/block/{}/size'.format(
        device))


print get_size('sda1')