Python shutil.disk_usage() Examples

The following are 30 code examples of shutil.disk_usage(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module shutil , or try the search function .
Example #1
Source Project: meshed-memory-transformer   Author: aimagelab   File: field.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, preprocessing=None, postprocessing=None, detections_path=None, max_detections=100,
                 sort_by_prob=False, load_in_tmp=True):
        self.max_detections = max_detections
        self.detections_path = detections_path
        self.sort_by_prob = sort_by_prob

        tmp_detections_path = os.path.join('/tmp', os.path.basename(detections_path))

        if load_in_tmp:
            if not os.path.isfile(tmp_detections_path):
                if shutil.disk_usage("/tmp")[-1] < os.path.getsize(detections_path):
                    warnings.warn('Loading from %s, because /tmp has no enough space.' % detections_path)
                else:
                    warnings.warn("Copying detection file to /tmp")
                    shutil.copyfile(detections_path, tmp_detections_path)
                    warnings.warn("Done.")
                    self.detections_path = tmp_detections_path
            else:
                self.detections_path = tmp_detections_path

        super(ImageDetectionsField, self).__init__(preprocessing, postprocessing) 
Example #2
Source Project: psutil   Author: giampaolo   File: test_system.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_disk_usage(self):
        usage = psutil.disk_usage(os.getcwd())
        self.assertEqual(usage._fields, ('total', 'used', 'free', 'percent'))

        assert usage.total > 0, usage
        assert usage.used > 0, usage
        assert usage.free > 0, usage
        assert usage.total > usage.used, usage
        assert usage.total > usage.free, usage
        assert 0 <= usage.percent <= 100, usage.percent
        if hasattr(shutil, 'disk_usage'):
            # py >= 3.3, see: http://bugs.python.org/issue12442
            shutil_usage = shutil.disk_usage(os.getcwd())
            tolerance = 5 * 1024 * 1024  # 5MB
            self.assertEqual(usage.total, shutil_usage.total)
            self.assertAlmostEqual(usage.free, shutil_usage.free,
                                   delta=tolerance)
            self.assertAlmostEqual(usage.used, shutil_usage.used,
                                   delta=tolerance)

        # if path does not exist OSError ENOENT is expected across
        # all platforms
        fname = self.get_testfn()
        with self.assertRaises(FileNotFoundError):
            psutil.disk_usage(fname) 
Example #3
Source Project: cot   Author: glennmatthews   File: utilities.py    License: MIT License 6 votes vote down vote up
def available_bytes_at_path(path):
    """Get the available disk space in a given directory.

    Args:
      path (str): Directory path to check.

    Returns:
      int: Available space, in bytes

    Raises:
      OSError: if the specified path does not exist or is not readable.
    """
    if not os.path.exists(path):
        raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), path)
    if not os.path.isdir(path):
        raise OSError(errno.ENOTDIR, os.strerror(errno.ENOTDIR), path)
    available = disk_usage(path).free
    logger.debug("There appears to be %s available at %s",
                 pretty_bytes(available), path)
    return available 
Example #4
Source Project: aws-iot-analytics-notebook-containers   Author: awslabs   File: kernel_image_creator.py    License: Apache License 2.0 6 votes vote down vote up
def _get_message_if_space_insufficient(cls, paths_to_copy):
        INSUFFIENT_SPACE_ERROR_FMT = "There is insufficient space remaining on this instance to " + \
        "containerize this notebook. Containerization would require {} of additional space."

        files_to_copy_bytes = cls._get_total_size_of_files(paths_to_copy)
        _, _, free_space_bytes = shutil.disk_usage("/")

        required_bytes = int(cls.REQUIRED_SPACE_PER_FILES_SPACE * files_to_copy_bytes
            ) + cls.SPACE_REQUIREMENT_FUDGE_BYTES

        if required_bytes > free_space_bytes:
            cls.logger.info("Insufficient space to containerize. Has {} bytes, requires {} bytes, " +
                "with fudge space requires {} bytes.".format(
                    free_space_bytes, files_to_copy_bytes, required_bytes))

            additional_required_bytes = required_bytes - free_space_bytes
            human_readable_additional_space_required = size(required_bytes - free_space_bytes)
            return INSUFFIENT_SPACE_ERROR_FMT.format("{} bytes ({})".format(
                additional_required_bytes, human_readable_additional_space_required)) 
Example #5
Source Project: dcos-e2e   Author: dcos   File: doctor.py    License: Apache License 2.0 6 votes vote down vote up
def _check_tmp_free_space() -> CheckLevels:
    """
    Warn if there is not enough free space in the default temporary directory.
    """
    free_space = shutil.disk_usage(gettempdir()).free
    free_space_gb = free_space / 1024 / 1024 / 1024

    low_space_message = (
        'The default temporary directory ("{tmp_prefix}") has '
        '{free_space:.1f} GB of free space available. '
        'Creating a cluster typically takes approximately 2 GB of temporary '
        'storage. '
        'If you encounter problems with disk space usage, set the ``TMPDIR`` '
        'environment variable to a suitable temporary directory or use the '
        '``--workspace-dir`` option on the ``minidcos docker create`` command.'
    ).format(
        tmp_prefix=Path('/') / gettempprefix(),
        free_space=free_space_gb,
    )

    if free_space_gb < 5:
        warn(message=low_space_message)
        return CheckLevels.WARNING

    return CheckLevels.NONE 
Example #6
Source Project: Carnets   Author: holzschu   File: data.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_free_space_in_dir(path):
    """
    Given a path to a directory, returns the amount of free space (in
    bytes) on that filesystem.

    Parameters
    ----------
    path : str
        The path to a directory

    Returns
    -------
    bytes : int
        The amount of free space on the partition that the directory
        is on.
    """
    if not os.path.isdir(path):
        raise OSError(
            "Can only determine free space associated with directories, "
            "not files.")
        # Actually you can on Linux but I want to avoid code that fails
        # on Windows only.
    return shutil.disk_usage(path).free 
Example #7
Source Project: multibootusb   Author: mbusb   File: usb.py    License: GNU General Public License v2.0 5 votes vote down vote up
def disk_usage(mount_path):
    """
    Return disk usage statistics about the given path as a (total, used, free)
    namedtuple.  Values are expressed in bytes.
    """
    # Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
    # License: MIT
    _ntuple_diskusage = collections.namedtuple('usage', 'total used free')

    if platform.system() == "Linux":
        st = os.statvfs(mount_path)
        free = st.f_bavail * st.f_frsize
        total = st.f_blocks * st.f_frsize
        used = (st.f_blocks - st.f_bfree) * st.f_frsize

        return _ntuple_diskusage(total, used, free)

    elif platform.system() == "Windows":

        _, total, free = ctypes.c_ulonglong(), ctypes.c_ulonglong(), \
                         ctypes.c_ulonglong()
        if sys.version_info >= (3,) or isinstance(mount_path, unicode):
            fun = ctypes.windll.kernel32.GetDiskFreeSpaceExW
        else:
            fun = ctypes.windll.kernel32.GetDiskFreeSpaceExA
        ret = fun(mount_path, ctypes.byref(_), ctypes.byref(total), ctypes.byref(free))
        if ret == 0:
            raise ctypes.WinError()
        used = total.value - free.value

        return _ntuple_diskusage(total.value, used, free.value)
    else:
        raise NotImplementedError("Platform not supported.") 
Example #8
Source Project: speaksee   Author: aimagelab   File: field.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, preprocessing=None, postprocessing=None, detections_path=None, max_detections=100,
                 sort_by_prob=False, load_in_tmp=True):
        self.max_detections = max_detections
        self.detections_path = detections_path
        self.sort_by_prob = sort_by_prob

        tmp_detections_path = os.path.join('/tmp', os.path.basename(detections_path))

        if load_in_tmp:
            if not os.path.isfile(tmp_detections_path):
                if shutil.disk_usage("/tmp")[-1] < os.path.getsize(detections_path):
                    warnings.warn('Loading from %s, because /tmp has no enough space.' % detections_path)
                else:
                    warnings.warn("Copying detection file to /tmp")
                    shutil.copyfile(detections_path, tmp_detections_path)
                    warnings.warn("Done.")
                    self.detections_path = tmp_detections_path
            else:
                self.detections_path = tmp_detections_path

        super(ImageDetectionsField, self).__init__(preprocessing, postprocessing) 
Example #9
Source Project: docker-box   Author: MicroPyramid   File: utils.py    License: MIT License 5 votes vote down vote up
def used_space(self):
        x = shutil.disk_usage('/')
        return format(x.used / 1024 / 1024 / 1024, '.2f') 
Example #10
Source Project: microk8s   Author: ubuntu   File: auxillary.py    License: Apache License 2.0 5 votes vote down vote up
def _free_space() -> int:
        """
        Get space free of disk that this script is installed to.

        :return: Integer free space
        """
        return disk_usage(realpath('/')).free 
Example #11
Source Project: orc   Author: gesiscss   File: image_cleaner.py    License: MIT License 5 votes vote down vote up
def get_available_disk_space(path_to_check):
    disk_usage = shutil.disk_usage(path_to_check)
    available = (disk_usage.free * 100) / disk_usage.total
    return available 
Example #12
Source Project: tartube   Author: axcore   File: utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def disk_get_free_space(path, bytes_flag=False):

    """Can be called by anything.

    Returns the size of the disk on which a specified file/directory exists,
    minus the used space on that disk.

    Args:

        path (str): Path to a file/directory on the disk, typically Tartube's
            data directory

        bytes_flag (bool): True to return an integer value in MB, false to
            return a value in bytes

    Returns:

        The free space in MB (or in bytes, if the flag is specified), or 0 if
            the size can't be calculated for any reason

    """

    try:
        total_bytes, used_bytes, free_bytes = shutil.disk_usage(
            os.path.realpath(path),
        )

        if not bytes_flag:
            return int(free_bytes / 1000000)
        else:
            return free_bytes

    except:
        return 0 
Example #13
Source Project: tartube   Author: axcore   File: utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def disk_get_total_space(path, bytes_flag=False):

    """Can be called by anything.

    Returns the size of the disk on which a specified file/directory exists.

    Args:

        path (str): Path to a file/directory on the disk, typically Tartube's
            data directory

        bytes_flag (bool): True to return an integer value in MB, false to
            return a value in bytes

    Returns:

        The total size in MB (or in bytes, if the flag is specified)

    """

    total_bytes, used_bytes, free_bytes = shutil.disk_usage(
        os.path.realpath(path),
    )

    if not bytes_flag:
        return int(total_bytes / 1000000)
    else:
        return total_bytes 
Example #14
Source Project: tartube   Author: axcore   File: utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def disk_get_used_space(path, bytes_flag=False):

    """Can be called by anything.

    Returns the size of the disk on which a specified file/directory exists,
    minus the free space on that disk.

    Args:

        path (str): Path to a file/directory on the disk, typically Tartube's
            data directory

        bytes_flag (bool): True to return an integer value in MB, false to
            return a value in bytes

    Returns:

        The used space in MB (or in bytes, if the flag is specified)

    """

    total_bytes, used_bytes, free_bytes = shutil.disk_usage(
        os.path.realpath(path),
    )

    if not bytes_flag:
        return int(used_bytes / 1000000)
    else:
        return used_bytes 
Example #15
Source Project: rhinobot_heroku   Author: helionmusic   File: run.py    License: MIT License 5 votes vote down vote up
def opt_check_disk_space(warnlimit_mb=200):
    if disk_usage('.').free < warnlimit_mb*1024*2:
        log.warning("Less than %sMB of free space remains on this device" % warnlimit_mb)


################################################# 
Example #16
Source Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_shutil.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_disk_usage(self):
        usage = shutil.disk_usage(os.getcwd())
        self.assertGreater(usage.total, 0)
        self.assertGreater(usage.used, 0)
        self.assertGreaterEqual(usage.free, 0)
        self.assertGreaterEqual(usage.total, usage.used)
        self.assertGreater(usage.total, usage.free) 
Example #17
Source Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_shutil.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_module_all_attribute(self):
        self.assertTrue(hasattr(shutil, '__all__'))
        target_api = ['copyfileobj', 'copyfile', 'copymode', 'copystat',
                      'copy', 'copy2', 'copytree', 'move', 'rmtree', 'Error',
                      'SpecialFileError', 'ExecError', 'make_archive',
                      'get_archive_formats', 'register_archive_format',
                      'unregister_archive_format', 'get_unpack_formats',
                      'register_unpack_format', 'unregister_unpack_format',
                      'unpack_archive', 'ignore_patterns', 'chown', 'which',
                      'get_terminal_size', 'SameFileError']
        if hasattr(os, 'statvfs') or os.name == 'nt':
            target_api.append('disk_usage')
        self.assertEqual(set(shutil.__all__), set(target_api)) 
Example #18
Source Project: python-aria-mirror-bot   Author: lzzy12   File: __main__.py    License: GNU General Public License v3.0 5 votes vote down vote up
def stats(update, context):
    currentTime = get_readable_time((time.time() - botStartTime))
    total, used, free = shutil.disk_usage('.')
    total = get_readable_file_size(total)
    used = get_readable_file_size(used)
    free = get_readable_file_size(free)
    stats = f'Bot Uptime: {currentTime}\n' \
            f'Total disk space: {total}\n' \
            f'Used: {used}\n' \
            f'Free: {free}'
    sendMessage(stats, context.bot, update) 
Example #19
Source Project: thonny   Author: thonny   File: base_file_browser.py    License: MIT License 5 votes vote down vote up
def request_fs_info(self, path):
        if path == "":
            self.notify_missing_selection()
        else:
            if not os.path.isdir(path):
                path = os.path.dirname(path)

            import shutil

            self.present_fs_info(shutil.disk_usage(path)._asdict()) 
Example #20
Source Project: dcos   Author: dcos   File: make_disk_resources.py    License: Apache License 2.0 5 votes vote down vote up
def get_disk_free(path):
    '''
    @type path: str

    @rtype tuple
    '''
    return (path, floor(float(shutil.disk_usage(path).free) / MB)) 
Example #21
Source Project: jarvis   Author: haynieresearch   File: test_system.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_disk_usage(self):
        usage = psutil.disk_usage(os.getcwd())
        self.assertEqual(usage._fields, ('total', 'used', 'free', 'percent'))

        assert usage.total > 0, usage
        assert usage.used > 0, usage
        assert usage.free > 0, usage
        assert usage.total > usage.used, usage
        assert usage.total > usage.free, usage
        assert 0 <= usage.percent <= 100, usage.percent
        if hasattr(shutil, 'disk_usage'):
            # py >= 3.3, see: http://bugs.python.org/issue12442
            shutil_usage = shutil.disk_usage(os.getcwd())
            tolerance = 5 * 1024 * 1024  # 5MB
            self.assertEqual(usage.total, shutil_usage.total)
            self.assertAlmostEqual(usage.free, shutil_usage.free,
                                   delta=tolerance)
            self.assertAlmostEqual(usage.used, shutil_usage.used,
                                   delta=tolerance)

        # if path does not exist OSError ENOENT is expected across
        # all platforms
        fname = tempfile.mktemp()
        with self.assertRaises(OSError) as exc:
            psutil.disk_usage(fname)
        self.assertEqual(exc.exception.errno, errno.ENOENT) 
Example #22
Source Project: jarvis   Author: haynieresearch   File: test_system.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_disk_usage_unicode(self):
        # See: https://github.com/giampaolo/psutil/issues/416
        if ASCII_FS:
            with self.assertRaises(UnicodeEncodeError):
                psutil.disk_usage(TESTFN_UNICODE) 
Example #23
Source Project: jarvis   Author: haynieresearch   File: test_system.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_disk_usage_bytes(self):
        psutil.disk_usage(b'.') 
Example #24
Source Project: MusicBot   Author: Just-Some-Bots   File: run.py    License: MIT License 5 votes vote down vote up
def opt_check_disk_space(warnlimit_mb=200):
    if disk_usage('.').free < warnlimit_mb*1024*2:
        log.warning("Less than %sMB of free space remains on this device" % warnlimit_mb)


################################################# 
Example #25
Source Project: catcli   Author: deadc0de6   File: noder.py    License: GNU General Public License v3.0 5 votes vote down vote up
def storage_node(self, name, path, parent, attr=None):
        '''create a new node representing a storage'''
        path = os.path.abspath(path)
        free = shutil.disk_usage(path).free
        total = shutil.disk_usage(path).total
        epoch = int(time.time())
        return anytree.AnyNode(name=name, type=self.TYPE_STORAGE, free=free,
                               total=total, parent=parent, attr=attr, ts=epoch) 
Example #26
Source Project: multibootusb   Author: mbusb   File: osdriver.py    License: GNU General Public License v2.0 4 votes vote down vote up
def wmi_get_volume_info_ex(usb_disk):
    assert platform.system() == 'Windows'
    partition, disk = wmi_get_drive_info(usb_disk)
    #print (disk.Caption, partition.StartingOffset, partition.DiskIndex,
    #       disk.FileSystem, disk.VolumeName)

    # Extract Volume serial number off of the boot sector because 
    # retrieval via COM object 'Scripting.FileSystemObject' or wmi interface
    # truncates NTFS serial number to 32 bits.
    with open('//./Physicaldrive%d'%partition.DiskIndex, 'rb') as f:
        f.seek(int(partition.StartingOffset))
        bs_ = f.read(512)
        serial_extractor = {
            'NTFS'  : lambda bs: \
            ''.join('%02X' % c for c in reversed(bs[0x48:0x48+8])),
            'FAT32' : lambda bs: \
            '%02X%02X-%02X%02X' % tuple(
                map(int,reversed(bs[67:71])))
            }.get(disk.FileSystem, lambda bs: None)
        uuid = serial_extractor(bs_)
    mount_point = usb_disk + '\\'
    size_total, size_used, size_free \
        = shutil.disk_usage(mount_point)[:3]
    r = {
        'uuid' : uuid,
        'file_system' : disk.FileSystem,
        'label' : disk.VolumeName.strip() or 'No_label',
        'mount_point' : mount_point,
        'size_total' : size_total,
        'size_used'  : size_used,
        'size_free'  : size_free,
        'vendor'     : 'Not_Found',
        'model'      : 'Not_Found',
        'devtype'    : 'partition',
        'mediatype'    : {
            0 : 'Unknown',
            1 : 'Fixed Disk',
            2 : 'Removable Disk',
            3 : 'Local Disk',
            4 : 'Network Drive',
            5 : 'Compact Disc',
            6 : 'RAM Disk',
        }.get(disk.DriveType, 'DiskType(%d)' % disk.DriveType),
        'disk_index' : partition.DiskIndex,
    }
    # print (r)
    return r 
Example #27
Source Project: multibootusb   Author: mbusb   File: usb.py    License: GNU General Public License v2.0 4 votes vote down vote up
def details_udisks2(usb_disk_part):
    """
    Get details of USB disk detail.
    usb_disk_part: It is the partition of an USB removable disk.
    """
    import dbus
    bus = dbus.SystemBus()

    mount_point = ''
    uuid = ''
    file_system = ''
    vendor = ''
    model = ''
    label = ''
    devtype = "disk"

    bd = bus.get_object('org.freedesktop.UDisks2', '/org/freedesktop/UDisks2/block_devices%s'%usb_disk_part[4:])
    device = bd.Get('org.freedesktop.UDisks2.Block', 'Device', dbus_interface='org.freedesktop.DBus.Properties')
    device = bytearray(device).replace(b'\x00', b'').decode('utf-8')
    if device[-1].isdigit() is True:
        uuid = bd.Get('org.freedesktop.UDisks2.Block', 'IdUUID', dbus_interface='org.freedesktop.DBus.Properties')
        file_system = bd.Get('org.freedesktop.UDisks2.Block', 'IdType', dbus_interface='org.freedesktop.DBus.Properties')
        mount_point = bd.Get('org.freedesktop.UDisks2.Filesystem', 'MountPoints', dbus_interface='org.freedesktop.DBus.Properties')
        devtype = 'partition'
    else:
        devtype = 'disk'
        file_system = 'No_File_System'
    if mount_point:
        # mount_point = str(bytearray(mount_point[0]).decode('utf-8').replace(b'\x00', b''))
        mount_point = bytearray(mount_point[0]).replace(b'\x00', b'').decode('utf-8')
    else:
        try:
            mount_point = UDISKS.mount(usb_disk_part)
            config.add_remounted(usb_disk_part)
        except:
            mount_point = "No_Mount"
    try:
        label = bd.Get('org.freedesktop.UDisks2.Block', 'IdLabel', dbus_interface='org.freedesktop.DBus.Properties')
    except:
        label = "No_Label"
    usb_drive_id = (bd.Get('org.freedesktop.UDisks2.Block', 'Drive', dbus_interface='org.freedesktop.DBus.Properties'))
    bd1 = bus.get_object('org.freedesktop.UDisks2', usb_drive_id)
    try:
        vendor = bd1.Get('org.freedesktop.UDisks2.Drive', 'Vendor', dbus_interface='org.freedesktop.DBus.Properties')
    except:
        vendor = str('No_Vendor')
    try:
        model = bd1.Get('org.freedesktop.UDisks2.Drive', 'Model', dbus_interface='org.freedesktop.DBus.Properties')
    except:
        model = str('No_Model')
    if not mount_point == "No_Mount":
            size_total, size_used, size_free = \
                        shutil.disk_usage(mount_point)[:3]
    else:
        raise PartitionNotMounted(usb_disk_part)

    return {'uuid': uuid, 'file_system': file_system, 'label': label, 'mount_point': mount_point,
            'size_total': size_total, 'size_used': size_used, 'size_free': size_free,
            'vendor': vendor, 'model': model, 'devtype': devtype} 
Example #28
Source Project: multibootusb   Author: mbusb   File: install.py    License: GNU General Public License v2.0 4 votes vote down vote up
def install_progress():
    """
    Function to calculate progress percentage of install.
    :return:
    """
    from . import progressbar
    try:
        usb_details = details(config.usb_disk)
    except PartitionNotMounted as e:
        log(str(e))
        return

    config.usb_mount = usb_details['mount_point']
    usb_size_used = usb_details['size_used']
    thrd = threading.Thread(target=install_distro, name="install_progress")
    # thrd.daemon()
    # install_size = usb_size_used / 1024
#     install_size = iso_size(config.image_path) / 1024
    final_size = (usb_size_used + iso_size(config.image_path)) + config.persistence
    thrd.start()
    pbar = progressbar.ProgressBar(maxval=100).start()  # bar = progressbar.ProgressBar(redirect_stdout=True)
    while thrd.is_alive():
        current_size = shutil.disk_usage(usb_details['mount_point'])[1]
        percentage = int((current_size / final_size) * 100)
        if percentage > 100:
            percentage = 100
        config.percentage = percentage
        pbar.update(percentage)
        time.sleep(0.1) 
Example #29
Source Project: gpt   Author: encarsia   File: modules.py    License: GNU General Public License v3.0 4 votes vote down vote up
def discspace_info(self):
        """Save memory information about disc and card in list
           [total,used,free], use values to display levelbar and label element below"""

        self.disc_space = [shutil.disk_usage(cli.stdir).total,
                           shutil.disk_usage(cli.stdir).used,
                           shutil.disk_usage(cli.stdir).free,
                           ]
        if cli.detectcard():
            self.card_space = [shutil.disk_usage(cli.cardpath).total,
                               shutil.disk_usage(cli.cardpath).used,
                               shutil.disk_usage(cli.cardpath).free,
                               True,
                               ]
        else:
            self.card_space = [1, 0, 0, False]

        self.disc_bar = self.obj("level_wdir")
        self.card_bar = self.obj("level_sd")

        self.disc_bar.add_offset_value("lower", 0.5)
        self.disc_bar.add_offset_value("low", 0.7)
        self.disc_bar.add_offset_value("high", 0.9)

        self.card_bar.add_offset_value("lower", 0.4)
        self.card_bar.add_offset_value("low", 0.7)
        self.card_bar.add_offset_value("high", 0.9)

        self.disc_bar.set_value(self.disc_space[1] / self.disc_space[0])
        self.card_bar.set_value(self.card_space[1] / self.card_space[0])

        self.obj("free_wdir").set_text(_("free: {0} of {1}").format(
            self.sizeof_fmt(self.disc_space[2]),
            self.sizeof_fmt(self.disc_space[0]),
            ))

        if self.card_space[3]:
            self.obj("free_sd").set_text(_("free: {0} of {1}").format(
                self.sizeof_fmt(self.card_space[2]),
                self.sizeof_fmt(self.card_space[0]),
                ))
        else:
            self.obj("free_sd").set_text("")

    # borrowed from
    # http://stackoverflow.com/questions/1094841/
    # reusable-library-to-get-human-readable-version-of-file-size 
Example #30
Source Project: gpt   Author: encarsia   File: modules.py    License: GNU General Public License v3.0 4 votes vote down vote up
def freespace(self, src, dest):
        """Check for free disc space"""
        import_size = 0
        for dirpath, dirnames, filenames in os.walk(src):
            for f in filenames:
                fp = os.path.join(dirpath, f)
                import_size += os.path.getsize(fp)
        if import_size < shutil.disk_usage(dest).free:
            return True
        else:
            self.needspace = app.sizeof_fmt(import_size - shutil.disk_usage(dest).free)
            return False

    # Zielordner wählen, neuen oder bestehenden Ordner, Defaultwert yyyy-mm-dd