diff --git a/pyfpdb/Options.py b/pyfpdb/Options.py index 38307d40..8cd98f20 100644 --- a/pyfpdb/Options.py +++ b/pyfpdb/Options.py @@ -32,6 +32,9 @@ def fpdb_options(): parser.add_option("-c", "--configFile", dest="config", default=None, help="Specifies a configuration file.") + parser.add_option("-r", "--rerunPython", + action="store_true", + help="Indicates program was restarted with a different path (only allowed once).") (options, sys.argv) = parser.parse_args() return (options, sys.argv) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 570143cf..7f648b52 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -17,6 +17,33 @@ import os import sys +import re + +# if path is set to use an old version of python look for a new one: +# (does this work in linux?) +if os.name == 'nt' and sys.version[0:3] not in ('2.5', '2.6') and '-r' not in sys.argv: + #print "old path =", os.environ['PATH'] + dirs = re.split(os.pathsep, os.environ['PATH']) + # remove any trailing / or \ chars from dirs: + dirs = [re.sub('[\\/]$','',p) for p in dirs] + # remove any dirs containing 'python' apart from those ending in 'python25', 'python26' or 'python': + dirs = [p for p in dirs if not re.search('python', p, re.I) or re.search('python25$', p, re.I) or re.search('python26$', p, re.I)] + tmppath = ";".join(dirs) + #print "new path =", tmppath + if re.search('python', tmppath, re.I): + os.environ['PATH'] = tmppath + print "Python " + sys.version[0:3] + ' - press return to continue\n' + sys.stdin.readline() + os.execvpe('python.exe', ('python.exe', 'fpdb.py', '-r'), os.environ) # first arg is ignored (name of program being run) + else: + print "\npython 2.5 not found, please install python 2.5 or 2.6 for fpdb\n" + exit +else: + pass + #print "debug - not changing path" + +print "Python " + sys.version[0:3] + '...\n' + import threading import Options import string