Eric Fiselier | 2d9feb5 | 2015-03-20 22:09:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
Eric Fiselier | 2d9feb5 | 2015-03-20 22:09:29 +0000 | [diff] [blame] | 2 | """ |
| 3 | sym_match - Match all symbols in a list against a list of regexes. |
| 4 | """ |
| 5 | from argparse import ArgumentParser |
| 6 | import sys |
| 7 | from sym_check import util, match, extract |
| 8 | |
| 9 | |
| 10 | def main(): |
| 11 | parser = ArgumentParser( |
| 12 | description='Extract a list of symbols from a shared library.') |
| 13 | parser.add_argument( |
| 14 | '--blacklist', dest='blacklist', |
| 15 | type=str, action='store', default=None) |
| 16 | parser.add_argument( |
| 17 | 'symbol_list', metavar='symbol_list', type=str, |
| 18 | help='The file containing the old symbol list') |
| 19 | parser.add_argument( |
| 20 | 'regexes', metavar='regexes', default=[], nargs='*', |
| 21 | help='The file containing the new symbol list or a library') |
| 22 | args = parser.parse_args() |
| 23 | |
| 24 | if not args.regexes and args.blacklist is None: |
| 25 | sys.stderr.write('Either a regex or a blacklist must be specified.\n') |
| 26 | sys.exit(1) |
| 27 | if args.blacklist: |
| 28 | search_list = util.read_blacklist(args.blacklist) |
| 29 | else: |
| 30 | search_list = args.regexes |
| 31 | |
| 32 | symbol_list = util.extract_or_load(args.symbol_list) |
| 33 | |
| 34 | matching_count, report = match.find_and_report_matching( |
| 35 | symbol_list, search_list) |
| 36 | sys.stdout.write(report) |
| 37 | if matching_count != 0: |
| 38 | print('%d matching symbols found...' % matching_count) |
| 39 | |
| 40 | |
| 41 | if __name__ == '__main__': |
| 42 | main() |