1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """Base functionality: messages, verbosity, python version checking"""
22
23 import os
24 import sys
25 import traceback
26
27 _mbuild_verbose_level = 1
29 """Return True if the configured message level supplied is >= the
30 level arguement
31 @param level: int
32 @param level: the verbosity level at which this function should return True
33
34 @rtype: bool
35 @return: True iff the level argument is >= current verbosity level
36 """
37 global _mbuild_verbose_level
38 if _mbuild_verbose_level >= level:
39 return True
40 return False
45
50
52 """add a bracket around s and append m.
53 @rtype: string
54 @return: a bracketed string s and a suffixed message m
55 """
56 return '[%s] %s' % (s,str(m))
57
59 """Emit '[s] t' to stderr with a newline"""
60 sys.stderr.write(bracket(s,t) + "\n")
61
63 """Emit s to stdout with a newline"""
64 sys.stdout.write(pad)
65 sys.stdout.write(s)
66 sys.stdout.write("\n")
67
69 """Emit s to stdout without a newline"""
70 sys.stdout.write(pad)
71 sys.stdout.write(s)
72
73 -def msgb(s,t='',pad=''):
74 """a bracketed string s sent to stdout, followed by a string t"""
75 msg(bracket(s,t), pad=pad)
76
77 -def vmsgb(v,s,t='',pad=''):
78 """If verbosity v is sufficient, emit a bracketed string s sent to
79 stdout, followed by a string t"""
80 if verbose(v):
81 msg(bracket(s,t),pad=pad)
82
84 """Conditionally die, if v is not zero. Print the msg and the cmd.
85 @type v: int
86 @param v: we die if v is not 0
87
88 @type cmd: string
89 @param cmd: a command to print
90
91 @type msg: string
92 @param msg: a message to print before the command
93 """
94 if v != 0:
95 s = msg + "\n [CMD] " + cmd
96 die(s)
97
99 """Emit an error message m (and optionally s) and exit with a return value 1"""
100 msgb("MBUILD ERROR", "%s %s\n\n" % (m,s) )
101 traceback.print_exc(file=sys.stdout)
102 sys.exit(1)
104 """Emit an warning message"""
105 msgb("MBUILD WARNING", m)
106
108 """Return the python version as an integer
109 @rtype: int
110 @return: major * 100000 + minor + 1000 + fixlevel
111 """
112 tuple = sys.version_info
113 major = int(tuple[0])
114 minor = int(tuple[1])
115 fix = int(tuple[2])
116 vnum = major *100000 + minor * 1000 + fix
117 return vnum
118
120 """Return the python version as a tuple (major,minor,fixlevel)
121 @rtype: tuple
122 @return: (major,minor,fixlevel)
123 """
124
125 tuple = sys.version_info
126 major = int(tuple[0])
127 minor = int(tuple[1])
128 fix = int(tuple[2])
129 return (major,minor,fix)
130
132 """Return true if the current python version at least the one
133 specified by the arguments.
134 @rtype: bool
135 @return: True/False
136 """
137 t = get_python_version_tuple()
138 if t[0] > maj:
139 return True
140 if t[0] == maj and t[1] > minor:
141 return True
142 if t[0] == maj and t[1] == minor and t[2] >= fix:
143 return True
144 return False
145
146
147
148 try:
149 if check_python_version(2,4) == False:
150 die("MBUILD error: Need Python version 2.4 or later.")
151 except:
152 die("MBUILD error: Need Python version 2.4 or later.")
153
154 import platform
155 _on_mac = False
156 _on_native_windows = False
157 _on_windows = False
158 _on_cygwin = False
159 _on_linux = False
160 _on_freebsd = False
161 _operating_system_name = platform.system()
162 if _operating_system_name.find('CYGWIN') != -1:
163 _on_cygwin = True
164 _on_windows = True
165 elif _operating_system_name == 'Microsoft' or _operating_system_name == 'Windows':
166 _on_native_windows = True
167 _on_windows = True
168 elif _operating_system_name == 'Linux':
169 _on_linux = True
170 elif _operating_system_name == 'FreeBSD':
171 _on_freebsd = True
172 elif _operating_system_name == 'Darwin':
173 _on_mac = True
174 else:
175 die("Could not detect operating system type: " + _operating_system_name)
176
184
186 """
187 @rtype: bool
188 @return: True iff on windows cygwin/win32/win64
189 """
190 global _on_windows
191 return _on_windows
192