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

Unified 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: Handle non-ascii, remove extraneous test Created Sept. 21, 2018, 8:33 a.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 | setup.py » ('j') | tests/test_differ.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: abp/filters/diff_script.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/abp/filters/diff_script.py
@@ -0,0 +1,60 @@
+# This file is part of Adblock Plus <https://adblockplus.org/>,
+# Copyright (C) 2006-present eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+"""Command line script for rendering Adblock Plus filter list diffs."""
+
+from __future__ import print_function
+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.
+import io
+import sys
+
+from .sources import NotFound
+from .renderer import render_diff
+__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.
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(description='Render a filter list diff.')
+ parser.add_argument(
+ 'base', help='the older filter list that needs to be updated',
+ nargs='?')
+ parser.add_argument(
+ 'latest', help='the most recent version of the filter list',
+ nargs='?')
+ parser.add_argument(
+ 'outfile', help='output file for filter list diff',
+ default='-', nargs='?')
+ return parser.parse_args()
+
+
+def main(args_in=None):
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
+ """Entry point for the diff rendering script (diffrender)."""
+ args = parse_args()
+
+ with io.open(args.base, 'r') as base, io.open(args.latest, 'r') as latest:
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.
+ try:
+ lines = render_diff(base, latest)
+ if args.outfile == '-':
+ outfile = io.open(sys.stdout.fileno(), 'w',
+ closefd=False,
+ encoding=sys.stdout.encoding or 'utf-8')
+ else:
+ outfile = io.open(args.outfile, 'w', encoding='utf-8')
+
+ with outfile:
+ for line in lines:
+ print(line, file=outfile)
+ except NotFound as exc:
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.
+ sys.exit(exc)
« no previous file with comments | « no previous file | setup.py » ('j') | tests/test_differ.py » ('J')

Powered by Google App Engine
This is Rietveld