def detect(self, volume_system, vstype='detect'):
        """Finds and mounts all volumes based on parted.

        :param VolumeSystem volume_system: The volume system.
        """

        # for some reason, parted does not properly return extended volume types in its machine
        # output, so we need to execute it twice.
        meta_volumes = []
        # noinspection PyBroadException
        try:
            output = _util.check_output_(['parted', volume_system.parent.get_raw_path(), 'print'], stdin=subprocess.PIPE)
            for line in output.splitlines():
                if 'extended' in line:
                    meta_volumes.append(int(line.split()[0]))
        except Exception:
            logger.exception("Failed executing parted command.")
            # skip detection of meta volumes

        # noinspection PyBroadException
        try:
            # parted does not support passing in the vstype. It either works, or it doesn't.
            cmd = ['parted', volume_system.parent.get_raw_path(), '-sm', 'unit s', 'print free']
            output = _util.check_output_(cmd, stdin=subprocess.PIPE)
            volume_system.volume_source = 'multi'
        except Exception as e:
            logger.exception("Failed executing parted command")
            raise SubsystemError(e)

        num = 0
        for line in output.splitlines():
            if line.startswith("Warning") or not line or ':' not in line or line.startswith(self.parent.get_raw_path()):
                continue
            line = line[:-1]  # remove last ;
            try:
                slot, start, end, length, description = line.split(':', 4)
                if ':' in description:
                    description, label, flags = description.split(':', 2)
                else:
                    description, label, flags = description, '', ''

                try:
                    slot = int(slot)
                except ValueError:
                    continue

                volume = volume_system._make_subvolume(
                    index=self._format_index(volume_system, num),
                    offset=int(start[:-1]) * volume_system.disk.block_size,  # remove last s
                    size=int(length[:-1]) * volume_system.disk.block_size)
                volume.info['fsdescription'] = description
                if label:
                    volume.info['label'] = label
                if flags:
                    volume.info['parted_flags'] = flags

                # TODO: detection of meta volumes

                if description == 'free':
                    volume.flag = 'unalloc'
                    logger.info("Found unallocated space: block offset: {0}, length: {1}".format(start[:-1],
                                                                                                 length[:-1]))
                elif slot in meta_volumes:
                    volume.flag = 'meta'
                    volume.slot = slot
                    logger.info("Found meta volume: block offset: {0}, length: {1}".format(start[:-1], length[:-1]))
                else:
                    volume.flag = 'alloc'
                    volume.slot = slot
                    volume_system._assign_disktype_data(volume)
                    logger.info("Found allocated {2}: block offset: {0}, length: {1} "
                                .format(start[:-1], length[:-1], volume.info['fsdescription']))
            except AttributeError:
                logger.exception("Error while parsing parted output")
                continue

            num += 1

            yield volume
def detect ( self , volume_system , vstype = 'detect' ) : meta_volumes = [ ] try : output = _util . check_output_ ( [ 'parted' , volume_system . parent . get_raw_path ( ) , 'print' ] , stdin = subprocess . PIPE ) for line in output . splitlines ( ) : if 'extended' in line : meta_volumes . append ( int ( line . split ( ) [ 0 ] ) ) except Exception : logger . exception ( "Failed executing parted command." ) try : cmd = [ 'parted' , volume_system . parent . get_raw_path ( ) , '-sm' , 'unit s' , 'print free' ] output = _util . check_output_ ( cmd , stdin = subprocess . PIPE ) volume_system . volume_source = 'multi' except Exception as e : logger . exception ( "Failed executing parted command" ) raise SubsystemError ( e ) num = 0 for line in output . splitlines ( ) : if line . startswith ( "Warning" ) or not line or ':' not in line or line . startswith ( self . parent . get_raw_path ( ) ) : continue line = line [ : - 1 ] try : slot , start , end , length , description = line . split ( ':' , 4 ) if ':' in description : description , label , flags = description . split ( ':' , 2 ) else : description , label , flags = description , '' , '' try : slot = int ( slot ) except ValueError : continue volume = volume_system . _make_subvolume ( index = self . _format_index ( volume_system , num ) , offset = int ( start [ : - 1 ] ) * volume_system . disk . block_size , size = int ( length [ : - 1 ] ) * volume_system . disk . block_size ) volume . info [ 'fsdescription' ] = description if label : volume . info [ 'label' ] = label if flags : volume . info [ 'parted_flags' ] = flags if description == 'free' : volume . flag = 'unalloc' logger . info ( "Found unallocated space: block offset: {0}, length: {1}" . format ( start [ : - 1 ] , length [ : - 1 ] ) ) elif slot in meta_volumes : volume . flag = 'meta' volume . slot = slot logger . info ( "Found meta volume: block offset: {0}, length: {1}" . format ( start [ : - 1 ] , length [ : - 1 ] ) ) else : volume . flag = 'alloc' volume . slot = slot volume_system . _assign_disktype_data ( volume ) logger . info ( "Found allocated {2}: block offset: {0}, length: {1} " . format ( start [ : - 1 ] , length [ : - 1 ] , volume . info [ 'fsdescription' ] ) ) except AttributeError : logger . exception ( "Error while parsing parted output" ) continue num += 1 yield volume
Finds and mounts all volumes based on parted.

        :param VolumeSystem volume_system: The volume system.