| Index: convert_js.py |
| =================================================================== |
| --- a/convert_js.py |
| +++ b/convert_js.py |
| @@ -9,40 +9,48 @@ from abp_rewrite import doRewrite |
| def toCString(string): |
| string = string.replace('\\', '\\\\').replace('"', '\\"') |
| string = string.replace('\r', '').replace('\n', '\\n') |
| # Work around MSVC line length limitation |
| #(see http://msdn.microsoft.com/en-us/library/dddywwsc(v=vs.80).aspx) |
| string = re.sub(r'(.{16000})(.)', r'\1"\n"\2', string, re.S) |
| return '"%s"' % string.encode('utf-8') |
| -def convert(convertFiles, verbatimFiles, outFile): |
| +def convert(verbatimBefore, convertFiles, verbatimAfter, outFile): |
| outHandle = open(outFile, 'wb') |
| print >>outHandle, 'const char* jsSources[] = {' |
| - for file in verbatimFiles: |
| + for file in verbatimBefore: |
| fileHandle = codecs.open(file, 'rb', encoding='utf-8') |
| print >>outHandle, toCString(os.path.basename(file)) + ',' |
| print >>outHandle, toCString(fileHandle.read()) + ',' |
| fileHandle.close() |
| convertFiles = map(lambda f: f if os.path.isabs(f) else os.path.join(baseDir, f), convertFiles) |
| converted = doRewrite(convertFiles, ['module=true', 'source_repo=https://hg.adblockplus.org/adblockplus/']) |
| print >>outHandle, toCString('adblockplus.js') + ',' |
| print >>outHandle, toCString(converted) + ',' |
| + for file in verbatimAfter: |
|
Felix Dahlke
2013/04/16 15:14:33
Given how this is the same code as above, I think
|
| + fileHandle = codecs.open(file, 'rb', encoding='utf-8') |
| + print >>outHandle, toCString(os.path.basename(file)) + ',' |
| + print >>outHandle, toCString(fileHandle.read()) + ',' |
| + fileHandle.close() |
| + |
| print >>outHandle, '0, 0' |
| print >>outHandle, '};' |
| if __name__ == '__main__': |
| args = sys.argv[1:] |
| outFile = args.pop() |
| - verbatimFiles = [] |
| - while len(args): |
| - file = args.pop() |
| - if file == '--': |
| - break |
| + verbatimBefore = [] |
| + verbatimAfter = [] |
| + convertFiles = [] |
| + for fileName in args: |
| + if fileName.startswith('before='): |
| + verbatimBefore.append(fileName.replace('before=', '')) |
| + elif fileName.startswith('after='): |
| + verbatimAfter.append(fileName.replace('after=', '')) |
| else: |
| - verbatimFiles.insert(0, file) |
| + convertFiles.append(fileName) |
| - convertFiles = args |
| - convert(convertFiles, verbatimFiles, outFile) |
| + convert(verbatimBefore, convertFiles, verbatimAfter, outFile) |