Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: convert_js.py

Issue 10329009: Changes to convert_js.py to support gyp restrictions (Closed)
Patch Set: Created April 18, 2013, 6:56 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | libadblockplus.gyp » ('j') | libadblockplus.gyp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: convert_js.py
===================================================================
--- a/convert_js.py
+++ b/convert_js.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# coding: utf-8
-import sys, os, codecs, re
+import sys, os, codecs, re, argparse
baseDir = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.join(baseDir, 'adblockplus', 'buildtools', 'jshydra'))
from abp_rewrite import doRewrite
@@ -27,7 +27,9 @@
printFilesVerbatim(outHandle, verbatimBefore)
- convertFiles = map(lambda f: f if os.path.isabs(f) else os.path.join(baseDir, f), convertFiles)
+ # We should trust that gyp is giving us the correct path names. In case we can't, however, the
+ # following is commented out rather than removed. We can add an optional argument for it if needed.
+ #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) + ','
@@ -38,18 +40,14 @@
print >>outHandle, '};'
if __name__ == '__main__':
- args = sys.argv[1:]
- outFile = args.pop()
-
- 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:
- convertFiles.append(fileName)
-
- convert(verbatimBefore, convertFiles, verbatimAfter, outFile)
+ parser = argparse.ArgumentParser(description='Convert JavaScript files')
+ parser.add_argument('--before', metavar='verbatim_file', nargs='+',
+ help='JavaScript file to include verbatim at the beginning')
+ parser.add_argument('--convert', metavar='file_to_convert', nargs='+',
+ help='JavaScript files to convert')
+ parser.add_argument('--after', metavar='verbatim_file', nargs='+',
+ help='JavaScript file to include verbatim at the end')
+ parser.add_argument('output_file',
+ help='output from the conversion')
+ args = parser.parse_args()
+ convert(args.before, args.convert, args.after, args.output_file)
« no previous file with comments | « no previous file | libadblockplus.gyp » ('j') | libadblockplus.gyp » ('J')

Powered by Google App Engine
This is Rietveld