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

Delta Between Two Patch Sets: abp/filters/diff_script.py

Issue 29884571: Issue 6945 - Add script to make filter list diffs (Closed) Base URL: https://hg.adblockplus.org/python-abp/
Left Patch Set: Handle non-ascii, remove extraneous test Created Sept. 21, 2018, 8:33 a.m.
Right Patch Set: Fix docstring Created Sept. 26, 2018, 6:20 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « README.md ('k') | abp/filters/renderer.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 """Command line script for rendering Adblock Plus filter list diffs.""" 16 """Command line script for rendering Adblock Plus filter list diffs."""
17 17
18 from __future__ import print_function 18 from __future__ import print_function
19
19 import argparse 20 import argparse
Sebastian Noack 2018/09/21 11:51:21 Nit: __future__ imports are special, so I would se
rhowell 2018/09/24 22:05:21 Done.
20 import io 21 import io
21 import sys 22 import sys
22 23
23 from .sources import NotFound
24 from .renderer import render_diff 24 from .renderer import render_diff
25
25 __all__ = ['main'] 26 __all__ = ['main']
Sebastian Noack 2018/09/21 11:51:21 Nit: There should be blank link above, here as wel
rhowell 2018/09/24 22:05:21 Done.
26 27
27 28
28 def parse_args(): 29 def parse_args():
29 parser = argparse.ArgumentParser(description='Render a filter list diff.') 30 parser = argparse.ArgumentParser(description='Render a filter list diff.')
30 parser.add_argument( 31 parser.add_argument(
31 'base', help='the older filter list that needs to be updated', 32 'base', help='the older filter list that needs to be updated',
32 nargs='?') 33 nargs='?')
33 parser.add_argument( 34 parser.add_argument(
34 'latest', help='the most recent version of the filter list', 35 'latest', help='the most recent version of the filter list',
35 nargs='?') 36 nargs='?')
36 parser.add_argument( 37 parser.add_argument(
37 'outfile', help='output file for filter list diff', 38 'outfile', help='output file for filter list diff',
38 default='-', nargs='?') 39 default='-', nargs='?')
39 return parser.parse_args() 40 return parser.parse_args()
40 41
41 42
42 def main(args_in=None): 43 def main():
Sebastian Noack 2018/09/21 11:51:20 The args_in argument seems to be unused, and I don
rhowell 2018/09/24 22:05:21 Oops, I should've removed this when removing the e
43 """Entry point for the diff rendering script (diffrender).""" 44 """Entry point for the diff rendering script (fldiff)."""
44 args = parse_args() 45 args = parse_args()
45 46
46 with io.open(args.base, 'r') as base, io.open(args.latest, 'r') as latest: 47 with io.open(args.base, 'r', encoding='utf-8') as base, \
Sebastian Noack 2018/09/21 11:51:21 Unlike below, you don't specify an encoding when c
rhowell 2018/09/24 22:05:21 Done.
47 try: 48 io.open(args.latest, 'r', encoding='utf-8') as latest:
48 lines = render_diff(base, latest)
49 if args.outfile == '-':
50 outfile = io.open(sys.stdout.fileno(), 'w',
51 closefd=False,
52 encoding=sys.stdout.encoding or 'utf-8')
53 else:
54 outfile = io.open(args.outfile, 'w', encoding='utf-8')
55 49
56 with outfile: 50 lines = render_diff(base, latest)
57 for line in lines: 51 if args.outfile == '-':
58 print(line, file=outfile) 52 outfile = io.open(sys.stdout.fileno(), 'w',
59 except NotFound as exc: 53 closefd=False,
Sebastian Noack 2018/09/21 11:51:20 Can we even run into this exception since we neith
rhowell 2018/09/24 22:05:21 I guess not. Removed it.
60 sys.exit(exc) 54 encoding=sys.stdout.encoding or 'utf-8')
55 else:
56 outfile = io.open(args.outfile, 'w', encoding='utf-8')
57
58 with outfile:
59 for line in lines:
60 print(line, file=outfile)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld