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: rebase Created April 21, 2016, 11:41 a.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 4 import sys
5 import os 5 import os
6 import codecs 6 import codecs
7 import re 7 import re
8 import json 8 import json
9 import argparse 9 import argparse
10 import xml.dom.minidom as minidom 10 import xml.dom.minidom as minidom
11 11
12 baseDir = os.path.abspath(os.path.dirname(__file__)) 12 baseDir = os.path.abspath(os.path.dirname(__file__))
13 sys.path.append(os.path.join(baseDir, 'adblockplus', 'buildtools', 'jshydra')) 13 sys.path.append(os.path.join(baseDir, 'adblockpluscore', 'buildtools', 'jshydra' ))
14 from abp_rewrite import doRewrite 14 from abp_rewrite import doRewrite
15 15
16 16
17 class CStringArray: 17 class CStringArray:
18 def __init__(self): 18 def __init__(self):
19 self._buffer = [] 19 self._buffer = []
20 self._strings = [] 20 self._strings = []
21 21
22 def add(self, string): 22 def add(self, string):
23 string = string.encode('utf-8').replace('\r', '') 23 string = string.encode('utf-8').replace('\r', '')
(...skipping 30 matching lines...) Expand all
54 for name, value in node.attributes.items(): 54 for name, value in node.attributes.items():
55 result[name] = value 55 result[name] = value
56 data.append(result) 56 data.append(result)
57 fileName = os.path.basename(file) 57 fileName = os.path.basename(file)
58 array.add(fileName) 58 array.add(fileName)
59 array.add('require.scopes["%s"] = %s;' % (fileName, json.dumps(data))) 59 array.add('require.scopes["%s"] = %s;' % (fileName, json.dumps(data)))
60 fileHandle.close() 60 fileHandle.close()
61 61
62 62
63 def convertJsFile(array, file): 63 def convertJsFile(array, file):
64 converted = doRewrite([os.path.abspath(file)], ['module=true', 'source_repo= https://hg.adblockplus.org/adblockplus/']) 64 converted = doRewrite([os.path.abspath(file)], ['module=true', 'source_repo= https://hg.adblockplus.org/adblockpluscore/'])
65 array.add(os.path.basename(file)) 65 array.add(os.path.basename(file))
66 array.add(converted) 66 array.add(converted)
67 67
68 68
69 def convert(verbatimBefore, convertFiles, verbatimAfter, outFile): 69 def convert(verbatimBefore, convertFiles, verbatimAfter, outFile):
70 array = CStringArray() 70 array = CStringArray()
71 addFilesVerbatim(array, verbatimBefore) 71 addFilesVerbatim(array, verbatimBefore)
72 72
73 for file in convertFiles: 73 for file in convertFiles:
74 if file.endswith('.xml'): 74 if file.endswith('.xml'):
(...skipping 12 matching lines...) Expand all
87 parser.add_argument('--before', metavar='verbatim_file', nargs='+', 87 parser.add_argument('--before', metavar='verbatim_file', nargs='+',
88 help='JavaScript file to include verbatim at the beginni ng') 88 help='JavaScript file to include verbatim at the beginni ng')
89 parser.add_argument('--convert', metavar='file_to_convert', nargs='+', 89 parser.add_argument('--convert', metavar='file_to_convert', nargs='+',
90 help='JavaScript files to convert') 90 help='JavaScript files to convert')
91 parser.add_argument('--after', metavar='verbatim_file', nargs='+', 91 parser.add_argument('--after', metavar='verbatim_file', nargs='+',
92 help='JavaScript file to include verbatim at the end') 92 help='JavaScript file to include verbatim at the end')
93 parser.add_argument('output_file', 93 parser.add_argument('output_file',
94 help='output from the conversion') 94 help='output from the conversion')
95 args = parser.parse_args() 95 args = parser.parse_args()
96 convert(args.before, args.convert, args.after, args.output_file) 96 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