From 6352e67ab208619e764515dfb05ade21f0f9471f Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 20 Mar 2018 23:32:45 -0700 Subject: [PATCH] Update ansible-test is_binary_file test. Add hard-coded list of common text and binary extensions. --- test/runner/lib/util.py | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/runner/lib/util.py b/test/runner/lib/util.py index 70676a2ead..cf80269ad5 100644 --- a/test/runner/lib/util.py +++ b/test/runner/lib/util.py @@ -441,6 +441,55 @@ def is_binary_file(path): :type path: str :rtype: bool """ + assume_text = set([ + '.cfg', + '.conf', + '.crt', + '.css', + '.html', + '.ini', + '.j2', + '.js', + '.json', + '.md', + '.pem', + '.ps1', + '.psm1', + '.py', + '.rst', + '.sh', + '.txt', + '.xml', + '.yaml', + '.yml', + ]) + + assume_binary = set([ + '.bin', + '.eot', + '.gz', + '.ico', + '.iso', + '.jpg', + '.otf', + '.p12', + '.png', + '.pyc', + '.rpm', + '.ttf', + '.woff', + '.woff2', + '.zip', + ]) + + ext = os.path.splitext(path)[1] + + if ext in assume_text: + return False + + if ext in assume_binary: + return True + with open(path, 'rb') as path_fd: return b'\0' in path_fd.read(1024)