[Git][reproducible-builds/diffoscope][master] 2 commits: Allow bare try-except when cleaning up tempfiles.
Chris Lamb
gitlab at salsa.debian.org
Fri May 8 10:07:58 UTC 2020
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
f02ef5fa by Chris Lamb at 2020-05-08T11:07:19+01:00
Allow bare try-except when cleaning up tempfiles.
- - - - -
090eece1 by Chris Lamb at 2020-05-08T11:07:19+01:00
Print the amount of free space that we have available in our temporary directory as a debugging message. (Re: reproducible-builds/diffoscope#100)
- - - - -
3 changed files:
- diffoscope/main.py
- diffoscope/tempfiles.py
- diffoscope/utils.py
Changes:
=====================================
diffoscope/main.py
=====================================
@@ -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)
=====================================
diffoscope/tempfiles.py
=====================================
@@ -2,7 +2,7 @@
#
# diffoscope: in-depth comparison of files, archives, and directories
#
-# Copyright © 2016-2019 Chris Lamb <lamby at debian.org>
+# Copyright © 2016-2020 Chris Lamb <lamby at debian.org>
# Copyright © 2018 Mattia Rizzolo <mattia at debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
@@ -53,7 +53,7 @@ def clean_all_temp_files():
os.unlink(x)
except FileNotFoundError:
pass
- except:
+ except: # noqa
logger.exception("Unable to delete %s", x)
_FILES.clear()
@@ -74,7 +74,7 @@ def clean_all_temp_files():
x.cleanup()
except FileNotFoundError:
pass
- except:
+ except: # noqa
logger.exception("Unable to delete %s", x)
_DIRS.clear()
@@ -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
=====================================
diffoscope/utils.py
=====================================
@@ -2,7 +2,7 @@
#
# diffoscope: in-depth comparison of files, archives, and directories
#
-# Copyright © 2019 Chris Lamb <lamby at debian.org>
+# Copyright © 2019-2020 Chris Lamb <lamby at 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}"
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/dc4516b926a8e33015b0ac1b08bfae704bb75dc9...090eece140c374e19606a10996a29161d20dd7b4
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/dc4516b926a8e33015b0ac1b08bfae704bb75dc9...090eece140c374e19606a10996a29161d20dd7b4
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20200508/423837ad/attachment.htm>
More information about the rb-commits
mailing list