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

Side by Side Diff: 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/
Patch Set: Use io.open instead of open() Created Sept. 18, 2018, 5:22 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 | setup.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-present eyeo GmbH
3 #
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
6 # published by the Free Software Foundation.
7 #
8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
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/>.
15
16 """Command line script for rendering Adblock Plus filter list diffs."""
17
18 import argparse
19 import io
20 import sys
21
22 from collections import namedtuple
23
24 from .sources import NotFound
25 from .renderer import render_diff
26 __all__ = ['main']
27
28
29 def parse_args():
30 parser = argparse.ArgumentParser(description='Render a filter list diff.')
31 parser.add_argument(
32 'base', help='the older filter list that needs to be updated',
33 default='-', nargs='?')
Vasily Kuznetsov 2018/09/19 18:40:04 It seems that base and latest should be mandatory
rhowell 2018/09/21 08:37:09 Done.
34 parser.add_argument(
35 'latest', help='the most recent version of the filter list',
36 default='-', nargs='?')
37 parser.add_argument(
38 'outfile', help='output file for filter list diff',
39 default='-', nargs='?')
40 return parser.parse_args()
41
42
43 def main(args_in=None):
44 """Entry point for the diff rendering script (diffrender)."""
45 if args_in:
46 Parse = namedtuple('Test', 'base, latest, outfile')
Vasily Kuznetsov 2018/09/19 18:40:04 Are we going to use this code path? If yes, I woul
rhowell 2018/09/21 08:37:08 Good point. This was helpful for me while testing,
47 args = Parse(args_in['base'], args_in['latest'], args_in['outfile'])
48 else:
49 args = parse_args()
50
51 with io.open(args.base, 'r') as base, io.open(args.latest, 'r') as latest:
52 try:
53 lines = render_diff(base, latest)
Sebastian Noack 2018/09/18 19:13:18 Iterating over a file-object yields each line incl
Vasily Kuznetsov 2018/09/19 18:40:04 Actually metadata is also stripped of the line end
Sebastian Noack 2018/09/20 16:59:12 Ah, right, that is because by default . doesn't ma
rhowell 2018/09/21 08:37:09 Acknowledged.
54 if args.outfile == '-':
55 for line in lines:
56 sys.stdout.write(line + '\n')
Sebastian Noack 2018/09/18 19:13:18 Does that work on Python 2 if there are any non-as
Sebastian Noack 2018/09/20 16:59:12 For reference, the problem is that in Python 2 if
Vasily Kuznetsov 2018/09/21 07:48:42 This is more or less the approach that we took in
rhowell 2018/09/21 08:37:08 This approach seems to be working well. Thanks, I
Sebastian Noack 2018/09/26 11:55:47 I just noticed, we might have the same issue in re
Vasily Kuznetsov 2018/09/26 16:50:40 Yeah, makes sense. Perhaps we could move this piec
57 else:
58 with io.open(args.outfile, 'w', encoding='utf-8') as out_fp:
59 for line in lines:
60 out_fp.write(line + '\n')
61 except NotFound as exc:
62 sys.exit(exc)
OLDNEW
« no previous file with comments | « no previous file | setup.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld