当前位置: 首页>>代码示例>>Python>>正文


Python shutil.disk_usage方法代码示例

本文整理汇总了Python中shutil.disk_usage方法的典型用法代码示例。如果您正苦于以下问题:Python shutil.disk_usage方法的具体用法?Python shutil.disk_usage怎么用?Python shutil.disk_usage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shutil的用法示例。


在下文中一共展示了shutil.disk_usage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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) 
开发者ID:aimagelab,项目名称:speaksee,代码行数:23,代码来源:field.py

示例2: test_disk_usage

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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) 
开发者ID:giampaolo,项目名称:psutil,代码行数:27,代码来源:test_system.py

示例3: available_bytes_at_path

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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 
开发者ID:glennmatthews,项目名称:cot,代码行数:22,代码来源:utilities.py

示例4: _get_message_if_space_insufficient

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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)) 
开发者ID:awslabs,项目名称:aws-iot-analytics-notebook-containers,代码行数:21,代码来源:kernel_image_creator.py

示例5: _check_tmp_free_space

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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 
开发者ID:dcos,项目名称:dcos-e2e,代码行数:27,代码来源:doctor.py

示例6: get_free_space_in_dir

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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 
开发者ID:holzschu,项目名称:Carnets,代码行数:25,代码来源:data.py

示例7: disk_usage

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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.") 
开发者ID:mbusb,项目名称:multibootusb,代码行数:35,代码来源:usb.py

示例8: install_progress

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:31,代码来源:install.py

示例9: freespace

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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 
开发者ID:encarsia,项目名称:gpt,代码行数:16,代码来源:modules.py

示例10: _check_size

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
def _check_size(self, s3key, check_inflate=False):
        """Check the size of an S3 file.

        Determine if there is enough local space to download and decompress the
        file.

        Args:
            s3key (str): the key name of the S3 object to check
            check_inflate (bool): if the file is compressed, evaluate the file's decompressed size.

        Returns:
            (bool): whether the file can be safely stored (and decompressed)

        """
        size_ok = False

        s3fileobj = self.s3_client.get_object(Bucket=self.report.get("S3Bucket"), Key=s3key)
        size = int(s3fileobj.get("ContentLength", -1))

        if size < 0:
            raise AWSReportDownloaderError(f"Invalid size for S3 object: {s3fileobj}")

        free_space = shutil.disk_usage(self.download_path)[2]
        if size < free_space:
            size_ok = True

        LOG.debug("%s is %s bytes; Download path has %s free", s3key, size, free_space)

        ext = os.path.splitext(s3key)[1]
        if ext == ".gz" and check_inflate and size_ok and size > 0:
            # isize block is the last 4 bytes of the file; see: RFC1952
            resp = self.s3_client.get_object(
                Bucket=self.report.get("S3Bucket"), Key=s3key, Range="bytes={}-{}".format(size - 4, size)
            )
            isize = struct.unpack("<I", resp["Body"].read(4))[0]
            if isize > free_space:
                size_ok = False

            LOG.debug("%s is %s bytes uncompressed; Download path has %s free", s3key, isize, free_space)

        return size_ok 
开发者ID:project-koku,项目名称:koku,代码行数:43,代码来源:aws_report_downloader.py

示例11: test_disk_usage

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:28,代码来源:test_system.py

示例12: test_disk_usage_unicode

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_system.py

示例13: test_disk_usage_bytes

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
def test_disk_usage_bytes(self):
        psutil.disk_usage(b'.') 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:4,代码来源:test_system.py

示例14: free_disk_usage

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
def free_disk_usage(directory='.'):
    return shutil.disk_usage(directory)[2] 
开发者ID:Nekmo,项目名称:telegram-upload,代码行数:4,代码来源:utils.py

示例15: find_recursive_pattern

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import disk_usage [as 别名]
def find_recursive_pattern(base_dir, pattern):
    for root, dirnames, filenames in os.walk(base_dir):
        for filename in fnmatch.filter(filenames, pattern):
            yield os.path.join(root, filename)


# disk_usage: Adapted from http://code.activestate.com/recipes/577972-disk-usage/ 
开发者ID:xBrite,项目名称:flyingcloud,代码行数:9,代码来源:file.py


注:本文中的shutil.disk_usage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。