blob: 16b7879e5b9eb95f47e63255ebf2c0ff546b3dc6 [file] [log] [blame]
Jack Jansen144fa671998-06-26 14:56:00 +00001import re
2import os
3
4# The regular expression for freeze directives. These are comments with the
5# word macfreeze immedeately followed by a colon, followed by a directive,
6# followed by argument(s)
7#
8# The directives supported are
9# include - Include a module or file
10# exclude - Exclude a module
11# path - Add sys.path entries. Relative paths are relative to the source file.
12#
13# See the macfreeze.py main program for a real live example.
14#
15DIRECTIVE_RE=r'^\s*#\s*macfreeze:\s*(\S*)\s*(.*)\s*$'
16REPROG=re.compile(DIRECTIVE_RE)
17
18def findfreezedirectives(program):
19 extra_modules = []
20 exclude_modules = []
Jack Jansenfb278a51999-06-04 15:56:33 +000021 optional_modules = []
Jack Jansen144fa671998-06-26 14:56:00 +000022 extra_path = []
23 progdir, filename = os.path.split(program)
24 fp = open(program)
25 for line in fp.readlines():
26 match = REPROG.match(line)
27 if match:
28 directive = match.group(1)
29 argument = match.group(2)
30 if directive == 'include':
31 extra_modules.append(argument)
32 elif directive == 'exclude':
33 exclude_modules.append(argument)
Jack Jansenfb278a51999-06-04 15:56:33 +000034 elif directive == 'optional':
35 optional_modules.append(argument)
Jack Jansen144fa671998-06-26 14:56:00 +000036 elif directive == 'path':
37 argument = os.path.join(progdir, argument)
38 extra_path.append(argument)
39 else:
40 print '** Unknown directive', line
Jack Jansenfb278a51999-06-04 15:56:33 +000041 return extra_modules, exclude_modules, optional_modules, extra_path
Jack Jansen144fa671998-06-26 14:56:00 +000042