comparison pyver.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 import sys # Needed for version
2 import string # Needed for split
3 from orpg.orpg_version import * # To get NEEDS_PYTHON_MAJOR, MINOR, and MICRO
4
5 def getNumber(numberstringtoconvert):
6 currentnumberstring = ""
7 for number in numberstringtoconvert:
8 if number >= "0" and number <="9":
9 currentnumberstring += number
10 else:
11 break
12 if currentnumberstring == "":
13 return 0
14 else:
15 return int(currentnumberstring)
16 # This checks to make sure a certain version of python or later is in use
17 # The actual version requested is set in orpg/openrpg_version
18 def checkPyVersion():
19
20 # taking the first split on whitespace of sys.version gives us the version info without the build stuff
21 vernumstring = string.split(sys.version)[0]
22
23 # This splits the version string into (major,minor,micro). Actually, a complicating factor
24 # is that there sometimes isn't a micro, e.g. 2.0. We'll just do it the hard way to build
25 # the numbers instead of tuple unpacking.
26 splits = string.split(vernumstring,'.')
27
28 # Assign default values
29 micro = 0
30 minor = 0
31 major = 0
32 # Assign the integer conversion of each, assuming that it was found. If not found, we assumed 0 just above.
33 if len(splits) > 0:
34 major = getNumber(splits[0])
35 if len(splits) > 1:
36 minor = getNumber(splits[1])
37 if len(splits) > 2:
38 micro = getNumber(splits[2])
39 # Check against min version info from orpg/orpg_version
40 if major >= NEEDS_PYTHON_MAJOR:
41 if major > NEEDS_PYTHON_MAJOR: # If it's greater, there's no need to check the minor
42 return
43 if minor >= NEEDS_PYTHON_MINOR:
44 if minor > NEEDS_PYTHON_MINOR: # If it's greater, there's no need to check the micro
45 return
46 if micro >= NEEDS_PYTHON_MICRO:
47 return
48
49 # If we get here, then the version check failed so we inform the user of the required version and exit
50 print "Invalid python version being used. Detected version %s," % (vernumstring)
51 print "but version %i.%i.%i or better is required!" % (NEEDS_PYTHON_MAJOR,NEEDS_PYTHON_MINOR,NEEDS_PYTHON_MICRO)
52 print "You either have the wrong version of Python installed or you"
53 print "have multiple versions installed. If you have multiple versions,"
54 print "please make sure Python %i.%i.%i or better is found first in your path or explicitly" % (NEEDS_PYTHON_MAJOR,NEEDS_PYTHON_MINOR,NEEDS_PYTHON_MICRO)
55 print "start using, \"<path>\python <program>\"."
56 sys.exit( 1 )