si.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:Starfish 作者: BillWang139967 项目源码 文件源码
def partinfo(self, uuid=None, devname=None):
        """Read partition info including uuid and filesystem.

        You can specify uuid or devname to get the identified partition info.
        If no argument provided, all partitions will return.

        We read info from /etc/blkid/blkid.tab instead of call blkid command.
        REF: http://linuxconfig.org/how-to-retrieve-and-change-partitions-universally-unique-identifier-uuid-on-linux
        """
        blks = {}
        p = subprocess.Popen(shlex.split('/sbin/blkid'), stdout=subprocess.PIPE, close_fds=True)
        p.stdout.read()
        p.wait()

        # OpenVZ may not have this file
        if not os.path.exists('/etc/blkid/blkid.tab'): return None

        with open('/etc/blkid/blkid.tab') as f:
            for line in f:
                dom = parseString(line).documentElement
                _fstype = dom.getAttribute('TYPE')
                _uuid = dom.getAttribute('UUID')
                _devname = dom.firstChild.nodeValue.replace('/dev/', '')
                partinfo = {
                    'name': _devname,
                    'fstype': _fstype,
                    'uuid': _uuid,
                }
                if uuid and uuid == _uuid:
                    return partinfo
                elif devname and devname == _devname:
                    return partinfo
                else:
                    blks[_devname] = partinfo
        if uuid or devname:
            return None
        else:
            return blks
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号