def detect(self, volume_system, vstype='detect'):
        """'Detects' a single volume. It should not be called other than from a :class:`Disk`."""
        volume = volume_system._make_single_subvolume(offset=0)
        is_directory = os.path.isdir(volume_system.parent.get_raw_path())

        if is_directory:
            filesize = _util.check_output_(['du', '-scDb', volume_system.parent.get_raw_path()]).strip()
            if filesize:
                volume.size = int(filesize.splitlines()[-1].split()[0])

        else:
            description = _util.check_output_(['file', '-sL', volume_system.parent.get_raw_path()]).strip()
            if description:
                # description is the part after the :, until the first comma
                volume.info['fsdescription'] = description.split(': ', 1)[1].split(',', 1)[0].strip()
                if 'size' in description:
                    volume.size = int(re.findall(r'size:? (\d+)', description)[0])
                else:
                    volume.size = os.path.getsize(volume_system.parent.get_raw_path())

        volume.flag = 'alloc'
        volume_system.volume_source = 'single'
        volume_system._assign_disktype_data(volume)
        yield volume
def detect ( self , volume_system , vstype = 'detect' ) : volume = volume_system . _make_single_subvolume ( offset = 0 ) is_directory = os . path . isdir ( volume_system . parent . get_raw_path ( ) ) if is_directory : filesize = _util . check_output_ ( [ 'du' , '-scDb' , volume_system . parent . get_raw_path ( ) ] ) . strip ( ) if filesize : volume . size = int ( filesize . splitlines ( ) [ - 1 ] . split ( ) [ 0 ] ) else : description = _util . check_output_ ( [ 'file' , '-sL' , volume_system . parent . get_raw_path ( ) ] ) . strip ( ) if description : volume . info [ 'fsdescription' ] = description . split ( ': ' , 1 ) [ 1 ] . split ( ',' , 1 ) [ 0 ] . strip ( ) if 'size' in description : volume . size = int ( re . findall ( r'size:? (\d+)' , description ) [ 0 ] ) else : volume . size = os . path . getsize ( volume_system . parent . get_raw_path ( ) ) volume . flag = 'alloc' volume_system . volume_source = 'single' volume_system . _assign_disktype_data ( volume ) yield volume
Detects' a single volume. It should not be called other than from a :class:`Disk`.