File: find-binaries.py

package info (click to toggle)
edk2 2020.11-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 187,752 kB
  • sloc: ansic: 1,595,106; perl: 161,094; python: 125,339; asm: 18,555; cpp: 16,555; sh: 7,382; java: 6,173; cs: 3,822; makefile: 3,173; javascript: 1,744; xml: 635; pascal: 402; lisp: 35; sed: 5
file content (59 lines) | stat: -rw-r--r-- 2,192 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3

# Use heuristics to identify new files that maybe binaries.
# Flagged files need to be manually inspected and either added to the
# whitelist (because they are safe to redistribute), or to the blacklist
# (so that they'll be removed prior to orig.tar.xz generation).

import os
import re
import sys

def nameOK(name):
    OKPatterns = ['\.gitignore', 'AUTHORS', 'FILE.LST', 'Change[lL]og',
                  'COPYING', 'configure', 'FAQ', '(GNU)?[Mm]akefile',
                  'INDEX', 'LICENSE', 'README', 'TODO' ]
    OKRegexs = map(re.compile, OKPatterns)

    for r in OKRegexs:
        if r.match(name):
            return True
    return False

def extensionOK(name):
    OKExtensions = [ '1', '3', 'ASL', 'asi', 'asl', 'aslc', 'Asm', 'asm',
                     'asm16', 'bat', 'bmp', 'c', 'CMM', 'cmm', 'cnf', 'cpp',
                     'css', 'dec', 'decTest', 'dlg', 'dsc', 'docx', 'dsp',
                     'dsw', 'el', 'env', 'fdf', 'g', 'gif', 'H', 'h', 'hpp',
                     'html', 'i', 'idf', 'in', 'inc', 'inf', 'info', 'ini',
                     'lds', 'log', 'lua', 'mak', 'makefile', 'md', 'nasm',
                     'nasmb', 'nsh', 'patch', 'pbxuser', 'pbxproj', 'pdf',
                     'pem', 'pl', 'png', 'pod', 'ps', 'py', 'r', 'rtf', 'S',
                     's', 'sct', 'sh', 'sln', 't', 'template', 'txt', 'uni',
                     'Vfr', 'vcproj', 'vfi', 'vfr', 'xml' ]
    ext = name.split('.')[-1]

    if ext in OKExtensions:
        return True
    return False

if __name__ == '__main__':
    top = './'
    for root, dirs, files in os.walk(top):
        with open('./debian/binary-check.whitelist', 'r') as f:
            whitelist = list(map(lambda s: s.strip(), f.readlines()))

        ret = 0
        for name in files:
            relpath = os.path.join(root, name)[len(top):]
            if relpath in whitelist:
                continue
            if nameOK(name):
                continue
            if extensionOK(name):
                continue
            else:
                sys.stdout.write("WARNING: Possible binary %s\n" % (os.path.join(root, name)))
                ret = -1
    sys.exit(ret)