annotate setup_win_common.py @ 3182:0c07af110477 docs-changes

Ignore Sphinx-generated files
author Thomas Kluyver <takowl@gmail.com>
date Wed, 09 Jan 2013 22:35:43 +0000
parents 49fce47e4d56
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1357
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
2
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
3 # module setup_win_common.py
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
4
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
5 """A module for reading the information common to all Windows setups.
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
6
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
7 Exports read and get_definitions.
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
8 """
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
9
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
10 path = 'Setup_Win_Common.in'
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
11
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
12 class Definition(object):
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
13 def __init__(self, name, value):
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
14 self.name = name
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
15 self.value = value
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
16
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
17 def read():
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
18 """Return the contents of the Windows Common Setup as a string"""
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
19
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
20 setup_in = open(path)
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
21 try:
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
22 return setup_in.read()
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
23 finally:
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
24 setup_in.close()
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
25
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
26 def get_definitions():
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
27 """Return a list of definitions in the Windows Common Setup
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
28
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
29 Each macro definition object has a 'name' and 'value' attribute.
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
30 """
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
31 import re
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
32
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
33 setup_in = open(path)
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
34 try:
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
35 deps = []
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
36 match = re.compile(r'([a-zA-Z0-9_]+) += +(.+)$').match
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
37 for line in setup_in:
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
38 m = match(line)
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
39 if m is not None:
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
40 deps.append(Definition(m.group(1), m.group(2)))
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
41 return deps
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
42 finally:
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
43 setup_in.close()
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
44
49fce47e4d56 Updated Windows config modules
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
45 __all__= ['read', 'get_dependencies']