Commit | Line | Data |
---|---|---|
a65627a8 TL |
1 | #!/usr/bin/env python3 |
2 | ||
3 | # Use heuristics to identify new files that maybe binaries. | |
4 | # Flagged files need to be manually inspected and either added to the | |
47a343bc | 5 | # allow list (because they are safe to redistribute), or to the reject list |
a65627a8 TL |
6 | # (so that they'll be removed prior to orig.tar.xz generation). |
7 | ||
8 | import os | |
9 | import re | |
10 | import sys | |
11 | ||
47a343bc | 12 | |
a65627a8 | 13 | def nameOK(name): |
47a343bc TL |
14 | OKPatterns = [r'\.gitignore', r'AUTHORS', r'FILE.LST', r'Change[lL]og', |
15 | r'COPYING', r'configure', r'FAQ', r'(GNU)?[Mm]akefile', | |
16 | r'INDEX', r'LICENSE', r'README', r'TODO'] | |
a65627a8 TL |
17 | OKRegexs = map(re.compile, OKPatterns) |
18 | ||
19 | for r in OKRegexs: | |
20 | if r.match(name): | |
21 | return True | |
22 | return False | |
23 | ||
47a343bc | 24 | |
a65627a8 | 25 | def extensionOK(name): |
47a343bc TL |
26 | OKExtensions = ['1', '3', 'ASL', 'asi', 'asl', 'aslc', 'Asm', 'asm', |
27 | 'asm16', 'bat', 'bmp', 'c', 'CMM', 'cmm', 'cnf', 'cpp', | |
28 | 'css', 'dec', 'decTest', 'dlg', 'dsc', 'docx', 'dsp', | |
29 | 'dsw', 'el', 'env', 'fdf', 'g', 'gif', 'H', 'h', 'hpp', | |
30 | 'html', 'i', 'idf', 'in', 'inc', 'inf', 'info', 'ini', | |
31 | 'lds', 'log', 'lua', 'mak', 'makefile', 'md', 'nasm', | |
32 | 'nasmb', 'nsh', 'patch', 'pbxuser', 'pbxproj', 'pdf', | |
33 | 'pem', 'pl', 'png', 'pod', 'ps', 'py', 'r', 'rtf', 'S', | |
34 | 's', 'sct', 'sh', 'sln', 't', 'template', 'txt', 'uni', | |
35 | 'Vfr', 'vcproj', 'vfi', 'vfr', 'xml'] | |
a65627a8 TL |
36 | ext = name.split('.')[-1] |
37 | ||
38 | if ext in OKExtensions: | |
39 | return True | |
40 | return False | |
41 | ||
47a343bc | 42 | |
a65627a8 TL |
43 | if __name__ == '__main__': |
44 | top = './' | |
45 | for root, dirs, files in os.walk(top): | |
47a343bc TL |
46 | with open('./debian/binary-check.allow', 'r') as f: |
47 | allowlist = list(map(lambda s: s.strip(), f.readlines())) | |
a65627a8 TL |
48 | |
49 | ret = 0 | |
50 | for name in files: | |
51 | relpath = os.path.join(root, name)[len(top):] | |
47a343bc | 52 | if relpath in allowlist: |
a65627a8 TL |
53 | continue |
54 | if nameOK(name): | |
55 | continue | |
56 | if extensionOK(name): | |
57 | continue | |
58 | else: | |
47a343bc TL |
59 | sys.stdout.write( |
60 | "WARNING: Possible binary %s\n" % | |
61 | (os.path.join(root, name)) | |
62 | ) | |
a65627a8 TL |
63 | ret = -1 |
64 | sys.exit(ret) |