mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2026-01-11 00:46:51 +00:00
补充某些必要的文件
This commit is contained in:
164
cocos2d-x/tools/cocos2d-console/bin/MultiLanguage.py
Normal file
164
cocos2d-x/tools/cocos2d-console/bin/MultiLanguage.py
Normal file
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/python
|
||||
# ----------------------------------------------------------------------------
|
||||
# MultiLanguage: Get the multi-language strings for console.
|
||||
#
|
||||
# Author: Bin Zhang
|
||||
#
|
||||
# License: MIT
|
||||
# ----------------------------------------------------------------------------
|
||||
'''
|
||||
Get the multi-language strings for console.
|
||||
'''
|
||||
|
||||
import cocos
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import locale
|
||||
|
||||
def get_current_path():
|
||||
if getattr(sys, 'frozen', None):
|
||||
ret = os.path.realpath(os.path.dirname(sys.executable))
|
||||
else:
|
||||
ret = os.path.realpath(os.path.dirname(__file__))
|
||||
|
||||
return ret
|
||||
|
||||
class MultiLanguage(object):
|
||||
CONFIG_FILE_NAME = 'strings.json'
|
||||
DEFAULT_LANGUAGE = 'en'
|
||||
instance = None
|
||||
|
||||
@classmethod
|
||||
def get_available_langs(cls):
|
||||
info = cls.get_instance().cfg_info
|
||||
ret = []
|
||||
if info is not None:
|
||||
for key in info.keys():
|
||||
if isinstance(key, unicode):
|
||||
ret.append(key.encode('utf-8'))
|
||||
|
||||
return ret
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls):
|
||||
if cls.instance is None:
|
||||
cls.instance = MultiLanguage()
|
||||
|
||||
return cls.instance
|
||||
|
||||
@classmethod
|
||||
def get_string(cls, key, fmt_value=None):
|
||||
fmt = cls.get_instance().get_current_string(key)
|
||||
if fmt_value is None:
|
||||
ret = fmt
|
||||
else:
|
||||
if isinstance(fmt_value, tuple):
|
||||
dst_values = []
|
||||
for value in fmt_value:
|
||||
if isinstance(value, unicode):
|
||||
dst_values.append(value.encode(cls.get_instance().get_encoding()))
|
||||
else:
|
||||
dst_values.append(value)
|
||||
ret = fmt % tuple(dst_values)
|
||||
elif isinstance(fmt_value, unicode):
|
||||
ret = fmt % fmt_value.encode(cls.get_instance().get_encoding())
|
||||
else:
|
||||
ret = fmt % fmt_value
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
@classmethod
|
||||
def set_language(cls, lang):
|
||||
cls.get_instance().set_current_language(lang)
|
||||
|
||||
def __init__(self):
|
||||
cfg_file_path = os.path.join(get_current_path(), MultiLanguage.CONFIG_FILE_NAME)
|
||||
|
||||
try:
|
||||
sys_lang, self.encoding = locale.getdefaultlocale()
|
||||
except:
|
||||
sys_lang = None
|
||||
self.encoding = None
|
||||
pass
|
||||
|
||||
if self.encoding is None:
|
||||
self.encoding = 'utf-8'
|
||||
|
||||
if sys_lang is None:
|
||||
cur_lang_key = MultiLanguage.DEFAULT_LANGUAGE
|
||||
else:
|
||||
cur_lang_key = self.get_lang_key(sys_lang)
|
||||
|
||||
# override lang & encoding
|
||||
self.encoding = 'utf-8'
|
||||
cur_lang_key = MultiLanguage.DEFAULT_LANGUAGE
|
||||
|
||||
# get the strings info
|
||||
if os.path.isfile(cfg_file_path):
|
||||
f = open(cfg_file_path)
|
||||
self.cfg_info = json.load(f, encoding='utf-8')
|
||||
f.close()
|
||||
|
||||
if self.cfg_info.has_key(cur_lang_key):
|
||||
self.cur_lang_strings = self.cfg_info[cur_lang_key]
|
||||
else:
|
||||
self.cur_lang_strings = None
|
||||
|
||||
if self.cfg_info.has_key(MultiLanguage.DEFAULT_LANGUAGE):
|
||||
self.default_lang_strings = self.cfg_info[MultiLanguage.DEFAULT_LANGUAGE]
|
||||
else:
|
||||
self.default_lang_strings = None
|
||||
else:
|
||||
self.cfg_info = None
|
||||
self.cur_lang_strings = None
|
||||
self.default_lang_strings = None
|
||||
|
||||
def get_lang_key(self, sys_lang):
|
||||
sys_lang_info = sys_lang.split('_')
|
||||
lang = sys_lang_info[0]
|
||||
lang = lang.lower()
|
||||
region = None
|
||||
if len(sys_lang_info) > 1:
|
||||
region = sys_lang_info[1]
|
||||
region = region.lower()
|
||||
|
||||
if lang == 'zh':
|
||||
if (region is None) or (region == 'cn'):
|
||||
ret = lang
|
||||
else:
|
||||
ret = 'zh_tr'
|
||||
else:
|
||||
ret = lang
|
||||
|
||||
return ret
|
||||
|
||||
def has_key(self, key, strings_info):
|
||||
ret = False
|
||||
if strings_info is not None and strings_info.has_key(key):
|
||||
ret = True
|
||||
|
||||
return ret
|
||||
|
||||
def set_current_language(self, lang):
|
||||
if (self.cfg_info is not None) and (self.cfg_info.has_key(lang)):
|
||||
self.cur_lang_strings = self.cfg_info[lang]
|
||||
else:
|
||||
cocos.Logging.warning(MultiLanguage.get_string('COCOS_WARNING_LANG_NOT_SUPPORT_FMT', lang))
|
||||
|
||||
def get_encoding(self):
|
||||
return self.encoding
|
||||
|
||||
def get_current_string(self, key):
|
||||
if self.has_key(key, self.cur_lang_strings):
|
||||
ret = self.cur_lang_strings[key]
|
||||
elif self.has_key(key, self.default_lang_strings):
|
||||
ret = self.default_lang_strings[key]
|
||||
else:
|
||||
ret= key
|
||||
|
||||
if isinstance(ret, unicode):
|
||||
ret = ret.encode(self.encoding)
|
||||
|
||||
return ret
|
||||
7
cocos2d-x/tools/cocos2d-console/bin/cocos
Executable file
7
cocos2d-x/tools/cocos2d-console/bin/cocos
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash -l
|
||||
|
||||
COCOS_CONSOLE_BIN_DIRECTORY=$(dirname "$0")
|
||||
COCOS_CONSOLE_BIN_DIRECTORY=$(cd "$COCOS_CONSOLE_BIN_DIRECTORY" && pwd -P)
|
||||
|
||||
python "$COCOS_CONSOLE_BIN_DIRECTORY/cocos.py" "$@"
|
||||
|
||||
3
cocos2d-x/tools/cocos2d-console/bin/cocos.bat
Normal file
3
cocos2d-x/tools/cocos2d-console/bin/cocos.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
@python "%~dp0/cocos.py" %*
|
||||
|
||||
1072
cocos2d-x/tools/cocos2d-console/bin/cocos.py
Normal file
1072
cocos2d-x/tools/cocos2d-console/bin/cocos.py
Normal file
File diff suppressed because it is too large
Load Diff
57
cocos2d-x/tools/cocos2d-console/bin/cocos2d.ini
Normal file
57
cocos2d-x/tools/cocos2d-console/bin/cocos2d.ini
Normal file
@@ -0,0 +1,57 @@
|
||||
#
|
||||
# cocos2d command line tool configuration file
|
||||
#
|
||||
|
||||
[global]
|
||||
# there are 3 modes
|
||||
# "source", which means that the cocos2d-x source code is being used for "new" and other plugins.
|
||||
# "precompiled", which means that cocos2d-x precompiled libraries and headers will be used for "new" and other plugins
|
||||
# "distro", which means that cocos2d-x precompiled libraries and headers won't be copied when using "new" and other plugins
|
||||
# Default: source. Distros and other installers must override this setting
|
||||
cocos2d_x_mode=source
|
||||
|
||||
# Enable/Disable the data statistics
|
||||
# If the value is 'false' or 'no', statistics is disabled.
|
||||
# Otherwise, it's enabled.
|
||||
enable_stat=true
|
||||
|
||||
[plugins]
|
||||
# What are the plugins that must be enabled
|
||||
plugin_new.CCPluginNew
|
||||
plugin_compile.CCPluginCompile
|
||||
plugin_run.CCPluginRun
|
||||
plugin_deploy.CCPluginDeploy
|
||||
plugin_jscompile.CCPluginJSCompile
|
||||
plugin_luacompile.CCPluginLuaCompile
|
||||
plugin_generate.LibsCompiler
|
||||
plugin_generate.SimulatorCompiler
|
||||
plugin_generate.TemplateGenerator
|
||||
plugin_package.CCPluginPackage
|
||||
plugin_framework.CCPluginFramework
|
||||
plugin_gui.CCPluginGUI
|
||||
#plugin_version.CCPluginVersion
|
||||
#plugin_install.CCPluginInstall
|
||||
#plugin_update.CCPluginUpdate
|
||||
#plugin_clean.CCPluginClean
|
||||
#plugin_dist.CCPluginDist
|
||||
#plugin_test.CCPluginTest
|
||||
# To add a new plugin add it's classname here
|
||||
|
||||
|
||||
[paths]
|
||||
# where cocos2d-x is installed
|
||||
# example: /usr/local/cocos2d-x
|
||||
# eg: this file must exist: /usr/local/cocos2d-x/cocos/cocos2d.h
|
||||
# Default: empty. Installers will populate it
|
||||
cocos2d_x=
|
||||
|
||||
# where are the cocos2d-x's templates installed
|
||||
# example: /home/user/templates
|
||||
# eg: this directory must exist: /home/user/templates/cpp-template-default
|
||||
# Default: empty. Installers will populate it
|
||||
templates=
|
||||
|
||||
# where are the plugins installed
|
||||
# but distros can override this directory
|
||||
# Default: ../plugins. Installers can replace it if needed
|
||||
plugins=../plugins
|
||||
698
cocos2d-x/tools/cocos2d-console/bin/cocos_project.py
Normal file
698
cocos2d-x/tools/cocos2d-console/bin/cocos_project.py
Normal file
@@ -0,0 +1,698 @@
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
import cocos
|
||||
from MultiLanguage import MultiLanguage
|
||||
|
||||
class Project(object):
|
||||
CPP = 'cpp'
|
||||
LUA = 'lua'
|
||||
JS = 'js'
|
||||
|
||||
CONFIG = '.cocos-project.json'
|
||||
|
||||
KEY_PROJ_TYPE = 'project_type'
|
||||
KEY_HAS_NATIVE = 'has_native'
|
||||
KEY_CUSTOM_STEP_SCRIPT = "custom_step_script"
|
||||
KEY_ENGINE_VERSION = "engine_version"
|
||||
|
||||
CUSTOM_STEP_PRE_BUILD = "pre-build"
|
||||
CUSTOM_STEP_POST_BUILD = "post-build"
|
||||
|
||||
@staticmethod
|
||||
def list_for_display():
|
||||
return [x.lower() for x in Project.language_list()]
|
||||
|
||||
@staticmethod
|
||||
def language_list():
|
||||
return (Project.CPP, Project.LUA, Project.JS)
|
||||
|
||||
def __init__(self, project_dir):
|
||||
# parse the config file
|
||||
self.info = self._parse_project_json(project_dir)
|
||||
|
||||
def _parse_project_json(self, src_dir):
|
||||
proj_path = self._find_project_dir(src_dir)
|
||||
# config file is not found
|
||||
if proj_path == None:
|
||||
raise cocos.CCPluginError(MultiLanguage.get_string('PROJECT_CFG_NOT_FOUND_FMT',
|
||||
os.path.join(src_dir, Project.CONFIG)),
|
||||
cocos.CCPluginError.ERROR_PATH_NOT_FOUND)
|
||||
|
||||
project_json = os.path.join(proj_path, Project.CONFIG)
|
||||
try:
|
||||
f = open(project_json)
|
||||
project_info = json.load(f)
|
||||
f.close()
|
||||
except Exception:
|
||||
if f is not None:
|
||||
f.close()
|
||||
raise cocos.CCPluginError(MultiLanguage.get_string('PROJECT_CFG_BROKEN_FMT',
|
||||
project_json),
|
||||
cocos.CCPluginError.ERROR_PARSE_FILE)
|
||||
|
||||
if project_info is None:
|
||||
raise cocos.CCPluginError(MultiLanguage.get_string('PROJECT_CFG_PARSE_FAILED_FMT',
|
||||
Project.CONFIG), cocos.CCPluginError.ERROR_PARSE_FILE)
|
||||
|
||||
if not project_info.has_key(Project.KEY_PROJ_TYPE):
|
||||
raise cocos.CCPluginError(MultiLanguage.get_string('PROJECT_CFG_GET_VALUE_FAILED_FMT',
|
||||
(Project.KEY_PROJ_TYPE, Project.CONFIG)),
|
||||
cocos.CCPluginError.ERROR_WRONG_CONFIG)
|
||||
|
||||
lang = project_info[Project.KEY_PROJ_TYPE]
|
||||
lang = lang.lower()
|
||||
|
||||
# The config is invalid
|
||||
if not (lang in Project.language_list()):
|
||||
raise cocos.CCPluginError(MultiLanguage.get_string('PROJECT_CFG_INVALID_LANG_FMT',
|
||||
(Project.KEY_PROJ_TYPE, ', '.join(Project.list_for_display()))),
|
||||
cocos.CCPluginError.ERROR_WRONG_CONFIG)
|
||||
|
||||
# record the dir & language of the project
|
||||
self._project_dir = proj_path
|
||||
self._project_lang = lang
|
||||
|
||||
# if is script project, record whether it has native or not
|
||||
self._has_native = False
|
||||
if (self._is_script_project() and project_info.has_key(Project.KEY_HAS_NATIVE)):
|
||||
self._has_native = project_info[Project.KEY_HAS_NATIVE]
|
||||
|
||||
# if has custom step script, record it
|
||||
self._custom_step = None
|
||||
if (project_info.has_key(Project.KEY_CUSTOM_STEP_SCRIPT)):
|
||||
script_path = project_info[Project.KEY_CUSTOM_STEP_SCRIPT]
|
||||
if not os.path.isabs(script_path):
|
||||
script_path = os.path.join(self._project_dir, script_path)
|
||||
|
||||
if os.path.isfile(script_path):
|
||||
import sys
|
||||
script_dir, script_name = os.path.split(script_path)
|
||||
sys.path.append(script_dir)
|
||||
self._custom_step = __import__(os.path.splitext(script_name)[0])
|
||||
cocos.Logging.info(MultiLanguage.get_string('PROJECT_INFO_FOUND_CUSTOM_STEP_FMT', script_path))
|
||||
else:
|
||||
cocos.Logging.warning(MultiLanguage.get_string('PROJECT_WARNING_CUSTOM_SCRIPT_NOT_FOUND_FMT',
|
||||
script_path))
|
||||
self._custom_step = None
|
||||
|
||||
return project_info
|
||||
|
||||
def invoke_custom_step_script(self, event, tp, args):
|
||||
try:
|
||||
if self._custom_step is not None:
|
||||
self._custom_step.handle_event(event, tp, args)
|
||||
except Exception as e:
|
||||
cocos.Logging.warning(MultiLanguage.get_string('PROJECT_WARNING_CUSTOM_STEP_FAILED_FMT', e))
|
||||
raise e
|
||||
|
||||
def _find_project_dir(self, start_path):
|
||||
path = start_path
|
||||
while True:
|
||||
if cocos.os_is_win32():
|
||||
# windows root path, eg. c:\
|
||||
if re.match(".+:\\\\$", path):
|
||||
break
|
||||
else:
|
||||
# unix like use '/' as root path
|
||||
if path == '/' :
|
||||
break
|
||||
cfg_path = os.path.join(path, Project.CONFIG)
|
||||
if (os.path.exists(cfg_path) and os.path.isfile(cfg_path)):
|
||||
return path
|
||||
|
||||
path = os.path.dirname(path)
|
||||
|
||||
return None
|
||||
|
||||
def get_proj_config(self, key):
|
||||
project_json = os.path.join(self._project_dir, Project.CONFIG)
|
||||
f = open(project_json)
|
||||
project_info = json.load(f)
|
||||
f.close()
|
||||
|
||||
ret = None
|
||||
if project_info.has_key(key):
|
||||
ret = project_info[key]
|
||||
|
||||
return ret
|
||||
|
||||
def write_proj_config(self, key, value):
|
||||
project_json = os.path.join(self._project_dir, Project.CONFIG)
|
||||
|
||||
if os.path.isfile(project_json):
|
||||
f = open(project_json)
|
||||
project_info = json.load(f)
|
||||
f.close()
|
||||
|
||||
if project_info is None:
|
||||
project_info = {}
|
||||
|
||||
project_info[key] = value
|
||||
|
||||
outfile = open(project_json, "w")
|
||||
json.dump(project_info, outfile, sort_keys = True, indent = 4)
|
||||
outfile.close()
|
||||
|
||||
def get_project_dir(self):
|
||||
return self._project_dir
|
||||
|
||||
def get_language(self):
|
||||
return self._project_lang
|
||||
|
||||
def has_android_libs(self):
|
||||
if self._is_script_project():
|
||||
proj_android_path = os.path.join(self.get_project_dir(), "frameworks", "runtime-src", "proj.android", "libs")
|
||||
else:
|
||||
proj_android_path = os.path.join(self.get_project_dir(), "proj.android", "libs")
|
||||
|
||||
return os.path.isdir(proj_android_path)
|
||||
|
||||
def _is_native_support(self):
|
||||
return self._has_native
|
||||
|
||||
def _is_script_project(self):
|
||||
return self._is_lua_project() or self._is_js_project()
|
||||
|
||||
def _is_cpp_project(self):
|
||||
return self._project_lang == Project.CPP
|
||||
|
||||
def _is_lua_project(self):
|
||||
return self._project_lang == Project.LUA
|
||||
|
||||
def _is_js_project(self):
|
||||
return self._project_lang == Project.JS
|
||||
|
||||
class Platforms(object):
|
||||
ANDROID = 'android'
|
||||
IOS = 'ios'
|
||||
MAC = 'mac'
|
||||
WEB = 'web'
|
||||
WIN32 = 'win32'
|
||||
LINUX = 'linux'
|
||||
WP8 = "wp8"
|
||||
WP8_1 = "wp8_1"
|
||||
METRO = "metro"
|
||||
|
||||
CFG_CLASS_MAP = {
|
||||
ANDROID : "cocos_project.AndroidConfig",
|
||||
IOS : "cocos_project.iOSConfig",
|
||||
MAC : "cocos_project.MacConfig",
|
||||
WEB : "cocos_project.WebConfig",
|
||||
WIN32 : "cocos_project.Win32Config",
|
||||
LINUX : "cocos_project.LinuxConfig",
|
||||
WP8 : "cocos_project.Wp8Config",
|
||||
WP8_1 : "cocos_project.Wp8_1Config",
|
||||
METRO : "cocos_project.MetroConfig"
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def list_for_display():
|
||||
return [x.lower() for x in Platforms.list()]
|
||||
|
||||
@staticmethod
|
||||
def list():
|
||||
return Platforms.CFG_CLASS_MAP.keys()
|
||||
|
||||
def __init__(self, project, current, proj_dir = None):
|
||||
self._project = project
|
||||
|
||||
proj_info = self._project.info
|
||||
self._gen_available_platforms(proj_info, proj_dir)
|
||||
|
||||
self._current = None
|
||||
if current is not None:
|
||||
current_lower = current.lower()
|
||||
if current_lower in self._available_platforms.keys():
|
||||
self._current = current_lower
|
||||
else:
|
||||
raise cocos.CCPluginError(MultiLanguage.get_string('PROJECT_INVALID_PLATFORM_FMT',
|
||||
(self._available_platforms.keys(), current)),
|
||||
cocos.CCPluginError.ERROR_WRONG_ARGS)
|
||||
|
||||
def _filter_platforms(self, platforms):
|
||||
ret = []
|
||||
platforms_for_os = {
|
||||
"linux" : [ Platforms.WEB, Platforms.LINUX, Platforms.ANDROID ],
|
||||
"mac" : [ Platforms.WEB, Platforms.IOS, Platforms.MAC, Platforms.ANDROID ],
|
||||
"win32" : [ Platforms.WEB, Platforms.WIN32, Platforms.ANDROID, Platforms.WP8,
|
||||
Platforms.WP8_1, Platforms.METRO]
|
||||
}
|
||||
for p in platforms:
|
||||
if cocos.os_is_linux():
|
||||
if p in platforms_for_os["linux"]:
|
||||
ret.append(p)
|
||||
if cocos.os_is_mac():
|
||||
if p in platforms_for_os["mac"]:
|
||||
ret.append(p)
|
||||
if cocos.os_is_win32():
|
||||
if p in platforms_for_os["win32"]:
|
||||
ret.append(p)
|
||||
|
||||
return ret
|
||||
|
||||
def _gen_available_platforms(self, proj_info, proj_dir):
|
||||
# generate the platform list for different projects
|
||||
if self._project._is_lua_project():
|
||||
if self._project._is_native_support():
|
||||
platform_list = [ Platforms.ANDROID, Platforms.WIN32, Platforms.IOS, Platforms.MAC, Platforms.LINUX ]
|
||||
else:
|
||||
if self._project.has_android_libs():
|
||||
platform_list = [ Platforms.ANDROID ]
|
||||
else:
|
||||
platform_list = []
|
||||
elif self._project._is_js_project():
|
||||
if self._project._is_native_support():
|
||||
platform_list = [ Platforms.ANDROID, Platforms.WIN32, Platforms.IOS, Platforms.MAC, Platforms.WEB, Platforms.LINUX, Platforms.WP8, Platforms.WP8_1, Platforms.METRO ]
|
||||
else:
|
||||
if self._project.has_android_libs():
|
||||
platform_list = [ Platforms.ANDROID, Platforms.WEB ]
|
||||
else:
|
||||
platform_list = [ Platforms.WEB ]
|
||||
elif self._project._is_cpp_project():
|
||||
platform_list = [ Platforms.ANDROID, Platforms.WIN32, Platforms.IOS, Platforms.MAC, Platforms.LINUX, Platforms.WP8, Platforms.WP8_1, Platforms.METRO ]
|
||||
|
||||
# filter the available platform list
|
||||
platform_list = self._filter_platforms(platform_list)
|
||||
|
||||
# check the real available platforms
|
||||
self._available_platforms = {}
|
||||
root_path = self._project.get_project_dir()
|
||||
for p in platform_list:
|
||||
cfg_class = cocos.get_class(Platforms.CFG_CLASS_MAP[p])
|
||||
if cfg_class is None:
|
||||
continue
|
||||
|
||||
cfg_key = "%s_cfg" % p
|
||||
if proj_info.has_key(cfg_key):
|
||||
cfg_obj = cfg_class(root_path, self._project._is_script_project(), proj_info[cfg_key])
|
||||
else:
|
||||
cfg_obj = cfg_class(root_path, self._project._is_script_project())
|
||||
|
||||
if proj_dir is not None:
|
||||
cfg_obj.proj_path = os.path.join(root_path, proj_dir)
|
||||
|
||||
if cfg_obj._is_available():
|
||||
self._available_platforms[p] = cfg_obj
|
||||
|
||||
# don't have available platforms
|
||||
if len(self._available_platforms) == 0:
|
||||
raise cocos.CCPluginError(MultiLanguage.get_string('PROJECT_NO_AVAILABLE_PLATFORMS'),
|
||||
cocos.CCPluginError.ERROR_WRONG_CONFIG)
|
||||
|
||||
def get_current_platform(self):
|
||||
return self._current
|
||||
|
||||
def get_available_platforms(self):
|
||||
return self._available_platforms
|
||||
|
||||
def none_active(self):
|
||||
return self._current is None
|
||||
|
||||
def is_android_active(self):
|
||||
return self._current == Platforms.ANDROID
|
||||
|
||||
def is_ios_active(self):
|
||||
return self._current == Platforms.IOS
|
||||
|
||||
def is_mac_active(self):
|
||||
return self._current == Platforms.MAC
|
||||
|
||||
def is_web_active(self):
|
||||
return self._current == Platforms.WEB
|
||||
|
||||
def is_win32_active(self):
|
||||
return self._current == Platforms.WIN32
|
||||
|
||||
def is_linux_active(self):
|
||||
return self._current == Platforms.LINUX
|
||||
|
||||
def is_wp8_active(self):
|
||||
return self._current == Platforms.WP8
|
||||
|
||||
def is_wp8_1_active(self):
|
||||
return self._current == Platforms.WP8_1
|
||||
|
||||
def is_metro_active(self):
|
||||
return self._current == Platforms.METRO
|
||||
|
||||
def get_current_config(self):
|
||||
if self.none_active():
|
||||
return None
|
||||
|
||||
return self._available_platforms[self._current]
|
||||
|
||||
def project_path(self):
|
||||
if self._current is None:
|
||||
return None
|
||||
|
||||
cfg_obj = self._available_platforms[self._current]
|
||||
return cfg_obj.proj_path
|
||||
|
||||
def _has_one(self):
|
||||
return len(self._available_platforms) == 1
|
||||
|
||||
def select_one(self):
|
||||
if self._has_one():
|
||||
self._current = self._available_platforms.keys()[0]
|
||||
return
|
||||
|
||||
raise cocos.CCPluginError(MultiLanguage.get_string('PROJECT_SPECIFY_PLATFORM_FMT',
|
||||
str(self._available_platforms.keys())),
|
||||
cocos.CCPluginError.ERROR_WRONG_CONFIG)
|
||||
|
||||
class PlatformConfig(object):
|
||||
KEY_PROJ_PATH = "project_path"
|
||||
def __init__(self, proj_root_path, is_script, cfg_info = None):
|
||||
self._proj_root_path = proj_root_path
|
||||
self._is_script = is_script
|
||||
if cfg_info is None:
|
||||
self._use_default()
|
||||
else:
|
||||
self._parse_info(cfg_info)
|
||||
|
||||
def _use_default(self):
|
||||
pass
|
||||
|
||||
def _parse_info(self, cfg_info):
|
||||
if cfg_info.has_key(PlatformConfig.KEY_PROJ_PATH):
|
||||
self.proj_path = os.path.join(self._proj_root_path, cfg_info[PlatformConfig.KEY_PROJ_PATH])
|
||||
else:
|
||||
self.proj_path = None
|
||||
|
||||
def _is_available(self):
|
||||
ret = True
|
||||
if self.proj_path is None or not os.path.isdir(self.proj_path):
|
||||
ret = False
|
||||
|
||||
return ret
|
||||
|
||||
class AndroidConfig(PlatformConfig):
|
||||
KEY_STUDIO_PATH = "studio_proj_path"
|
||||
|
||||
def _use_default(self):
|
||||
if self._is_script:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "frameworks", "runtime-src", "proj.android-studio")
|
||||
else:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "proj.android-studio")
|
||||
|
||||
def _parse_info(self, cfg_info):
|
||||
super(AndroidConfig, self)._parse_info(cfg_info)
|
||||
|
||||
if cfg_info.has_key(AndroidConfig.KEY_STUDIO_PATH):
|
||||
self.proj_path = os.path.join(self._proj_root_path, cfg_info[AndroidConfig.KEY_STUDIO_PATH])
|
||||
|
||||
def _is_available(self):
|
||||
proj_android_existed = super(AndroidConfig, self)._is_available()
|
||||
proj_studio_existed = False
|
||||
if (self.proj_path is not None) and os.path.isdir(self.proj_path):
|
||||
proj_studio_existed = True
|
||||
|
||||
ret = (proj_android_existed or proj_studio_existed)
|
||||
return ret
|
||||
|
||||
class iOSConfig(PlatformConfig):
|
||||
KEY_PROJ_FILE = "project_file"
|
||||
KEY_TARGET_NAME = "target_name"
|
||||
|
||||
def _use_default(self):
|
||||
if self._is_script:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "frameworks", "runtime-src", "proj.ios_mac")
|
||||
else:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "proj.ios_mac")
|
||||
|
||||
self.proj_file = None
|
||||
self.target_name = None
|
||||
|
||||
def _parse_info(self, cfg_info):
|
||||
super(iOSConfig, self)._parse_info(cfg_info)
|
||||
if cfg_info.has_key(iOSConfig.KEY_PROJ_FILE):
|
||||
self.proj_file = cfg_info[iOSConfig.KEY_PROJ_FILE]
|
||||
else:
|
||||
self.proj_file = None
|
||||
|
||||
if cfg_info.has_key(iOSConfig.KEY_TARGET_NAME):
|
||||
self.target_name = cfg_info[iOSConfig.KEY_TARGET_NAME]
|
||||
else:
|
||||
self.target_name = None
|
||||
|
||||
def _is_available(self):
|
||||
ret = super(iOSConfig, self)._is_available()
|
||||
|
||||
return ret
|
||||
|
||||
class MacConfig(PlatformConfig):
|
||||
|
||||
def _use_default(self):
|
||||
if self._is_script:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "frameworks", "runtime-src", "proj.ios_mac")
|
||||
else:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "proj.ios_mac")
|
||||
|
||||
self.proj_file = None
|
||||
self.target_name = None
|
||||
|
||||
def _parse_info(self, cfg_info):
|
||||
super(MacConfig, self)._parse_info(cfg_info)
|
||||
if cfg_info.has_key(iOSConfig.KEY_PROJ_FILE):
|
||||
self.proj_file = cfg_info[iOSConfig.KEY_PROJ_FILE]
|
||||
else:
|
||||
self.proj_file = None
|
||||
|
||||
if cfg_info.has_key(iOSConfig.KEY_TARGET_NAME):
|
||||
self.target_name = cfg_info[iOSConfig.KEY_TARGET_NAME]
|
||||
else:
|
||||
self.target_name = None
|
||||
|
||||
def _is_available(self):
|
||||
ret = super(MacConfig, self)._is_available()
|
||||
|
||||
return ret
|
||||
|
||||
class Win32Config(PlatformConfig):
|
||||
KEY_SLN_FILE = "sln_file"
|
||||
KEY_PROJECT_NAME = "project_name"
|
||||
KEY_BUILD_CFG_PATH = "build_cfg_path"
|
||||
KEY_EXE_OUT_DIR = "exe_out_dir"
|
||||
|
||||
def _use_default(self):
|
||||
if self._is_script:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "frameworks", "runtime-src", "proj.win32")
|
||||
else:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "proj.win32")
|
||||
|
||||
self.sln_file = None
|
||||
self.project_name =None
|
||||
self.build_cfg_path = None
|
||||
self.exe_out_dir = None
|
||||
|
||||
def _parse_info(self, cfg_info):
|
||||
super(Win32Config, self)._parse_info(cfg_info)
|
||||
if cfg_info.has_key(Win32Config.KEY_SLN_FILE):
|
||||
self.sln_file = cfg_info[Win32Config.KEY_SLN_FILE]
|
||||
else:
|
||||
self.sln_file = None
|
||||
|
||||
if cfg_info.has_key(Win32Config.KEY_PROJECT_NAME):
|
||||
self.project_name = cfg_info[Win32Config.KEY_PROJECT_NAME]
|
||||
else:
|
||||
self.project_name = None
|
||||
|
||||
if cfg_info.has_key(Win32Config.KEY_BUILD_CFG_PATH):
|
||||
self.build_cfg_path = cfg_info[Win32Config.KEY_BUILD_CFG_PATH]
|
||||
else:
|
||||
self.build_cfg_path = None
|
||||
|
||||
if cfg_info.has_key(Win32Config.KEY_EXE_OUT_DIR):
|
||||
self.exe_out_dir = cfg_info[Win32Config.KEY_EXE_OUT_DIR]
|
||||
else:
|
||||
self.exe_out_dir = None
|
||||
|
||||
def _is_available(self):
|
||||
ret = super(Win32Config, self)._is_available()
|
||||
|
||||
return ret
|
||||
|
||||
class LinuxConfig(PlatformConfig):
|
||||
KEY_CMAKE_PATH = "cmake_path"
|
||||
KEY_BUILD_DIR = "build_dir"
|
||||
KEY_PROJECT_NAME = "project_name"
|
||||
KEY_BUILD_RESULT_DIR = "build_result_dir"
|
||||
|
||||
def _use_default(self):
|
||||
if self._is_script:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "frameworks", "runtime-src", "proj.linux")
|
||||
else:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "proj.linux")
|
||||
|
||||
self.cmake_path = None
|
||||
self.build_dir = None
|
||||
self.project_name = None
|
||||
self.build_result_dir = None
|
||||
|
||||
def _parse_info(self, cfg_info):
|
||||
super(LinuxConfig, self)._parse_info(cfg_info)
|
||||
if cfg_info.has_key(LinuxConfig.KEY_CMAKE_PATH):
|
||||
self.cmake_path = cfg_info[LinuxConfig.KEY_CMAKE_PATH]
|
||||
else:
|
||||
self.cmake_path = None
|
||||
|
||||
if cfg_info.has_key(LinuxConfig.KEY_BUILD_DIR):
|
||||
self.build_dir = cfg_info[LinuxConfig.KEY_BUILD_DIR]
|
||||
else:
|
||||
self.build_dir = None
|
||||
|
||||
if cfg_info.has_key(LinuxConfig.KEY_PROJECT_NAME):
|
||||
self.project_name = cfg_info[LinuxConfig.KEY_PROJECT_NAME]
|
||||
else:
|
||||
self.project_name = None
|
||||
|
||||
if cfg_info.has_key(LinuxConfig.KEY_BUILD_RESULT_DIR):
|
||||
self.build_result_dir = cfg_info[LinuxConfig.KEY_BUILD_RESULT_DIR]
|
||||
else:
|
||||
self.build_result_dir = None
|
||||
|
||||
def _is_available(self):
|
||||
ret = super(LinuxConfig, self)._is_available()
|
||||
|
||||
return ret
|
||||
|
||||
class WebConfig(PlatformConfig):
|
||||
KEY_SUB_URL = "sub_url"
|
||||
KEY_RUN_ROOT_DIR = "run_root_dir"
|
||||
KEY_COPY_RESOURCES = "copy_resources"
|
||||
|
||||
def _use_default(self):
|
||||
self.proj_path = self._proj_root_path
|
||||
self.run_root_dir = self._proj_root_path
|
||||
self.copy_res = None
|
||||
self.sub_url = None
|
||||
|
||||
def _parse_info(self, cfg_info):
|
||||
super(WebConfig, self)._parse_info(cfg_info)
|
||||
if cfg_info.has_key(WebConfig.KEY_SUB_URL):
|
||||
self.sub_url = cfg_info[WebConfig.KEY_SUB_URL]
|
||||
else:
|
||||
self.sub_url = None
|
||||
|
||||
if cfg_info.has_key(WebConfig.KEY_RUN_ROOT_DIR):
|
||||
self.run_root_dir = os.path.join(self._proj_root_path, cfg_info[WebConfig.KEY_RUN_ROOT_DIR])
|
||||
else:
|
||||
self.run_root_dir = None
|
||||
|
||||
if cfg_info.has_key(WebConfig.KEY_COPY_RESOURCES):
|
||||
self.copy_res = cfg_info[WebConfig.KEY_COPY_RESOURCES]
|
||||
else:
|
||||
self.copy_res = None
|
||||
|
||||
def _is_available(self):
|
||||
ret = super(WebConfig, self)._is_available()
|
||||
|
||||
if ret:
|
||||
index_path = os.path.join(self.proj_path, "index.html")
|
||||
ret = os.path.isfile(index_path)
|
||||
|
||||
return ret
|
||||
|
||||
class Wp8Config(PlatformConfig):
|
||||
KEY_BUILD_FOLDER_PATH = "build_folder_path"
|
||||
KEY_MANIFEST_PATH = "manifest_path"
|
||||
KEY_WP8_PROJ_PATH = 'wp8_proj_path'
|
||||
|
||||
def _use_default(self):
|
||||
if self._is_script:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "frameworks", "runtime-src", "proj.wp8-xaml")
|
||||
else:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "proj.wp8-xaml")
|
||||
|
||||
self.wp8_proj_path = self.proj_path
|
||||
self.sln_file = None
|
||||
self.project_name =None
|
||||
self.build_folder_path = "App/Bin/x86"
|
||||
self.manifest_path = "App/Properties/WMAppManifest.xml"
|
||||
|
||||
def _parse_info(self, cfg_info):
|
||||
super(Wp8Config, self)._parse_info(cfg_info)
|
||||
if cfg_info.has_key(Win32Config.KEY_SLN_FILE):
|
||||
self.sln_file = cfg_info[Win32Config.KEY_SLN_FILE]
|
||||
else:
|
||||
self.sln_file = None
|
||||
|
||||
if cfg_info.has_key(Wp8Config.KEY_WP8_PROJ_PATH):
|
||||
self.wp8_proj_path = os.path.join(self._proj_root_path, cfg_info[Wp8Config.KEY_WP8_PROJ_PATH])
|
||||
else:
|
||||
self.wp8_proj_path = self.proj_path
|
||||
|
||||
if cfg_info.has_key(Win32Config.KEY_PROJECT_NAME):
|
||||
self.project_name = cfg_info[Win32Config.KEY_PROJECT_NAME]
|
||||
else:
|
||||
self.project_name = None
|
||||
|
||||
if cfg_info.has_key(Wp8Config.KEY_BUILD_FOLDER_PATH):
|
||||
self.build_folder_path = cfg_info[Wp8Config.KEY_BUILD_FOLDER_PATH]
|
||||
else:
|
||||
self.build_folder_path = "App/Bin/x86"
|
||||
|
||||
if cfg_info.has_key(Wp8Config.KEY_MANIFEST_PATH):
|
||||
self.manifest_path = cfg_info[Wp8Config.KEY_MANIFEST_PATH]
|
||||
else:
|
||||
self.manifest_path = "App/Properties/WMAppManifest.xml"
|
||||
|
||||
def _is_available(self):
|
||||
ret = super(Wp8Config, self)._is_available()
|
||||
|
||||
return ret
|
||||
|
||||
class Wp8_1Config(PlatformConfig):
|
||||
def _use_default(self):
|
||||
if self._is_script:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "frameworks", "runtime-src", "proj.win8.1-universal")
|
||||
else:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "proj.win8.1-universal")
|
||||
|
||||
self.sln_file = None
|
||||
self.project_name =None
|
||||
|
||||
def _parse_info(self, cfg_info):
|
||||
super(Wp8_1Config, self)._parse_info(cfg_info)
|
||||
if cfg_info.has_key(Win32Config.KEY_SLN_FILE):
|
||||
self.sln_file = cfg_info[Win32Config.KEY_SLN_FILE]
|
||||
else:
|
||||
self.sln_file = None
|
||||
|
||||
if cfg_info.has_key(Win32Config.KEY_PROJECT_NAME):
|
||||
self.project_name = cfg_info[Win32Config.KEY_PROJECT_NAME]
|
||||
else:
|
||||
self.project_name = None
|
||||
|
||||
def _is_available(self):
|
||||
ret = super(Wp8_1Config, self)._is_available()
|
||||
|
||||
return ret
|
||||
|
||||
class MetroConfig(PlatformConfig):
|
||||
def _use_default(self):
|
||||
if self._is_script:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "frameworks", "runtime-src", "proj.win8.1-universal")
|
||||
else:
|
||||
self.proj_path = os.path.join(self._proj_root_path, "proj.win8.1-universal")
|
||||
|
||||
self.sln_file = None
|
||||
self.project_name =None
|
||||
|
||||
def _parse_info(self, cfg_info):
|
||||
super(MetroConfig, self)._parse_info(cfg_info)
|
||||
if cfg_info.has_key(Win32Config.KEY_SLN_FILE):
|
||||
self.sln_file = cfg_info[Win32Config.KEY_SLN_FILE]
|
||||
else:
|
||||
self.sln_file = None
|
||||
|
||||
if cfg_info.has_key(Win32Config.KEY_PROJECT_NAME):
|
||||
self.project_name = cfg_info[Win32Config.KEY_PROJECT_NAME]
|
||||
else:
|
||||
self.project_name = None
|
||||
|
||||
def _is_available(self):
|
||||
ret = super(MetroConfig, self)._is_available()
|
||||
|
||||
return ret
|
||||
560
cocos2d-x/tools/cocos2d-console/bin/cocos_stat.py
Normal file
560
cocos2d-x/tools/cocos2d-console/bin/cocos_stat.py
Normal file
@@ -0,0 +1,560 @@
|
||||
#!/usr/bin/python
|
||||
# ----------------------------------------------------------------------------
|
||||
# statistics: Statistics the user behaviors of cocos2d-console by google analytics
|
||||
#
|
||||
# Author: Bin Zhang
|
||||
#
|
||||
# License: MIT
|
||||
# ----------------------------------------------------------------------------
|
||||
'''
|
||||
Statistics the user behaviors of cocos2d-console by google analytics
|
||||
'''
|
||||
|
||||
import cocos
|
||||
import uuid
|
||||
import locale
|
||||
import httplib
|
||||
import urllib
|
||||
import platform
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
import socket
|
||||
import hashlib
|
||||
import datetime
|
||||
import zlib
|
||||
|
||||
import multiprocessing
|
||||
|
||||
# GA related Constants
|
||||
|
||||
GA_HOST = 'www.google-analytics.com'
|
||||
GA_PATH = '/collect'
|
||||
GA_APIVERSION = '1'
|
||||
APPNAME = 'CocosConcole'
|
||||
|
||||
TIMEOUT_VALUE = 0.5
|
||||
|
||||
# formal tracker ID
|
||||
GA_TRACKERID = 'UA-60734607-3'
|
||||
|
||||
# debug tracker ID
|
||||
# GA_TRACKERID = 'UA-60530469-4'
|
||||
|
||||
# BI related Constants
|
||||
BI_HOST = 'ark.cocounion.com'
|
||||
BI_PATH = '/as'
|
||||
BI_APPID = '433748803'
|
||||
|
||||
GA_ENABLED = True
|
||||
BI_ENABLED = False
|
||||
|
||||
class Fields(object):
|
||||
API_VERSION = 'v'
|
||||
TRACKING_ID = 'tid'
|
||||
HIT_TYPE = 't'
|
||||
CLIENT_ID = 'cid'
|
||||
EVENT_CATEGORY = 'ec'
|
||||
EVENT_ACTION = 'ea'
|
||||
EVENT_LABEL = 'el'
|
||||
EVENT_VALUE = 'ev'
|
||||
APP_NAME = 'an'
|
||||
APP_VERSION = 'av'
|
||||
USER_LANGUAGE = 'ul'
|
||||
USER_AGENT = 'ua'
|
||||
SCREEN_NAME = "cd"
|
||||
SCREEN_RESOLUTION = "sr"
|
||||
|
||||
|
||||
GA_CACHE_EVENTS_FILE = 'cache_events'
|
||||
GA_CACHE_EVENTS_BAK_FILE = 'cache_event_bak'
|
||||
|
||||
local_cfg_path = os.path.expanduser('~/.cocos')
|
||||
local_cfg_file = os.path.join(local_cfg_path, GA_CACHE_EVENTS_FILE)
|
||||
local_cfg_bak_file = os.path.join(local_cfg_path, GA_CACHE_EVENTS_BAK_FILE)
|
||||
file_in_use_lock = multiprocessing.Lock()
|
||||
bak_file_in_use_lock = multiprocessing.Lock()
|
||||
|
||||
|
||||
BI_CACHE_EVENTS_FILE = 'bi_cache_events'
|
||||
bi_cfg_file = os.path.join(local_cfg_path, BI_CACHE_EVENTS_FILE)
|
||||
bi_file_in_use_lock = multiprocessing.Lock()
|
||||
|
||||
def get_user_id():
|
||||
node = uuid.getnode()
|
||||
mac = uuid.UUID(int = node).hex[-12:]
|
||||
|
||||
uid = hashlib.md5(mac).hexdigest()
|
||||
return uid
|
||||
|
||||
def get_language():
|
||||
lang, encoding = locale.getdefaultlocale()
|
||||
return lang
|
||||
|
||||
def get_user_agent():
|
||||
ret_str = None
|
||||
if cocos.os_is_win32():
|
||||
ver_info = sys.getwindowsversion()
|
||||
ver_str = '%d.%d' % (ver_info[0], ver_info[1])
|
||||
if cocos.os_is_32bit_windows():
|
||||
arch_str = "WOW32"
|
||||
else:
|
||||
arch_str = "WOW64"
|
||||
ret_str = "Mozilla/5.0 (Windows NT %s; %s) Chrome/33.0.1750.154 Safari/537.36" % (ver_str, arch_str)
|
||||
elif cocos.os_is_mac():
|
||||
ver_str = (platform.mac_ver()[0]).replace('.', '_')
|
||||
ret_str = "Mozilla/5.0 (Macintosh; Intel Mac OS X %s) Chrome/35.0.1916.153 Safari/537.36" % ver_str
|
||||
elif cocos.os_is_linux():
|
||||
arch_str = platform.machine()
|
||||
ret_str = "Mozilla/5.0 (X11; Linux %s) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1636.0 Safari/537.36" % arch_str
|
||||
|
||||
return ret_str
|
||||
|
||||
def get_system_info():
|
||||
if cocos.os_is_win32():
|
||||
ret_str = "windows"
|
||||
ret_str += "_%s" % platform.release()
|
||||
if cocos.os_is_32bit_windows():
|
||||
ret_str += "_%s" % "32bit"
|
||||
else:
|
||||
ret_str += "_%s" % "64bit"
|
||||
elif cocos.os_is_mac():
|
||||
ret_str = "mac_%s" % (platform.mac_ver()[0]).replace('.', '_')
|
||||
elif cocos.os_is_linux():
|
||||
ret_str = "linux_%s" % platform.linux_distribution()[0]
|
||||
else:
|
||||
ret_str = "unknown"
|
||||
|
||||
return ret_str
|
||||
|
||||
def get_python_version():
|
||||
return "python_%s" % platform.python_version()
|
||||
|
||||
def get_time_stamp():
|
||||
utc_dt = datetime.datetime.utcnow()
|
||||
local_dt = utc_dt + datetime.timedelta(hours=8)
|
||||
epoch = datetime.datetime(1970,1,1)
|
||||
local_ts = (local_dt - epoch).total_seconds()
|
||||
ret = '%d' % int(local_ts)
|
||||
|
||||
return ret
|
||||
|
||||
def get_static_params(engine_version):
|
||||
static_params = {
|
||||
Fields.API_VERSION: GA_APIVERSION,
|
||||
Fields.TRACKING_ID: GA_TRACKERID,
|
||||
Fields.CLIENT_ID: get_user_id(),
|
||||
Fields.APP_NAME: APPNAME,
|
||||
Fields.HIT_TYPE: "event",
|
||||
Fields.USER_LANGUAGE: get_language(),
|
||||
Fields.APP_VERSION: engine_version,
|
||||
Fields.SCREEN_NAME: get_system_info(),
|
||||
Fields.SCREEN_RESOLUTION: get_python_version()
|
||||
}
|
||||
agent_str = get_user_agent()
|
||||
if agent_str is not None:
|
||||
static_params[Fields.USER_AGENT] = agent_str
|
||||
|
||||
return static_params
|
||||
|
||||
def gen_bi_event(event, event_value):
|
||||
time_stamp = get_time_stamp()
|
||||
if event_value == 0:
|
||||
is_cache_event = '1'
|
||||
else:
|
||||
is_cache_event = '0'
|
||||
|
||||
category = event[0]
|
||||
action = event[1]
|
||||
label = event[2]
|
||||
|
||||
event_name = category
|
||||
params = {
|
||||
'cached_event' : is_cache_event
|
||||
}
|
||||
if category == 'cocos':
|
||||
if action == 'start':
|
||||
event_name = 'cocos_invoked'
|
||||
elif action == 'running_command':
|
||||
event_name = 'running_command'
|
||||
params['command'] = label
|
||||
else:
|
||||
params['category'] = category
|
||||
params['action'] = action
|
||||
params['label'] = label
|
||||
elif category == 'new':
|
||||
event_name = 'new_project'
|
||||
params['language'] = action
|
||||
params['template'] = label
|
||||
elif category == 'new_engine_ver':
|
||||
event_name = 'engine_info'
|
||||
params['version'] = action
|
||||
params['engine_type'] = label
|
||||
elif category == 'compile':
|
||||
params['language'] = action
|
||||
params['target_platform'] = label
|
||||
else:
|
||||
params['category'] = category
|
||||
params['action'] = action
|
||||
params['label'] = label
|
||||
|
||||
if len(event) >= 4:
|
||||
appear_time = event[3]
|
||||
else:
|
||||
appear_time = time_stamp
|
||||
ret = {
|
||||
'u' : {
|
||||
'28' : get_user_id(),
|
||||
'34' : get_python_version()
|
||||
},
|
||||
'p' : params,
|
||||
's' : time_stamp,
|
||||
'e' : event_name,
|
||||
't' : appear_time
|
||||
}
|
||||
|
||||
return ret
|
||||
|
||||
def get_bi_params(events, event_value, multi_events=False, engine_versio=''):
|
||||
if cocos.os_is_win32():
|
||||
system_str = 'windows'
|
||||
ver_info = sys.getwindowsversion()
|
||||
ver_str = '%d.%d' % (ver_info[0], ver_info[1])
|
||||
if cocos.os_is_32bit_windows():
|
||||
arch_str = "_32bit"
|
||||
else:
|
||||
arch_str = "_64bit"
|
||||
system_ver = '%s%s' % (ver_str, arch_str)
|
||||
elif cocos.os_is_mac():
|
||||
system_str = 'mac'
|
||||
system_ver = (platform.mac_ver()[0])
|
||||
elif cocos.os_is_linux():
|
||||
system_str = 'linux'
|
||||
system_ver = platform.machine()
|
||||
else:
|
||||
system_str = 'unknown'
|
||||
system_ver = 'unknown'
|
||||
|
||||
events_param = []
|
||||
if multi_events:
|
||||
for e in events:
|
||||
events_param.append(gen_bi_event(e, event_value))
|
||||
else:
|
||||
events_param.append(gen_bi_event(events, event_value))
|
||||
|
||||
params = {
|
||||
'device': {
|
||||
'10' : system_ver,
|
||||
'11' : system_str
|
||||
},
|
||||
'app': {
|
||||
'7' : BI_APPID,
|
||||
'8' : engine_version,
|
||||
'9' : get_language()
|
||||
},
|
||||
'time' : get_time_stamp(),
|
||||
'events' : events_param
|
||||
}
|
||||
|
||||
return params
|
||||
|
||||
def cache_event(event, is_ga=True, multi_events=False):
|
||||
if is_ga:
|
||||
cache_ga_event(event)
|
||||
else:
|
||||
cache_bi_event(event, multi_events)
|
||||
|
||||
# BI cache events related methods
|
||||
def cache_bi_event(event, multi_events=False):
|
||||
bi_file_in_use_lock.acquire()
|
||||
|
||||
outFile = None
|
||||
try:
|
||||
# get current cached events
|
||||
cache_events = get_bi_cached_events(need_lock=False)
|
||||
|
||||
if multi_events:
|
||||
need_cache_size = len(event)
|
||||
else:
|
||||
need_cache_size = 1
|
||||
|
||||
# delete the oldest events if there are too many events.
|
||||
events_size = len(cache_events)
|
||||
if events_size >= Statistic.MAX_CACHE_EVENTS:
|
||||
start_idx = events_size - (Statistic.MAX_CACHE_EVENTS - need_cache_size)
|
||||
cache_events = cache_events[start_idx:]
|
||||
|
||||
# cache the new event
|
||||
if multi_events:
|
||||
for e in event:
|
||||
cache_events.append(e)
|
||||
else:
|
||||
cache_events.append(event)
|
||||
|
||||
# write file
|
||||
outFile = open(bi_cfg_file, 'w')
|
||||
json.dump(cache_events, outFile)
|
||||
outFile.close()
|
||||
except:
|
||||
if outFile is not None:
|
||||
outFile.close()
|
||||
finally:
|
||||
bi_file_in_use_lock.release()
|
||||
|
||||
def get_bi_cached_events(need_lock=True):
|
||||
if not os.path.isfile(bi_cfg_file):
|
||||
cached_events = []
|
||||
else:
|
||||
f = None
|
||||
try:
|
||||
if need_lock:
|
||||
bi_file_in_use_lock.acquire()
|
||||
|
||||
f = open(bi_cfg_file)
|
||||
cached_events = json.load(f)
|
||||
f.close()
|
||||
|
||||
if not isinstance(cached_events, list):
|
||||
cached_events = []
|
||||
except:
|
||||
cached_events = []
|
||||
finally:
|
||||
if f is not None:
|
||||
f.close()
|
||||
|
||||
if need_lock:
|
||||
bi_file_in_use_lock.release()
|
||||
|
||||
return cached_events
|
||||
|
||||
# GA cache events related methods
|
||||
def get_ga_cached_events(is_bak=False, need_lock=True):
|
||||
if is_bak:
|
||||
cfg_file = local_cfg_bak_file
|
||||
lock = bak_file_in_use_lock
|
||||
else:
|
||||
cfg_file = local_cfg_file
|
||||
lock = file_in_use_lock
|
||||
|
||||
if not os.path.isfile(cfg_file):
|
||||
cached_events = []
|
||||
else:
|
||||
f = None
|
||||
try:
|
||||
if need_lock:
|
||||
lock.acquire()
|
||||
|
||||
f = open(cfg_file)
|
||||
cached_events = json.load(f)
|
||||
f.close()
|
||||
|
||||
if not isinstance(cached_events, list):
|
||||
cached_events = []
|
||||
except:
|
||||
cached_events = []
|
||||
finally:
|
||||
if f is not None:
|
||||
f.close()
|
||||
if need_lock:
|
||||
lock.release()
|
||||
|
||||
return cached_events
|
||||
|
||||
def cache_ga_event(event):
|
||||
file_in_use_lock.acquire()
|
||||
|
||||
outFile = None
|
||||
try:
|
||||
# get current cached events
|
||||
cache_events = get_ga_cached_events(is_bak=False, need_lock=False)
|
||||
|
||||
# delete the oldest events if there are too many events.
|
||||
events_size = len(cache_events)
|
||||
if events_size >= Statistic.MAX_CACHE_EVENTS:
|
||||
start_idx = events_size - (Statistic.MAX_CACHE_EVENTS - 1)
|
||||
cache_events = cache_events[start_idx:]
|
||||
|
||||
# cache the new event
|
||||
cache_events.append(event)
|
||||
|
||||
# write file
|
||||
outFile = open(local_cfg_file, 'w')
|
||||
json.dump(cache_events, outFile)
|
||||
outFile.close()
|
||||
except:
|
||||
if outFile is not None:
|
||||
outFile.close()
|
||||
finally:
|
||||
file_in_use_lock.release()
|
||||
|
||||
def pop_bak_ga_cached_event():
|
||||
bak_file_in_use_lock.acquire()
|
||||
events = get_ga_cached_events(is_bak=True, need_lock=False)
|
||||
|
||||
if len(events) > 0:
|
||||
e = events[0]
|
||||
events = events[1:]
|
||||
outFile = None
|
||||
try:
|
||||
outFile = open(local_cfg_bak_file, 'w')
|
||||
json.dump(events, outFile)
|
||||
outFile.close()
|
||||
except:
|
||||
if outFile:
|
||||
outFile.close()
|
||||
else:
|
||||
e = None
|
||||
|
||||
bak_file_in_use_lock.release()
|
||||
|
||||
return e
|
||||
|
||||
def do_send_ga_cached_event(engine_version):
|
||||
e = pop_bak_ga_cached_event()
|
||||
while(e is not None):
|
||||
do_send(e, 0, is_ga=True, multi_events=False, engine_version=engine_version)
|
||||
e = pop_bak_ga_cached_event()
|
||||
|
||||
def get_params_str(event, event_value, is_ga=True, multi_events=False, engine_version=''):
|
||||
if is_ga:
|
||||
params = get_static_params(engine_version)
|
||||
params[Fields.EVENT_CATEGORY] = event[0]
|
||||
params[Fields.EVENT_ACTION] = event[1]
|
||||
params[Fields.EVENT_LABEL] = event[2]
|
||||
params[Fields.EVENT_VALUE] = '%d' % event_value
|
||||
params_str = urllib.urlencode(params)
|
||||
else:
|
||||
params = get_bi_params(event, event_value, multi_events, engine_version)
|
||||
strParam = json.dumps(params)
|
||||
params_str = zlib.compress(strParam, 9)
|
||||
|
||||
return params_str
|
||||
|
||||
def do_http_request(event, event_value, is_ga=True, multi_events=False, engine_version=''):
|
||||
ret = False
|
||||
conn = None
|
||||
try:
|
||||
params_str = get_params_str(event, event_value, is_ga, multi_events, engine_version)
|
||||
if is_ga:
|
||||
host_url = GA_HOST
|
||||
host_path = GA_PATH
|
||||
else:
|
||||
host_url = BI_HOST
|
||||
host_path = BI_PATH
|
||||
|
||||
socket.setdefaulttimeout(TIMEOUT_VALUE)
|
||||
|
||||
conn = httplib.HTTPConnection(host_url, timeout=TIMEOUT_VALUE)
|
||||
conn.request(method="POST", url=host_path, body=params_str)
|
||||
|
||||
response = conn.getresponse()
|
||||
res = response.status
|
||||
if res >= 200 and res < 300:
|
||||
# status is 2xx mean the request is success.
|
||||
ret = True
|
||||
else:
|
||||
ret = False
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
return ret
|
||||
|
||||
def do_send(event, event_value, is_ga=True, multi_events=False, engine_version=''):
|
||||
try:
|
||||
ret = do_http_request(event, event_value, is_ga, multi_events, engine_version)
|
||||
if not ret:
|
||||
# request failed, cache the event
|
||||
cache_event(event, is_ga, multi_events)
|
||||
except:
|
||||
pass
|
||||
|
||||
class Statistic(object):
|
||||
|
||||
MAX_CACHE_EVENTS = 50
|
||||
MAX_CACHE_PROC = 5
|
||||
|
||||
def __init__(self, engine_version):
|
||||
self.process_pool = []
|
||||
self.engine_version = engine_version
|
||||
if cocos.os_is_win32():
|
||||
multiprocessing.freeze_support()
|
||||
|
||||
def send_cached_events(self):
|
||||
try:
|
||||
# send GA cached events
|
||||
if GA_ENABLED:
|
||||
events = get_ga_cached_events()
|
||||
event_size = len(events)
|
||||
if event_size == 0:
|
||||
return
|
||||
|
||||
# rename the file
|
||||
if os.path.isfile(local_cfg_bak_file):
|
||||
os.remove(local_cfg_bak_file)
|
||||
os.rename(local_cfg_file, local_cfg_bak_file)
|
||||
|
||||
# create processes to handle the events
|
||||
proc_num = min(event_size, Statistic.MAX_CACHE_PROC)
|
||||
for i in range(proc_num):
|
||||
p = multiprocessing.Process(target=do_send_ga_cached_event, args=(self.engine_version,))
|
||||
p.start()
|
||||
self.process_pool.append(p)
|
||||
|
||||
# send BI cached events
|
||||
if BI_ENABLED:
|
||||
events = get_bi_cached_events()
|
||||
event_size = len(events)
|
||||
if event_size == 0:
|
||||
return
|
||||
|
||||
# remove the cached events file
|
||||
if os.path.isfile(bi_cfg_file):
|
||||
os.remove(bi_cfg_file)
|
||||
|
||||
p = multiprocessing.Process(target=do_send, args=(events, 0, False, True, self.engine_version,))
|
||||
p.start()
|
||||
self.process_pool.append(p)
|
||||
except:
|
||||
pass
|
||||
|
||||
def send_event(self, category, action, label):
|
||||
try:
|
||||
event = [ category, action, label ]
|
||||
|
||||
# send event to GA
|
||||
if GA_ENABLED:
|
||||
p = multiprocessing.Process(target=do_send, args=(event, 1, True, False, self.engine_version,))
|
||||
p.start()
|
||||
self.process_pool.append(p)
|
||||
|
||||
# send event to BI
|
||||
if BI_ENABLED:
|
||||
# add timestamp
|
||||
event.append(get_time_stamp())
|
||||
p = multiprocessing.Process(target=do_send, args=(event, 1, False, False, self.engine_version,))
|
||||
p.start()
|
||||
self.process_pool.append(p)
|
||||
except:
|
||||
pass
|
||||
|
||||
def terminate_stat(self):
|
||||
# terminate sub-processes
|
||||
if len(self.process_pool) > 0:
|
||||
alive_count = 0
|
||||
for p in self.process_pool:
|
||||
if p.is_alive():
|
||||
alive_count += 1
|
||||
|
||||
if alive_count > 0:
|
||||
time.sleep(1)
|
||||
for p in self.process_pool:
|
||||
if p.is_alive():
|
||||
p.terminate()
|
||||
|
||||
# remove the backup file
|
||||
if os.path.isfile(local_cfg_bak_file):
|
||||
os.remove(local_cfg_bak_file)
|
||||
94
cocos2d-x/tools/cocos2d-console/bin/install.py
Normal file
94
cocos2d-x/tools/cocos2d-console/bin/install.py
Normal file
@@ -0,0 +1,94 @@
|
||||
#
|
||||
# cocos console installation script.
|
||||
#
|
||||
# Script idea based on Homebrew installation script.
|
||||
# by Luis Parravicini.
|
||||
#
|
||||
|
||||
import os
|
||||
import sys
|
||||
import urllib
|
||||
from tarfile import TarFile
|
||||
import shutil
|
||||
|
||||
|
||||
COCOS2D_PREFIX = os.path.expanduser('~/.cocos2d')
|
||||
|
||||
|
||||
# TODO copied from cocos.py, refactor.
|
||||
class Logging:
|
||||
# TODO maybe the right way to do this is to use something like colorama?
|
||||
RED = '\033[31m'
|
||||
GREEN = '\033[32m'
|
||||
YELLOW = '\033[33m'
|
||||
MAGENTA = '\033[35m'
|
||||
RESET = '\033[0m'
|
||||
|
||||
@staticmethod
|
||||
def _print(s, color=None):
|
||||
if color and sys.stdout.isatty() and sys.platform != 'win32':
|
||||
print color + s + Logging.RESET
|
||||
else:
|
||||
print s
|
||||
|
||||
@staticmethod
|
||||
def debug(s):
|
||||
Logging._print(s, Logging.MAGENTA)
|
||||
|
||||
@staticmethod
|
||||
def info(s):
|
||||
Logging._print(s, Logging.GREEN)
|
||||
|
||||
@staticmethod
|
||||
def warning(s):
|
||||
Logging._print(s, Logging.YELLOW)
|
||||
|
||||
@staticmethod
|
||||
def error(s):
|
||||
Logging._print(s, Logging.RED)
|
||||
|
||||
|
||||
def die(msg):
|
||||
Logging.error(msg)
|
||||
sys.exit(1)
|
||||
|
||||
def touch(path):
|
||||
open(path, 'w').close()
|
||||
|
||||
|
||||
|
||||
Logging.info("Starting the installation for Cocos2D console")
|
||||
|
||||
console_path = os.path.join(COCOS2D_PREFIX, 'console')
|
||||
install_mark_path = os.path.join(console_path, 'installed')
|
||||
if os.path.exists(install_mark_path):
|
||||
die("""
|
||||
It appears cocos2d console is already installed. If you want to resintall you should
|
||||
delete the directory "%s" before running the installer again.
|
||||
""" % console_path)
|
||||
|
||||
Logging.info("Downloading...")
|
||||
download_path, _ = urllib.urlretrieve('https://github.com/cocos2d/cocos2d-console/tarball/master')
|
||||
|
||||
Logging.info("Installing...")
|
||||
with TarFile.open(download_path) as tar:
|
||||
tmp_path = os.path.join(COCOS2D_PREFIX, 'tmp')
|
||||
tar.extractall(tmp_path)
|
||||
# it's assumed the first entry is the directory containing all the other files
|
||||
dir = tar.getmembers()[0].name
|
||||
|
||||
extracted_path = os.path.join(tmp_path, dir)
|
||||
if os.path.exists(console_path):
|
||||
shutil.rmtree(console_path)
|
||||
shutil.move(extracted_path, console_path)
|
||||
|
||||
bin_path = os.path.join(console_path, 'console', 'bin')
|
||||
path = os.environ.get('PATH', '')
|
||||
if not bin_path in path.split(os.pathsep):
|
||||
Logging.warning("console path '%s' is not in PATH!" % bin_path)
|
||||
|
||||
touch(install_mark_path)
|
||||
|
||||
Logging.info("Cocos2D console installed successfully at %s" % console_path)
|
||||
Logging.info("Now type: cocos")
|
||||
|
||||
1038
cocos2d-x/tools/cocos2d-console/bin/strings.json
Normal file
1038
cocos2d-x/tools/cocos2d-console/bin/strings.json
Normal file
File diff suppressed because it is too large
Load Diff
284
cocos2d-x/tools/cocos2d-console/bin/utils.py
Normal file
284
cocos2d-x/tools/cocos2d-console/bin/utils.py
Normal file
@@ -0,0 +1,284 @@
|
||||
#!/usr/bin/python
|
||||
#-*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import cocos
|
||||
import re
|
||||
import zipfile
|
||||
|
||||
VS_VERSION_MAP = {
|
||||
2012 : "11.0",
|
||||
2013 : "12.0",
|
||||
2015 : "14.0",
|
||||
2017 : "15.0"
|
||||
}
|
||||
|
||||
def get_msbuild_path(vs_version):
|
||||
if cocos.os_is_win32():
|
||||
import _winreg
|
||||
else:
|
||||
return None
|
||||
|
||||
if isinstance(vs_version, int):
|
||||
# The value of vs_version is int. such as : 2017
|
||||
if vs_version in VS_VERSION_MAP.keys():
|
||||
vs_ver = VS_VERSION_MAP[vs_version]
|
||||
else:
|
||||
# not supported VS version
|
||||
return None
|
||||
elif isinstance(vs_version, str):
|
||||
# The value of vs_version is string. such as: "12.0", "14.0"
|
||||
vs_ver = vs_version
|
||||
else:
|
||||
return None
|
||||
|
||||
# If the system is 64bit, find VS in both 32bit & 64bit registry
|
||||
# If the system is 32bit, only find VS in 32bit registry
|
||||
if cocos.os_is_32bit_windows():
|
||||
reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
|
||||
else:
|
||||
reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]
|
||||
|
||||
# Find VS path
|
||||
msbuild_path = None
|
||||
for reg_flag in reg_flag_list:
|
||||
try:
|
||||
vs = _winreg.OpenKey(
|
||||
_winreg.HKEY_LOCAL_MACHINE,
|
||||
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\%s" % vs_ver,
|
||||
0,
|
||||
_winreg.KEY_READ | reg_flag
|
||||
)
|
||||
msbuild_path, type = _winreg.QueryValueEx(vs, 'MSBuildToolsPath')
|
||||
except:
|
||||
continue
|
||||
|
||||
if msbuild_path is not None:
|
||||
msbuild_path = os.path.join(msbuild_path, "MSBuild.exe")
|
||||
if os.path.exists(msbuild_path):
|
||||
break
|
||||
else:
|
||||
msbuild_path = None
|
||||
|
||||
return msbuild_path
|
||||
|
||||
def get_devenv_path(vs_version):
|
||||
if cocos.os_is_win32():
|
||||
import _winreg
|
||||
else:
|
||||
return None
|
||||
|
||||
if isinstance(vs_version, int):
|
||||
# The value of vs_version is int. such as : 2017
|
||||
if vs_version in VS_VERSION_MAP.keys():
|
||||
vs_ver = VS_VERSION_MAP[vs_version]
|
||||
else:
|
||||
# not supported VS version
|
||||
return None
|
||||
elif isinstance(vs_version, str):
|
||||
# The value of vs_version is string. such as: "12.0", "14.0"
|
||||
vs_ver = vs_version
|
||||
else:
|
||||
return None
|
||||
|
||||
# If the system is 64bit, find VS in both 32bit & 64bit registry
|
||||
# If the system is 32bit, only find VS in 32bit registry
|
||||
if cocos.os_is_32bit_windows():
|
||||
reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
|
||||
else:
|
||||
reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]
|
||||
|
||||
devenv_path = None
|
||||
for reg_flag in reg_flag_list:
|
||||
try:
|
||||
vs = _winreg.OpenKey(
|
||||
_winreg.HKEY_LOCAL_MACHINE,
|
||||
r"SOFTWARE\Microsoft\VisualStudio",
|
||||
0,
|
||||
_winreg.KEY_READ | reg_flag
|
||||
)
|
||||
except:
|
||||
continue
|
||||
|
||||
# find specified VS
|
||||
try:
|
||||
key = _winreg.OpenKey(vs, r"SxS\VS7")
|
||||
devenv_path, type = _winreg.QueryValueEx(key, vs_ver)
|
||||
except:
|
||||
pass
|
||||
|
||||
if devenv_path is not None:
|
||||
devenv_path = os.path.join(devenv_path, "Common7", "IDE", "devenv.com")
|
||||
if os.path.exists(devenv_path):
|
||||
break
|
||||
else:
|
||||
devenv_path = None
|
||||
|
||||
return devenv_path
|
||||
|
||||
def get_vs_versions():
|
||||
# Get the VS versions
|
||||
ret = []
|
||||
if cocos.os_is_win32():
|
||||
import _winreg
|
||||
else:
|
||||
return ret
|
||||
|
||||
# If the system is 64bit, find VS in both 32bit & 64bit registry
|
||||
# If the system is 32bit, only find VS in 32bit registry
|
||||
if cocos.os_is_32bit_windows():
|
||||
reg_flag_list = [ _winreg.KEY_WOW64_32KEY ]
|
||||
else:
|
||||
reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ]
|
||||
|
||||
version_pattern = re.compile(r'(\d+)\.(\d+)')
|
||||
for reg_flag in reg_flag_list:
|
||||
try:
|
||||
vs = _winreg.OpenKey(
|
||||
_winreg.HKEY_LOCAL_MACHINE,
|
||||
r"SOFTWARE\Microsoft\VisualStudio",
|
||||
0,
|
||||
_winreg.KEY_READ | reg_flag
|
||||
)
|
||||
except:
|
||||
continue
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
# enum the keys in vs reg
|
||||
try:
|
||||
version = _winreg.EnumKey(vs, i)
|
||||
except:
|
||||
break
|
||||
i += 1
|
||||
|
||||
match = re.match(version_pattern, version)
|
||||
if match is None:
|
||||
continue
|
||||
|
||||
ver_str = '%s.%s' % (match.group(1), match.group(2))
|
||||
if ver_str not in ret:
|
||||
ret.append(ver_str)
|
||||
|
||||
return ret
|
||||
|
||||
def get_newest_msbuild(min_ver=None):
|
||||
versions = get_vs_versions()
|
||||
|
||||
min_ver_float = 0.0
|
||||
if isinstance(min_ver, str):
|
||||
# value of min_ver is string. such as : "12.0", "14.0"
|
||||
min_ver_float = float(min_ver)
|
||||
elif isinstance(min_ver, int) and min_ver in VS_VERSION_MAP.keys():
|
||||
# value of min_ver is int. such as : 2017
|
||||
min_ver_float = float(VS_VERSION_MAP[min_ver])
|
||||
|
||||
find_ver = None
|
||||
find_path = None
|
||||
for v in versions:
|
||||
cur_v = float(v)
|
||||
if cur_v < min_ver_float:
|
||||
continue
|
||||
|
||||
v_path = get_msbuild_path(v)
|
||||
if v_path is not None:
|
||||
if (find_ver is None) or (cur_v > find_ver):
|
||||
find_ver = cur_v
|
||||
find_path = v_path
|
||||
|
||||
return find_path
|
||||
|
||||
def get_newest_devenv(min_ver=None):
|
||||
versions = get_vs_versions()
|
||||
|
||||
min_ver_float = 0.0
|
||||
if isinstance(min_ver, str):
|
||||
# value of min_ver is string. such as : "12.0", "14.0"
|
||||
min_ver_float = float(min_ver)
|
||||
elif isinstance(min_ver, int) and min_ver in VS_VERSION_MAP.keys():
|
||||
# value of min_ver is int. such as : 2017
|
||||
min_ver_float = float(VS_VERSION_MAP[min_ver])
|
||||
|
||||
find_ver = None
|
||||
find_path = None
|
||||
for v in versions:
|
||||
cur_v = float(v)
|
||||
if cur_v < min_ver_float:
|
||||
continue
|
||||
|
||||
v_path = get_devenv_path(v)
|
||||
if v_path is not None:
|
||||
if (find_ver is None) or (cur_v > find_ver):
|
||||
find_ver = cur_v
|
||||
find_path = v_path
|
||||
|
||||
if min_ver_float > 0 and find_ver > min_ver_float:
|
||||
need_upgrade = True
|
||||
else:
|
||||
need_upgrade = False
|
||||
|
||||
return (need_upgrade, find_path)
|
||||
|
||||
def rmdir(folder):
|
||||
if os.path.exists(folder):
|
||||
if sys.platform == 'win32':
|
||||
cocos.CMDRunner.run_cmd("rd /s/q \"%s\"" % folder, verbose=True)
|
||||
else:
|
||||
shutil.rmtree(folder)
|
||||
|
||||
VERSION_FILE_PATH = 'cocos/cocos2d.cpp'
|
||||
VERSION_PATTERN = r".*return[ \t]+\"(.*)\";"
|
||||
def get_engine_version(engine_path):
|
||||
ret = None
|
||||
|
||||
try:
|
||||
version_file = os.path.join(engine_path, VERSION_FILE_PATH)
|
||||
if os.path.isfile(version_file):
|
||||
f = open(version_file)
|
||||
for line in f.readlines():
|
||||
match = re.match(VERSION_PATTERN, line)
|
||||
if match:
|
||||
ret = match.group(1)
|
||||
break
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
return ret
|
||||
|
||||
def un_zip(file_name, output_dir):
|
||||
"""unzip zip file into output_dir"""
|
||||
zip_file = zipfile.ZipFile(file_name)
|
||||
for names in zip_file.namelist():
|
||||
zip_file.extract(names, output_dir)
|
||||
zip_file.close()
|
||||
|
||||
class ExtendEnv(object):
|
||||
extend_env = {}
|
||||
|
||||
@classmethod
|
||||
def parse_extend_env(cls, env):
|
||||
env_list = env.split(';')
|
||||
for item in env_list:
|
||||
index = item.find('=')
|
||||
if index > 0:
|
||||
key = item[:index]
|
||||
value = item[index+1:]
|
||||
cls.extend_env[key] = value
|
||||
|
||||
@classmethod
|
||||
def get_extend_env_value(cls, key):
|
||||
if (cls.extend_env.has_key(key)):
|
||||
return cls.extend_env[key]
|
||||
else:
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_extend_env_str(cls):
|
||||
env_list = []
|
||||
for item in cls.extend_env:
|
||||
env_list.append("%s=%s" % (item, cls.extend_env[item]))
|
||||
|
||||
return ';'.join(env_list)
|
||||
Reference in New Issue
Block a user