1#!/usr/bin/python
2
3import sys, os
4import glob, re
5
6partA = """\
7python version %d.%d.%d can't run %s.  Try the alternative(s):
8
9"""
10partB = """
11Run "man python" for more information about multiple version support in
12Mac OS X.
13"""
14
15sys.stderr.write(partA % (sys.version_info[:3] + (sys.argv[0],)))
16
17dir, base = os.path.split(sys.argv[0])
18specialcase = (base == 'python-config')
19if specialcase:
20    pat = "python*-config"
21else:
22    pat = base + '*'
23g = glob.glob(os.path.join(dir, pat))
24# match a single digit, dot and possibly multiple digits, because we might
25# have 2to32.6, where the program is 2to3 and the version is 2.6.
26vpat = re.compile("\d\.\d+")
27n = 0
28for i in g:
29    vers = vpat.search(i)
30    if vers is None:
31	continue
32    sys.stderr.write("%s (uses python %s)\n" % (i, i[vers.start():vers.end()]))
33    n = 1
34if n == 0:
35    sys.stderr.write("(Error: no alternatives found)\n")
36
37sys.stderr.write(partB)
38sys.exit(1)
39