Exemplo n.º 1
0
class OSXMountPoint(MountPoint):
    """
    One OS/X mountpoint parsed from /sbin/mount output

    Extra attributes:
    hfspath     Returns OS/X 'hfs path' or None
    """
    def __init__(self, mountpoint, device=None, filesystem=None):
        MountPoint.__init__(self, device, mountpoint, filesystem)
        try:
            self.hfspath = Alias(self.mountpoint).hfspath
        except ValueError:
            self.hfspath = None
        self.update_diskinfo()

    def update_diskinfo(self):
        if os.access(self.device, os.R_OK):
            self.diskinfo = DiskInfo(self.device)
        else:
            self.diskinfo = {}

    @property
    def name(self):
        return self.diskinfo.has_key(
            'VolumeName') and self.diskinfo['VolumeName'] or os.path.basename(
                self.mountpoint)

    @property
    def size(self):
        try:
            return self.usage['size']
        except KeyError:
            return 0

    @property
    def used(self):
        try:
            return self.usage['used']
        except KeyError:
            return 0

    @property
    def available(self):
        try:
            return self.usage['available']
        except KeyError:
            return 0

    @property
    def percent(self):
        try:
            return self.usage['percent']
        except KeyError:
            return 0

    @property
    def writable(self):
        return self.diskinfo.has_key(
            'Writable') and self.diskinfo['Writable'] or False

    @property
    def writable(self):
        return self.diskinfo.has_key(
            'Writable') and self.diskinfo['Writable'] or False

    @property
    def bootable(self):
        return self.diskinfo.has_key(
            'Bootable') and self.diskinfo['Bootable'] or False

    @property
    def internal(self):
        return self.diskinfo.has_key(
            'Internal') and self.diskinfo['Internal'] or False

    @property
    def ejectable(self):
        return self.diskinfo.has_key(
            'Ejectable') and self.diskinfo['Ejectable'] or True

    @property
    def removable(self):
        return self.diskinfo.has_key(
            'Removable') and self.diskinfo['Removable'] or False

    @property
    def blocksize(self):
        return self.diskinfo.has_key(
            'DeviceBlockSize') and self.diskinfo['DeviceBlockSize'] or 0

    @property
    def usage(self):
        """
        Check usage percentage for this mountpoint.
        Returns dictionary with usage details.
        """
        try:
            output = check_output(['df', '-k', self.mountpoint])
        except CalledProcessError, e:
            raise FileSystemError('Error checking filesystem usage: %s' % e)
        (header, usage) = output.split('\n', 1)

        m = re_df.match(usage)
        if not m:
            raise FileSystemError('Error matching df output line: %s' % usage)
        return {
            'mountpoint': self.mountpoint,
            'size': long(m.group(2)),
            'used': long(m.group(3)),
            'free': long(m.group(4)),
            'percent': int(m.group(5))
        }
Exemplo n.º 2
0
class OSXMountPoint(MountPoint):
    """
    One OS/X mountpoint parsed from /sbin/mount output

    Extra attributes:
    hfspath     Returns OS/X 'hfs path' or None
    """
    def __init__(self,mountpoint,device=None,filesystem=None):
        MountPoint.__init__(self,device,mountpoint,filesystem)
        try:
            self.hfspath = Alias(self.mountpoint).hfspath
        except ValueError:
            self.hfspath = None
        self.update_diskinfo()

    def update_diskinfo(self):
        if os.access(self.device,os.R_OK):
            self.diskinfo = DiskInfo(self.device)
        else:
            self.diskinfo = {}

    @property
    def name(self):
        return self.diskinfo.has_key('VolumeName') and self.diskinfo['VolumeName'] or os.path.basename(self.mountpoint)

    @property
    def size(self):
        try:
            return self.usage['size']
        except KeyError:
            return 0

    @property
    def used(self):
        try:
            return self.usage['used']
        except KeyError:
            return 0

    @property
    def available(self):
        try:
            return self.usage['available']
        except KeyError:
            return 0

    @property
    def percent(self):
        try:
            return self.usage['percent']
        except KeyError:
            return 0

    @property
    def writable(self):
        return self.diskinfo.has_key('Writable') and  self.diskinfo['Writable'] or False

    @property
    def writable(self):
        return self.diskinfo.has_key('Writable') and  self.diskinfo['Writable'] or False

    @property
    def bootable(self):
        return self.diskinfo.has_key('Bootable') and  self.diskinfo['Bootable'] or False

    @property
    def internal(self):
        return self.diskinfo.has_key('Internal') and  self.diskinfo['Internal'] or False

    @property
    def ejectable(self):
        return self.diskinfo.has_key('Ejectable') and  self.diskinfo['Ejectable'] or True

    @property
    def removable(self):
        return self.diskinfo.has_key('Removable') and  self.diskinfo['Removable'] or False

    @property
    def blocksize(self):
        return self.diskinfo.has_key('DeviceBlockSize') and  self.diskinfo['DeviceBlockSize'] or 0

    @property
    def usage(self):
        """
        Check usage percentage for this mountpoint.
        Returns dictionary with usage details.
        """
        try:
            output = check_output(['df','-k',self.mountpoint])
        except CalledProcessError,e:
            raise FileSystemError('Error checking filesystem usage: %s' % e)
        (header,usage) = output.split('\n',1)

        m = re_df.match(usage)
        if not m:
            raise FileSystemError('Error matching df output line: %s' % usage)
        return {
            'mountpoint': self.mountpoint,
            'size': long(m.group(2)),
            'used': long(m.group(3)),
            'free': long(m.group(4)),
            'percent': int(m.group(5))
        }