LEFT | RIGHT |
(no file at all) | |
| 1 #!/usr/bin/env python |
| 2 # coding: utf-8 |
| 3 |
| 4 import sys, os, codecs, re |
| 5 baseDir = os.path.abspath(os.path.dirname(__file__)) |
| 6 sys.path.append(os.path.join(baseDir, 'adblockplus', 'buildtools', 'jshydra')) |
| 7 from abp_rewrite import doRewrite |
| 8 |
| 9 def toCString(string): |
| 10 string = string.replace('\\', '\\\\').replace('"', '\\"') |
| 11 string = string.replace('\r', '').replace('\n', '\\n') |
| 12 return '"%s"' % string.encode('utf-8') |
| 13 |
| 14 def convert(convertFiles, verbatimFiles, outFile): |
| 15 outHandle = open(outFile, 'wb') |
| 16 print >>outHandle, 'const char* jsSources[] = {' |
| 17 |
| 18 for file in verbatimFiles: |
| 19 fileHandle = codecs.open(file, 'rb', encoding='utf-8') |
| 20 print >>outHandle, toCString(os.path.basename(file)) + ',' |
| 21 print >>outHandle, toCString(fileHandle.read()) + ',' |
| 22 fileHandle.close() |
| 23 |
| 24 convertFiles = map(lambda f: f if os.path.isabs(f) else os.path.join(baseDir,
f), convertFiles) |
| 25 converted = doRewrite(convertFiles, ['module=true', 'source_repo=https://hg.ad
blockplus.org/adblockplus/']) |
| 26 print >>outHandle, toCString('adblockplus.js') + ',' |
| 27 print >>outHandle, toCString(converted) + ',' |
| 28 |
| 29 print >>outHandle, '0, 0' |
| 30 print >>outHandle, '};' |
| 31 |
| 32 if __name__ == '__main__': |
| 33 args = sys.argv[1:] |
| 34 outFile = args.pop() |
| 35 |
| 36 verbatimFiles = [] |
| 37 while len(args): |
| 38 file = args.pop() |
| 39 if file == '--': |
| 40 break |
| 41 else: |
| 42 verbatimFiles.insert(0, file) |
| 43 |
| 44 convertFiles = args |
| 45 convert(convertFiles, verbatimFiles, outFile) |
LEFT | RIGHT |