Skip to content

Commit 8eb8d89

Browse files
committed
Merge pull request #4 from zrong/master
add some new function.
2 parents 6679d4c + e70f083 commit 8eb8d89

File tree

10 files changed

+156
-75
lines changed

10 files changed

+156
-75
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
setup(
3535
name="tbbl",
36-
version="0.0.7",
36+
version="0.1.3",
3737
url='http://zengrong.net/',
3838
author='zrong',
3939
author_email='[email protected]',

tbbl/__init__.py

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,4 @@
1-
import os
2-
import sys
3-
import logging
4-
import importlib
5-
from zrong import slog, add_log_handler
6-
from tbbl import base, config
7-
81
__all__ = ['base', 'admin', 'init', 'update', 'config', 'templ', 'res', 'server']
92

10-
def TEAM1201Error(Exception):
3+
class TEAM1201Error(Exception):
114
pass
12-
13-
def _build(name, conf, args, parser):
14-
pack = importlib.import_module("yhqb."+name)
15-
pack.build(conf, args, parser)
16-
17-
18-
def main():
19-
add_log_handler(slog,
20-
handler=logging.StreamHandler(sys.stdout),
21-
debug=logging.DEBUG)
22-
gconf = base.Conf()
23-
workDir = os.path.abspath(os.path.join(''))
24-
confFile = os.path.join(workDir, "yhqb_conf.py")
25-
if not os.path.exists(confFile):
26-
confFile = os.path.join(os.path.expanduser('~'), 'yhqb_conf.py')
27-
28-
slog.info('\nconffile:%s\n', confFile)
29-
if os.path.exists(confFile):
30-
oldconf = base.Conf()
31-
oldconf.readFromFile(confFile)
32-
gconf.updateConf(oldconf)
33-
else:
34-
gconf.init(workDir, confFile)
35-
if not config.checkConf(gconf):
36-
exit(1)
37-
if not config.checkEnv(gconf):
38-
exit(1)
39-
40-
gargs, subParser = config.checkArgs(gconf)
41-
if gargs:
42-
_build(gargs.sub_name, gconf, gargs, subParser)
43-

tbbl/admin.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import os
99
import subprocess
1010
from zrong import (slog)
11-
from zrong.base import (create_zip, DictBase)
12-
from zrong.ftp import (get_ftp, check_ftp_conf, upload_file, upload_dir)
11+
from zrong.base import (list_dir, create_zip, DictBase)
12+
from zrong.ftp import ( upload_file, upload_dir)
1313

1414
class AdminBase(object):
1515

@@ -26,22 +26,22 @@ def newConf():
2626
return None
2727

2828
def upload218Tool(self, filePath, remotePath, removeFile):
29-
ftpConf = DictBase(self.conf.ftp18_conf)
29+
ftpConf = self.conf.getFtpConf(self.args.ftp)
3030
ftpConf.start_path = ftpConf.tool_dir
3131
return upload_file(filePath, remotePath, ftpConf, removeFile)
3232

3333
def upload218Doc(self, dirName, uploadDir):
34-
ftpConf = DictBase(self.conf.ftp18_conf)
34+
ftpConf = self.conf.getFtpConf(self.args.ftp)
3535
ftpConf.start_path = ftpConf.doc_dir
3636
upload_dir(dirName, uploadDir, ftpConf)
3737

3838
def upload218Lib(self, filePath, remotePath):
39-
ftpConf = DictBase(self.conf.ftp18_conf)
39+
ftpConf = self.conf.getFtpConf(self.args.ftp)
4040
ftpConf.start_path = ftpConf.lib_dir
4141
return upload_file(filePath, remotePath, ftpConf, True)
4242

4343
def upload218Sim(self, filePath, remotePath, delFile=True):
44-
ftpConf = DictBase(self.conf.ftp18_conf)
44+
ftpConf = self.conf.getFtpConf(self.args.ftp)
4545
ftpConf.start_path = ftpConf.sim_dir
4646
return upload_file(filePath, remotePath, ftpConf, delFile)
4747

@@ -162,6 +162,44 @@ def lua(self):
162162
pre = len(srcDIR)+1
163163
self.upload218Lib(create_zip(files, pre), self.conf.lib_conf.lua)
164164

165+
def toluaauto(self, bindType):
166+
if not self.isAdmin():
167+
return
168+
inifile = None
169+
cwd = self.conf.getDistPath('tolua', 'auto')
170+
for f in list_dir(cwd):
171+
if f.endswith('.ini') \
172+
and f.startswith('cocos2dx_') \
173+
and bindType in f.lower():
174+
inifile = f
175+
if inifile:
176+
xarg = [self.conf.getExe('python2'), 'genbindings.py', inifile]
177+
slog.warning('toluaauto args: %s', xarg)
178+
slog.warning('toluaauto target path: %s', cwd)
179+
py = subprocess.Popen(xarg, cwd=cwd)
180+
py.wait()
181+
else:
182+
slog.error('Cannot find a file named %s!'%bindType)
183+
184+
def toluamanual(self, bindType):
185+
if not self.isAdmin():
186+
return
187+
toluafile = None
188+
cwd = self.conf.getDistPath('tolua', 'manual')
189+
for f in list_dir(cwd):
190+
if f.endswith('.tolua') \
191+
and bindType in f.lower():
192+
toluafile = f
193+
if toluafile:
194+
bindName = os.path.join(self.conf.getDistPath('tolua', 'manual'), toluafile)
195+
php = self.conf.getBin('quick/lib/compile_luabinding.php')
196+
xarg = [self.conf.getPHP(), php, '-pfx', 'cc', '-d',
197+
self.conf.getDistPath('runtime-src', 'Classes',
198+
'lua-bindings', 'manual'), bindName]
199+
subprocess.call(xarg)
200+
else:
201+
slog.error('Cannot find a file named %s!'%bindType)
202+
165203
def build(self):
166204
# After update self or rebuild conf, dismiss all others action.
167205
if self.args.reconf:
@@ -184,6 +222,12 @@ def build(self):
184222
if self.args.src:
185223
self.src()
186224
noAnyArgs = False
225+
if self.args.toluamanual:
226+
self.toluamanual(self.args.toluamanual)
227+
noAnyArgs = False
228+
if self.args.toluaauto:
229+
self.toluaauto(self.args.toluaauto)
230+
noAnyArgs = False
187231

188232
return noAnyArgs
189233

tbbl/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from jinja2 import Template
77
from zrong import slog
88
from zrong.base import (DictBase,write_by_templ,read_file,write_file)
9+
from tbbl import TEAM1201Error
910

1011
class ConfBase(DictBase):
1112

@@ -112,6 +113,17 @@ def getTemplSub(self, subName, keyName):
112113
subStr = read_file(subFile)
113114
return eval(subStr)[keyName]
114115

116+
def getFtpConf(self, ftpname):
117+
curFtp = ftpname if ftpname else self.ftp_conf.cur_ftp
118+
if not curFtp:
119+
raise TEAM1201Error('Cannnot get a ftp config name! '
120+
'Please check --ftp arg or '
121+
'set cur_ftp in section ftp_conf of config file.')
122+
ftpConf = self.ftp_conf[curFtp]
123+
if not ftpConf:
124+
raise TEAM1201Error('Cannnot get a ftp config object named %s!'%curFtp)
125+
return DictBase(ftpConf)
126+
115127
def absPath(*path):
116128
return os.path.abspath(os.path.join(*path))
117129

tbbl/config.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ def addCommonArgs(self, parser, *types):
5656
parser.add_argument('--vendor', type=str,
5757
default='team1201', choices=['team1201'],
5858
help='指定运营商。默认使用 team1201 。')
59+
elif typ == 'ftp':
60+
parser.add_argument('--ftp', type=str,
61+
choices=['18', '1201'],
62+
help='指定使用哪个 ftp 服务器。1201 是外网服务器。18 是内网服务器。'
63+
'若不提供此参数,则会使用配置文件中 ftp_conf.cur_ftp 的值。')
5964

6065
def addGitArgs(self, parser, git_conf, init):
6166
gitreponames = sorted(git_conf.keys())
@@ -68,19 +73,20 @@ def addGitArgs(self, parser, git_conf, init):
6873
def addAdmin(self, conf):
6974
parserAdmin = self.subParsers.add_parser('admin',
7075
help='管理员专用。一般为 zrong 使用。')
76+
self.addCommonArgs(parserAdmin, 'ftp')
7177
parserAdmin.add_argument('--src', action='store_true',
72-
help='打包 src 文件夹并上传到18 。当然包含 --lua 参数中的所有内容。')
78+
help='打包 src 文件夹并上传到 ftp 服务器 。当然包含 --lua 参数中的所有内容。')
7379
parserAdmin.add_argument('--res', action='store_true',
74-
help='打包 res 文件夹并上传到18。')
80+
help='打包 res 文件夹并上传到 ftp 服务器。')
7581
parserAdmin.add_argument('--reconf', action='store_true',
7682
help='重建 yhqb_conf.py.')
7783
parserAdmin.add_argument('--cocos', action='store_true',
78-
help='(zrong 专用)打包 cocos2d-x 源码,并上传到18。')
84+
help='(zrong 专用)打包 cocos2d-x 源码,并上传到 ftp 服务器。')
7985
parserAdmin.add_argument('--lua', action='store_true',
8086
help='(zrong 专用)打包 lua 框架(包含src目录下的'
81-
'quick、cocos、zrong 三个文件夹)并上传到18。')
87+
'quick、cocos、zrong 三个文件夹)并上传到 ftp 服务器。')
8288
parserAdmin.add_argument('--cpp', action='store_true',
83-
help='(zrong 专用)打包 frameworks/runtime-src 文件夹并上传到18。')
89+
help='(zrong 专用)打包 frameworks/runtime-src 文件夹并上传到 ftp 服务器。')
8490
parserAdmin.add_argument('--toluaauto', type=str,
8591
choices = ['filter', 'dragonbones', 'webview'],
8692
help='(zrong 专用)创建 lua 自动绑定文件。')
@@ -105,6 +111,7 @@ def addUpdate(self, conf):
105111
help='在 git 仓库中执行 "git reset --hard" 并推送(pull)。')
106112
parserUpdate.add_argument('-a', '--all', action='store_true',
107113
help='采用默认设置更新所有。')
114+
self.addCommonArgs(parserUpdate, 'ftp')
108115
parserUpdate.add_argument('--cocos', action='store_true',
109116
help='更新 cocos2d-x 框架。目标路径 client/frameworks/cocos2d-x 。')
110117
parserUpdate.add_argument('--lua', action='store_true',
@@ -148,8 +155,13 @@ def addRes(self, conf):
148155
help='使用默认设置处理所有资源。')
149156
parserRes.add_argument('--plst', type=str, nargs='*',
150157
help='处理碎图图像文件。'
151-
'将 plst 文件夹中的碎图转换成 SpriteSheet 格式。'
158+
'将 plst 文件夹中的碎图转换成 sprite sheet 格式。'
152159
'目标文件夹为 client/res/plst 。若不提供具体的文件,则处理所有文件。')
160+
parserRes.add_argument('--disable-rotation', action='store_true',
161+
help='仅当处理 --plst 时有效。'
162+
'在调用 Texture Packer 转换 sprite sheet 的时候禁用图片旋转。'
163+
'由于滤镜系统的 bug,滤镜在处理旋转的 sprite sheet 时无法显示图片。'
164+
'使用这种方式可以避免这个 bug。')
153165
parserRes.add_argument('--pdir', type=str, nargs='*',
154166
help='处理 pdir 中的独立图像资源。'
155167
'目标文件夹为 client/res/pdir 。'
@@ -172,14 +184,22 @@ def addRes(self, conf):
172184
'复制已存在的 sprite sheet,'
173185
'复制已存在的 ani_def_*.lua 动画定义文件。'
174186
'目标文件夹为 client/res/ani 。若不提供具体的文件,则处理所有文件。')
187+
parserRes.add_argument('--gen-def', action='store_true',
188+
help='仅当 --ani 提供了具体值时有效。'
189+
'自动生成指定的 ani 动画文件的 ani_def_*.lua 。')
190+
parserRes.add_argument('--tp-options', type=str, default='',
191+
help='仅当处理 --plst 和 --ani 时有效。'
192+
'在调用 TexturePacker 转换 sprite sheet 的时候传递指定的参数。'
193+
'详细参数说明请参考 TexturePacker 的命令行帮助。'
194+
'传递的参数必须使用 \\ 来转义,第一个参数之前必须加一个转义符和空格,'
195+
'否则会被命令行认为是一个正常的参数而非当前参数的值。'
196+
'例如,要传递 --verbose --format cocos2d 这2个参数,则这样使用:'
197+
'--tp-options \\ --verbose\\ --format\\ cocos2d')
175198
parserRes.add_argument('--oth', type=str, nargs='*',
176199
help='处理其它资源。目标文件夹为 client/res/oth 。'
177200
'若不提供具体的文件,则处理所有文件。')
178201
parserRes.add_argument('--test', action='store_true',
179202
help='处理测试用的资源资源。目标文件夹为 client/res/test 。')
180-
parserRes.add_argument('--gen-def', action='store_true',
181-
help='仅当 --ani 提供了具体值时有效。'
182-
'自动生成指定的 ani 动画文件的 ani_def_*.lua 。')
183203
parserRes.add_argument('--gettext', type=str,
184204
choices=['mo','po'],
185205
help='转换语言文件。'

tbbl/conv/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__all__ = ['md2lua']
1+
__all__ = ['md2lua', 'tp']

tbbl/conv/md2lua.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
99
# HomePage: http://weibo.com/5d13
1010
# Version: 0.1.1
11-
# LastChange: 2014-11-25 zrong
11+
# LastChange: 2015-05-06 zrong
1212
# History:
1313
#=============================================================================
1414
'''
1515

1616
import sys
1717
import os
18-
from zrong.base import (write_file, read_file,
19-
slog, list_dir)
18+
from zrong import (slog)
19+
from zrong.base import (write_file, read_file, list_dir)
2020

2121
lineno = 0
2222
verNum = 0
@@ -92,7 +92,7 @@ def proc(fullname):
9292
flag = 1
9393
slog.info('code: %s, title: %s', p.code, p.title)
9494
except:
95-
slog.info("%s has err!!!%s" ,lineno,line)
95+
slog.error("%s has err!!!%s" ,lineno,line)
9696
return
9797
continue
9898
elif flag == 1:

tbbl/conv/tp.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
########################################
2+
# tp.py
3+
#
4+
# Convert images to sprite sheet by TexturePacker
5+
# Author: zrong
6+
# Creation: 2015-05-06
7+
########################################
8+
9+
import os
10+
import shutil
11+
import subprocess
12+
from zrong import slog
13+
14+
def _get_args_list(options):
15+
return options.strip().split(' ')
16+
17+
def convert_to_cocos2d(tpexe, source, output, dirname, disable_rotation=False, options=None):
18+
plist_file = os.path.join(output, dirname+".plist")
19+
png_file = os.path.join(output, dirname+".png")
20+
imagefolder = os.path.join(source, dirname)
21+
xargs = ["--sheet", png_file, "--data", plist_file]
22+
if options:
23+
xargs = xargs + _get_args_list(options)
24+
if disable_rotation:
25+
xargs.append('--disable-rotation')
26+
succ = convert_by_options(tpexe, xargs, imagefolder)
27+
if succ:
28+
slog.info("\n.... converting %s", dirname)
29+
30+
def convert_by_options(tpexe, options, imagefolder):
31+
"""
32+
options must be a list or a string
33+
"""
34+
xargs = [tpexe]
35+
argslist = None
36+
if isinstance(options, list):
37+
argslist = options
38+
elif isinstance(options, str):
39+
argslist = _get_args_list(options)
40+
if not argslist:
41+
slog.error("Please give some options.")
42+
return False
43+
for value in argslist:
44+
xargs.append(value)
45+
xargs.append(imagefolder)
46+
tpout = subprocess.check_output(xargs, universal_newlines=True)
47+
slog.info("Call TexturePacker, command line is: \n")
48+
slog.warning("%s\n", " ".join(xargs))
49+
slog.info("%s\n", tpout)
50+
return True

tbbl/res.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import zrong.lua as lua
1616
from zrong.gettext import Gettext
1717
from tbbl.base import (write_by_jinja, print_sep)
18+
from tbbl.conv import tp
1819

1920
class AniDef(object):
2021
def __init__(self, conf, aniDir, aniArg, gendef):
@@ -246,17 +247,10 @@ def _commonProcess(self, dirList, souName, outName=None):
246247
print_sep('Process %s in directory [%s] has done.'
247248
%(dirList, souName), False, 40)
248249

249-
def _convertSS(self, sourceDir, outputDir, dirName):
250-
plist_file = os.path.join(outputDir, dirName+".plist")
251-
png_file = os.path.join(outputDir, dirName+".png")
252-
slog.info("\n.... converting %s", dirName)
253-
tpOut = subprocess.check_output([
254-
self.conf.getExe("tp"),
255-
"--sheet", png_file,
256-
"--data", plist_file,
257-
os.path.join(sourceDir, dirName)
258-
], universal_newlines=True)
259-
slog.info("%s\n", tpOut)
250+
def _convertSS(self, sourceDir, outputDir, dirName, disrot=False):
251+
# print("_convertSS", self.args.tp_options)
252+
tp.convert_to_cocos2d(self.conf.getExe("tp"), sourceDir, outputDir,
253+
dirName, disrot, self.args.tp_options)
260254

261255
def plst(self, plist):
262256
print_sep('Start to process %s in directory plst.'
@@ -277,7 +271,7 @@ def plst(self, plist):
277271
sourceDir = tmpDir
278272
print_sep('Start to convert spritesheet.')
279273
for dir_name in plist:
280-
self._convertSS(sourceDir, outputDir, dir_name)
274+
self._convertSS(sourceDir, outputDir, dir_name, self.args.disable_rotation)
281275
print_sep('Spritsheet converting has done.', False)
282276
if tmpDir:
283277
slog.info('Remove temporary directory [%s].'%tmpDir)

0 commit comments

Comments
 (0)