Skip to content

Commit

Permalink
cocos2dx version info
Browse files Browse the repository at this point in the history
Added version Info for cocos2dx version by using a regex expression to
read the version form the cocos2d.cpp file. Only tested on OSX. Fixes
cocos2d#339
  • Loading branch information
lyinch committed May 3, 2016
1 parent 5e5a8f2 commit 99670ba
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bin/cocos.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import locale
import gettext
import json
import re


# FIXME: MultiLanguage should be deprecated in favor of gettext
Expand Down Expand Up @@ -178,7 +179,6 @@ def run_cmd(command, verbose, cwd=None):
else:
log_path = CCPlugin._log_path()
command += ' >"%s" 2>&1' % log_path
sys.stdout.flush()
ret = subprocess.call(command, shell=True, cwd=cwd)
if ret != 0:
message = MultiLanguage.get_string('COCOS_ERROR_RUNNING_CMD_RET_FMT', str(ret))
Expand Down Expand Up @@ -870,6 +870,13 @@ def _check_python_version():

return ret

def get_cocos_version():
path = os.path.dirname(os.path.abspath(sys.argv[1]))
reg_exp = re.compile(ur'return\s"([^"]*)"')
str = open(path+'/cocos2d.cpp','r').read()
cocos_version = reg_exp.findall(str)
return cocos_version

# gettext
locale.setlocale(locale.LC_ALL, '') # use user's preferred locale
language, encoding = locale.getlocale()
Expand Down Expand Up @@ -916,7 +923,8 @@ def _check_python_version():
sys.exit(0)

if len(sys.argv) > 1 and sys.argv[1] in ('-v', '--version'):
print("%s" % COCOS2D_CONSOLE_VERSION)
print("Console Version: %s" % COCOS2D_CONSOLE_VERSION)
print("Cocos Version: %s" % get_cocos_version())
DataStatistic.terminate_stat()
sys.exit(0)

Expand Down

0 comments on commit 99670ba

Please sign in to comment.