[rhinstaller/blivet/pulls/47 master] Dynamic mountpoint detection

mulkieran installerbot-noreply at redhat.com
Wed Mar 18 14:11:44 UTC 2015


> @@ -0,0 +1,137 @@
> +# mounts.py
> +# Active mountpoints cache.
> +#
> +# Copyright (C) 2015  Red Hat, Inc.
> +#
> +# This copyrighted material is made available to anyone wishing to use,
> +# modify, copy, or redistribute it subject to the terms and conditions of
> +# the GNU General Public License v.2, or (at your option) any later version.
> +# This program is distributed in the hope that it will be useful, but WITHOUT
> +# ANY WARRANTY expressed or implied, including the implied warranties of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
> +# Public License for more details.  You should have received a copy of the
> +# GNU General Public License along with this program; if not, write to the
> +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> +# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
> +# source code or documentation are not subject to the GNU General Public
> +# License and may only be used or replicated with the express permission of
> +# Red Hat, Inc.
> +#
> +# Red Hat Author(s): Vojtech Trefny <vtrefny at redhat.com>
> +#
> +
> +from . import util
> +
> +import logging
> +log = logging.getLogger("blivet")
> +
> +class MountsCache(object):
> +
> +    def __init__(self):
> +        self.mountsHash = 0
> +        self.mountpoints = {}
> +
> +        # new device manually added to cache since last check
> +        self.newDevice = False
> +
> +    def add(self, devspec, subvolspec=None):
> +        """ Add device to cache
> +
> +            :param devscpec: device specification, eg. "/dev/vda1"
> +            :type devspec: str
> +            :param subvolspec: btrfs subvolume specification, eg. ID or name
> +            :type subvolspec: str
> +
> +        """
> +
> +        self.mountpoints[(devspec, subvolspec)] = None
> +        self.newDevice = True
> +
> +    def remove(self, devspec, subvolspec=None):
> +        """ Remove device from cache
> +
> +            :param devscpec: device specification, eg. "/dev/vda1"
> +            :type devspec: str
> +            :param subvolspec: btrfs subvolume specification, eg. ID or name
> +            :type subvolspec: str
> +
> +        """
> +
> +        if (devspec, subvolspec) in self.mountpoints:
> +            del self.mountpoints[(devspec, subvolspec)]
> +
> +    def clear(self):
> +        """ Clear cache
> +        """
> +
> +        for key in self.mountpoints.keys():
> +            self.mountpoints[key] = None
> +
> +        self._getActiveMounts()
> +
> +    def getMountpoint(self, devspec, subvolspec=None):
> +        """ Get mountpoint for selected device
> +
> +            :param devscpec: device specification, eg. "/dev/vda1"
> +            :type devspec: str
> +            :param subvolspec: btrfs subvolume specification, eg. ID or name
> +            :type subvolspec: str
> +            :returns: mountpoint (path)
> +            :rtype: str
> +
> +        """
> +
> +        self._cacheCheck()
> +
> +        if (devspec, subvolspec) not in self.mountpoints.keys():
> +            return None
> +
> +        else:
> +            return self.mountpoints[(devspec, subvolspec)]

```
return self.mountpoints.get((devspec, subvolspec))
```
can replace the if statement entirely.

-- 
To view this pull request on github, visit https://github.com/rhinstaller/blivet/pull/47#discussion_r26665559


More information about the anaconda-patches mailing list