Skip to content
Snippets Groups Projects
Commit 090eece1 authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Print the amount of free space that we have available in our temporary...

Print the amount of free space that we have available in our temporary directory as a debugging message. (Re: #100)
parent f02ef5fa
No related branches found
No related tags found
No related merge requests found
Pipeline #134369 passed
......@@ -40,12 +40,13 @@ from .tools import (
OS_NAMES,
get_current_os,
)
from .utils import format_bytes
from .config import Config
from .environ import normalize_environment
from .logging import line_eraser, setup_logging
from .progress import ProgressManager, Progress
from .profiling import ProfileManager, profile
from .tempfiles import clean_all_temp_files
from .tempfiles import clean_all_temp_files, get_tempdir_free_space
from .difference import Difference
from .comparators import ComparatorManager
from .external_tools import EXTERNAL_TOOLS
......@@ -650,6 +651,10 @@ def run_diffoscope(parsed_args):
"""
logger.debug("Starting diffoscope %s", VERSION)
logger.debug(
"Free space in temporary directory: %s",
format_bytes(get_tempdir_free_space()),
)
ProfileManager().setup(parsed_args)
PresenterManager().configure(parsed_args)
......
......@@ -2,7 +2,7 @@
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2016-2019 Chris Lamb <lamby@debian.org>
# Copyright © 2016-2020 Chris Lamb <lamby@debian.org>
# Copyright © 2018 Mattia Rizzolo <mattia@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
......@@ -90,3 +90,16 @@ def _get_base_temporary_directory():
_DIRS.append(d)
return _DIRS[0].name
def get_tempdir_free_space():
"""
unsigned long f_frsize Fundamental file system block size.
fsblkcnt_t f_blocks Total number of blocks on file system in units of f_frsize.
fsblkcnt_t f_bfree Total number of free blocks.
fsblkcnt_t f_bavail Number of free blocks available to
non-privileged process.
"""
statvfs = os.statvfs(tempfile.gettempdir())
return statvfs.f_frsize * statvfs.f_bavail
......@@ -2,7 +2,7 @@
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2019 Chris Lamb <lamby@debian.org>
# Copyright © 2019-2020 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -33,3 +33,14 @@ def format_cmdline(cmd, replace=(), truncate=None):
result = result[: truncate + 4] + " […]"
return result
def format_bytes(size, decimal_places=2):
# https://stackoverflow.com/a/43690506
for unit in ('B', 'KiB', 'MiB', 'GiB', 'TiB'):
if size < 1024.0:
break
size /= 1024.0
return f"{size:.{decimal_places}f} {unit}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment