From ab5bffbb6b78e24acf862fd2b724c7cbbca84c86 Mon Sep 17 00:00:00 2001 From: Fred Park Date: Tue, 17 Apr 2018 07:26:07 -0700 Subject: [PATCH] Limit file attribute warning on windows --- blobxfer/models/metadata.py | 18 +++++++++++++----- tests/test_blobxfer_models_metadata.py | 4 ++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/blobxfer/models/metadata.py b/blobxfer/models/metadata.py index ea8bb15..73125c3 100644 --- a/blobxfer/models/metadata.py +++ b/blobxfer/models/metadata.py @@ -86,6 +86,7 @@ VectoredNextEntry = collections.namedtuple( 'name', ] ) +_FILEATTR_WARNED_ON_WINDOWS = False def get_md5_from_metadata(ase): @@ -119,8 +120,12 @@ def generate_fileattr_metadata(local_path, metadata): :return: merged metadata dictionary """ if blobxfer.util.on_windows(): - logger.warning( - 'file attributes store/restore on Windows is not supported yet') + global _FILEATTR_WARNED_ON_WINDOWS + if not _FILEATTR_WARNED_ON_WINDOWS: + _FILEATTR_WARNED_ON_WINDOWS = True + logger.warning( + 'file attributes store/restore on Windows is not ' + 'supported yet') return None else: md = { @@ -149,9 +154,12 @@ def fileattr_from_metadata(md): return None else: if blobxfer.util.on_windows(): - logger.warning( - 'file attributes store/restore on Windows is not supported ' - 'yet') + global _FILEATTR_WARNED_ON_WINDOWS + if not _FILEATTR_WARNED_ON_WINDOWS: + _FILEATTR_WARNED_ON_WINDOWS = True + logger.warning( + 'file attributes store/restore on Windows is not ' + 'supported yet') fileattr = None else: try: diff --git a/tests/test_blobxfer_models_metadata.py b/tests/test_blobxfer_models_metadata.py index a64d033..33ee562 100644 --- a/tests/test_blobxfer_models_metadata.py +++ b/tests/test_blobxfer_models_metadata.py @@ -37,7 +37,9 @@ def test_get_md5_from_metadata(): def test_generate_fileattr_metadata(): with mock.patch('blobxfer.util.on_windows', return_value=True): + md._FILEATTR_WARNED_ON_WINDOWS = False assert md.generate_fileattr_metadata(None, None) is None + assert md._FILEATTR_WARNED_ON_WINDOWS with mock.patch('blobxfer.util.on_windows', return_value=False): lp = mock.MagicMock() @@ -65,11 +67,13 @@ def test_fileattr_from_metadata(): assert md.fileattr_from_metadata(None) is None with mock.patch('blobxfer.util.on_windows', return_value=True): + md._FILEATTR_WARNED_ON_WINDOWS = False val = { md.JSON_KEY_BLOBXFER_METADATA: json.dumps( {md._JSON_KEY_FILE_ATTRIBUTES: {}}) } assert md.fileattr_from_metadata(val) is None + assert md._FILEATTR_WARNED_ON_WINDOWS with mock.patch('blobxfer.util.on_windows', return_value=False): lp = mock.MagicMock()