Index: convert_js.py |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/convert_js.py |
@@ -0,0 +1,45 @@ |
+#!/usr/bin/env python |
+# coding: utf-8 |
+ |
+import sys, os, codecs, re |
+base_dir = os.path.abspath(os.path.dirname(__file__)) |
Felix Dahlke
2013/03/15 15:18:36
Everything else is named using camel case, why not
|
+sys.path.append(os.path.join(base_dir, 'adblockplus', 'buildtools', 'jshydra')) |
+from abp_rewrite import doRewrite |
+ |
+def toCString(string): |
+ string = string.replace('\\', '\\\\').replace('"', '\\"') |
+ string = string.replace('\r', '').replace('\n', '\\n') |
+ return '"%s"' % string.encode('utf-8') |
+ |
+def convert(convertFiles, verbatimFiles, outFile): |
+ outHandle = open(outFile, 'wb') |
+ print >>outHandle, 'const char* jsSources[] = {' |
+ |
+ for file in verbatimFiles: |
+ 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(base_dir, f), convertFiles) |
+ converted = doRewrite(convertFiles, ['module=true', 'source_repo=https://hg.adblockplus.org/adblockplus/']) |
+ print >>outHandle, toCString('adblockplus.js') + ',' |
+ print >>outHandle, toCString(converted) + ',' |
+ |
+ 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 |
+ else: |
+ verbatimFiles.insert(0, file) |
+ |
+ convertFiles = args |
+ convert(convertFiles, verbatimFiles, outFile) |