blob: 3ef96613e1a4fd9862d8a5a6e50b74a217143710 [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
Jack Jansenf6b53742000-06-13 13:39:17 +000011# optional - Include a module if it is found, but don't complain if it isn't
Jack Jansen144fa671998-06-26 14:56:00 +000012# path - Add sys.path entries. Relative paths are relative to the source file.
13#
14# See the macfreeze.py main program for a real live example.
15#
16DIRECTIVE_RE=r'^\s*#\s*macfreeze:\s*(\S*)\s*(.*)\s*$'
17REPROG=re.compile(DIRECTIVE_RE)
18
19def findfreezedirectives(program):
20 extra_modules = []
21 exclude_modules = []
Jack Jansenfb278a51999-06-04 15:56:33 +000022 optional_modules = []
Jack Jansen144fa671998-06-26 14:56:00 +000023 extra_path = []
24 progdir, filename = os.path.split(program)
25 fp = open(program)
26 for line in fp.readlines():
27 match = REPROG.match(line)
28 if match:
29 directive = match.group(1)
30 argument = match.group(2)
31 if directive == 'include':
32 extra_modules.append(argument)
33 elif directive == 'exclude':
34 exclude_modules.append(argument)
Jack Jansenfb278a51999-06-04 15:56:33 +000035 elif directive == 'optional':
36 optional_modules.append(argument)
Jack Jansen144fa671998-06-26 14:56:00 +000037 elif directive == 'path':
38 argument = os.path.join(progdir, argument)
39 extra_path.append(argument)
40 else:
41 print '** Unknown directive', line
Jack Jansenfb278a51999-06-04 15:56:33 +000042 return extra_modules, exclude_modules, optional_modules, extra_path
Jack Jansen144fa671998-06-26 14:56:00 +000043