Created
September 6, 2015 05:34
-
-
Save coneo/ab10ceb634db39265c50 to your computer and use it in GitHub Desktop.
根据一定规则进行cpp文件名的合并
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| # Filename: gencomsrc.py | |
| # Author: HongXiaoqiang | |
| # mail: prove_hxq@gmail.com | |
| import os, sys | |
| import glob | |
| ignoreNum = 2 # 忽略最后几个文件 | |
| cellSize = 2 # 每个新文件包含的cpp个数 | |
| filebase = "com_multi_src" # 文件基础名 | |
| #删除旧文件 | |
| delfiles = glob.glob(filebase+'*') | |
| for d in delfiles: | |
| os.remove(d) | |
| srcs = glob.glob('*.cpp') | |
| srcpairs = [] | |
| for src in srcs: | |
| size = os.path.getsize(src) | |
| srcpairs.append((size, src)) | |
| srcpairs.sort(key=lambda s: s[0]) | |
| print 'there are', len(srcpairs), 'cpp!' | |
| if len(srcpairs) < ignoreNum: | |
| print 'need more than 10 cpp files' | |
| sys.exit(0) | |
| srcpairs = srcpairs[0:-ignoreNum] | |
| times = 0 | |
| index = 0 | |
| while len(srcpairs) >= 2: | |
| if times >= 5: | |
| index += 1 | |
| times = 0 | |
| filename = filebase + str(index) + ".cpp" | |
| dumpstr1 = "#include \"" + srcpairs[0][1] + "\"\n" | |
| dumpstr2 = "#include \"" + srcpairs[-1][1] + "\"\n" | |
| dumpfile = open(filename, "a") | |
| dumpfile.write(dumpstr1) | |
| dumpfile.write(dumpstr2) | |
| del srcpairs[0] | |
| del srcpairs[-1] | |
| times += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment