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

Side by Side Diff: convert_js.py

Issue 29340602: Issue 2596 - change adblockplus to adblockpluscore (Closed)
Patch Set: Created April 19, 2016, 8:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | dependencies » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 3
4 import sys, os, codecs, re, json, argparse 4 import sys, os, codecs, re, json, argparse
5 import xml.dom.minidom as minidom 5 import xml.dom.minidom as minidom
6 baseDir = os.path.abspath(os.path.dirname(__file__)) 6 baseDir = os.path.abspath(os.path.dirname(__file__))
7 sys.path.append(os.path.join(baseDir, 'adblockplus', 'buildtools', 'jshydra')) 7 sys.path.append(os.path.join(baseDir, 'adblockpluscore', 'buildtools', 'jshydra' ))
8 from abp_rewrite import doRewrite 8 from abp_rewrite import doRewrite
9 9
10 class CStringArray: 10 class CStringArray:
11 def __init__(self): 11 def __init__(self):
12 self._buffer = [] 12 self._buffer = []
13 self._strings = [] 13 self._strings = []
14 14
15 def add(self, string): 15 def add(self, string):
16 string = string.encode('utf-8').replace('\r', '') 16 string = string.encode('utf-8').replace('\r', '')
17 self._strings.append('std::string(buffer + %i, %i)' % (len(self._buffer), le n(string))) 17 self._strings.append('std::string(buffer + %i, %i)' % (len(self._buffer), le n(string)))
(...skipping 26 matching lines...) Expand all
44 result = {'type': node.tagName} 44 result = {'type': node.tagName}
45 for name, value in node.attributes.items(): 45 for name, value in node.attributes.items():
46 result[name] = value 46 result[name] = value
47 data.append(result) 47 data.append(result)
48 fileName = os.path.basename(file) 48 fileName = os.path.basename(file)
49 array.add(fileName) 49 array.add(fileName)
50 array.add('require.scopes["%s"] = %s;' % (fileName, json.dumps(data))) 50 array.add('require.scopes["%s"] = %s;' % (fileName, json.dumps(data)))
51 fileHandle.close() 51 fileHandle.close()
52 52
53 def convertJsFile(array, file): 53 def convertJsFile(array, file):
54 converted = doRewrite([os.path.abspath(file)], ['module=true', 'source_repo=ht tps://hg.adblockplus.org/adblockplus/']) 54 converted = doRewrite([os.path.abspath(file)], ['module=true', 'source_repo=ht tps://hg.adblockplus.org/adblockpluscore/'])
55 array.add(os.path.basename(file)) 55 array.add(os.path.basename(file))
56 array.add(converted) 56 array.add(converted)
57 57
58 def convert(verbatimBefore, convertFiles, verbatimAfter, outFile): 58 def convert(verbatimBefore, convertFiles, verbatimAfter, outFile):
59 array = CStringArray() 59 array = CStringArray()
60 addFilesVerbatim(array, verbatimBefore) 60 addFilesVerbatim(array, verbatimBefore)
61 61
62 for file in convertFiles: 62 for file in convertFiles:
63 if file.endswith('.xml'): 63 if file.endswith('.xml'):
64 convertXMLFile(array, file) 64 convertXMLFile(array, file)
(...skipping 11 matching lines...) Expand all
76 parser.add_argument('--before', metavar='verbatim_file', nargs='+', 76 parser.add_argument('--before', metavar='verbatim_file', nargs='+',
77 help='JavaScript file to include verbatim at the beginning') 77 help='JavaScript file to include verbatim at the beginning')
78 parser.add_argument('--convert', metavar='file_to_convert', nargs='+', 78 parser.add_argument('--convert', metavar='file_to_convert', nargs='+',
79 help='JavaScript files to convert') 79 help='JavaScript files to convert')
80 parser.add_argument('--after', metavar='verbatim_file', nargs='+', 80 parser.add_argument('--after', metavar='verbatim_file', nargs='+',
81 help='JavaScript file to include verbatim at the end') 81 help='JavaScript file to include verbatim at the end')
82 parser.add_argument('output_file', 82 parser.add_argument('output_file',
83 help='output from the conversion') 83 help='output from the conversion')
84 args = parser.parse_args() 84 args = parser.parse_args()
85 convert(args.before, args.convert, args.after, args.output_file) 85 convert(args.before, args.convert, args.after, args.output_file)
OLDNEW
« no previous file with comments | « no previous file | dependencies » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld