コード例 #1
0
ファイル: __init__.py プロジェクト: Sedl/servus
 def mount_all(self):
     # filter out already mounted partitions
     parts = [part for part in self._partitions
         if part.mountpoint and not part.mountdir]
     # sort for mounting in the right order
     parts = sorted(
         parts,
         key=lambda k: tools.get_subdir_count(k.mountpoint))
     if not len(parts):
         # nothing to do here
         return
     if not self._mount_temp:
         self._mount_temp = tempfile.mkdtemp(prefix='servus_mount_')
     for part in parts:
         npath = os.path.join(
             self._mount_temp,
             part.mountpoint.strip(os.sep))
         if not os.path.exists(npath):
             os.makedirs(npath)
         elif not os.path.isdir(npath):
             raise exc.MountError(
                 'Can\'t create mount directory "%s" because a '\
                 'file with the same name already exists.')
         LOG.info('Mounting "%s" to "%s"' % (part.devpath, npath))
         blktools.mount(part.devpath, npath)
コード例 #2
0
ファイル: blktools.py プロジェクト: Sedl/servus
def unmount_all(targdir):
    '''Unmounts all mounted partitions in the given directory including the
    directory itself.

    :param str targdir: target directory to unmount
    '''
    mounts = [mnt for mnt in get_mounts() if mnt[1].startswith(targdir)]
    # sort for unmounting in the right order
    mounts = sorted(mounts, key=lambda k: tools.get_subdir_count(k[1]), reverse=True)
    for mnt in mounts:
        LOG.info('Unmounting \'%s\' (%s)' % (mnt[0], mnt[1]))
        retcode = call_umount(mnt[1])
        if not retcode == 0:
            retcode = call_umount(mnt[1], lazy=True)
        if not retcode == 0:
            raise exc.MountError('Unmounting for \'%s\' failed with exit '\
                'code %d' % (mnt[1], retcode))