closed #4786, Show tip message when python is not compatible.

This commit is contained in:
zhangbin 2014-04-14 17:29:37 +08:00
parent de5f52857a
commit 7874cd8045
2 changed files with 35 additions and 25 deletions

View File

@ -60,6 +60,14 @@ NDK_ROOT = 'NDK_ROOT'
ANDROID_SDK_ROOT = 'ANDROID_SDK_ROOT' ANDROID_SDK_ROOT = 'ANDROID_SDK_ROOT'
ANT_ROOT = 'ANT_ROOT' ANT_ROOT = 'ANT_ROOT'
def _check_python_version():
major_ver = sys.version_info[0]
if major_ver > 2:
print ("The python version is %d.%d. But python 2.x is required. (Version 2.7 is well tested)\n"
"Download it here: https://www.python.org/" % (major_ver, sys.version_info[1]))
return False
return True
class SetEnvVar(object): class SetEnvVar(object):
@ -168,7 +176,7 @@ class SetEnvVar(object):
def _set_environment_variable(self, key, value): def _set_environment_variable(self, key, value):
print " -> Add %s environment variable..." % key print(" -> Add %s environment variable..." % key)
ret = False ret = False
if self._isWindows(): if self._isWindows():
ret = self._set_environment_variable_win32(key, value) ret = self._set_environment_variable_win32(key, value)
@ -176,9 +184,9 @@ class SetEnvVar(object):
ret = self._set_environment_variable_unix(key, value) ret = self._set_environment_variable_unix(key, value)
if ret: if ret:
print " ->Added %s=%s\n" % (key, value) print(" ->Added %s=%s\n" % (key, value))
else: else:
print " ->Add failed\n" print(" ->Add failed\n")
return ret return ret
@ -199,7 +207,7 @@ class SetEnvVar(object):
return ret return ret
def _find_environment_variable(self, var): def _find_environment_variable(self, var):
print " ->Find environment variable %s..." % var print(" ->Find environment variable %s..." % var)
ret = None ret = None
try: try:
ret = os.environ[var] ret = os.environ[var]
@ -235,9 +243,9 @@ class SetEnvVar(object):
ret = None ret = None
if ret is None: if ret is None:
print " ->%s not found\n" % var print(" ->%s not found\n" % var)
else: else:
print " ->%s is found : %s\n" % (var, ret) print(" ->%s is found : %s\n" % (var, ret))
return ret return ret
@ -320,7 +328,7 @@ class SetEnvVar(object):
ret = False ret = False
if not ret: if not ret:
print ' ->Error: "%s" is not a valid path of %s. Ignoring it.' % (value, var_name) print(' ->Error: "%s" is not a valid path of %s. Ignoring it.' % (value, var_name))
return ret return ret
@ -384,9 +392,9 @@ class SetEnvVar(object):
_winreg.FlushKey(env) _winreg.FlushKey(env)
_winreg.CloseKey(env) _winreg.CloseKey(env)
print ' ->Remove directory \"%s\" from PATH!\n' % remove_dir print(' ->Remove directory \"%s\" from PATH!\n' % remove_dir)
except Exception: except Exception:
print ' ->Remove directory \"%s\" from PATH failed!\n' % remove_dir print(' ->Remove directory \"%s\" from PATH failed!\n' % remove_dir)
def set_windows_path(self, add_dir): def set_windows_path(self, add_dir):
ret = False ret = False
@ -425,13 +433,13 @@ class SetEnvVar(object):
_winreg.CloseKey(env) _winreg.CloseKey(env)
if ret: if ret:
print " ->Add directory \"%s\" into PATH succeed!\n" % add_dir print(" ->Add directory \"%s\" into PATH succeed!\n" % add_dir)
else: else:
print " ->Add directory \"%s\" into PATH failed!\n" % add_dir print(" ->Add directory \"%s\" into PATH failed!\n" % add_dir)
def set_console_root(self): def set_console_root(self):
print "->Check environment variable %s" % COCOS_CONSOLE_ROOT print("->Check environment variable %s" % COCOS_CONSOLE_ROOT)
cocos_consle_root = os.path.join(self.current_absolute_path, 'tools', 'cocos2d-console', 'bin') cocos_consle_root = os.path.join(self.current_absolute_path, 'tools', 'cocos2d-console', 'bin')
old_dir = self._find_environment_variable(COCOS_CONSOLE_ROOT) old_dir = self._find_environment_variable(COCOS_CONSOLE_ROOT)
if old_dir is None: if old_dir is None:
@ -459,7 +467,7 @@ class SetEnvVar(object):
if self._isLinux(): if self._isLinux():
file_list = SetEnvVar.LINUX_CHECK_FILES file_list = SetEnvVar.LINUX_CHECK_FILES
print " ->Update variable %s in files %s" % (var_name, str(file_list)) print(" ->Update variable %s in files %s" % (var_name, str(file_list)))
variable_updated = False variable_updated = False
for file_name in file_list: for file_name in file_list:
path = os.path.join(home, file_name) path = os.path.join(home, file_name)
@ -484,11 +492,11 @@ class SetEnvVar(object):
file_obj = open(path, 'w') file_obj = open(path, 'w')
file_obj.writelines(lines) file_obj.writelines(lines)
file_obj.close() file_obj.close()
print " ->File %s updated!" % path print(" ->File %s updated!" % path)
# nothing updated, should add variable # nothing updated, should add variable
if not variable_updated: if not variable_updated:
print "\n ->No files updated, add variable %s instead!" % var_name print("\n ->No files updated, add variable %s instead!" % var_name)
ret = self._set_environment_variable(var_name, value) ret = self._set_environment_variable(var_name, value)
else: else:
ret = True ret = True
@ -499,18 +507,18 @@ class SetEnvVar(object):
def _force_update_env(self, var_name, value): def _force_update_env(self, var_name, value):
ret = False ret = False
if self._isWindows(): if self._isWindows():
print " ->Force update environment variable %s" % var_name print(" ->Force update environment variable %s" % var_name)
ret = self._set_environment_variable_win32(var_name, value) ret = self._set_environment_variable_win32(var_name, value)
if not ret: if not ret:
print " ->Failed!" print(" ->Failed!")
else: else:
print " ->Succeed : %s=%s" % (var_name, value) print(" ->Succeed : %s=%s" % (var_name, value))
else: else:
ret = self._force_update_unix_env(var_name, value) ret = self._force_update_unix_env(var_name, value)
return ret return ret
def set_variable(self, var_name, value): def set_variable(self, var_name, value):
print "->Check environment variable %s" % var_name print("->Check environment variable %s" % var_name)
find_value = self._find_environment_variable(var_name) find_value = self._find_environment_variable(var_name)
var_found = (find_value is not None) var_found = (find_value is not None)
action_none = 0 action_none = 0
@ -558,7 +566,7 @@ class SetEnvVar(object):
def set_environment_variables(self, ndk_root, android_sdk_root, ant_root): def set_environment_variables(self, ndk_root, android_sdk_root, ant_root):
print '\nSetting up cocos2d-x...' print('\nSetting up cocos2d-x...')
self.file_used_for_setup = self._get_filepath_for_setup() self.file_used_for_setup = self._get_filepath_for_setup()
@ -569,15 +577,17 @@ class SetEnvVar(object):
# tip the backup file # tip the backup file
if (self.backup_file is not None) and (os.path.exists(self.backup_file)): if (self.backup_file is not None) and (os.path.exists(self.backup_file)):
print '\nA backup file \"%s\" is created for \"%s\".' % (self.backup_file, self.file_used_for_setup) print('\nA backup file \"%s\" is created for \"%s\".' % (self.backup_file, self.file_used_for_setup))
if self._isWindows(): if self._isWindows():
print '\nPlease restart the terminal or restart computer to make added system variables take effect\n' print('\nPlease restart the terminal or restart computer to make added system variables take effect\n')
else: else:
print '\nPlease execute command: "source %s" to make added system variables take effect\n' % self.file_used_for_setup print('\nPlease execute command: "source %s" to make added system variables take effect\n' % self.file_used_for_setup)
if __name__ == '__main__': if __name__ == '__main__':
if not _check_python_version():
exit()
parser = OptionParser() parser = OptionParser()
parser.add_option('-n', '--ndkroot', dest='ndk_root', help='directory of ndk root') parser.add_option('-n', '--ndkroot', dest='ndk_root', help='directory of ndk root')
parser.add_option('-a', '--androidsdkroot', dest='android_sdk_root', help='directory of android sdk root') parser.add_option('-a', '--androidsdkroot', dest='android_sdk_root', help='directory of android sdk root')

@ -1 +1 @@
Subproject commit ae27f3bafbbdda9c32e5b89c79183183486e1299 Subproject commit 3b619aec6b20841119110059189279b89a9344f4