Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # coding: utf-8 | 2 # coding: utf-8 |
3 | 3 |
4 # This file is part of Adblock Plus <https://adblockplus.org/>, | 4 # This file is part of Adblock Plus <https://adblockplus.org/>, |
5 # Copyright (C) 2006-2015 Eyeo GmbH | 5 # Copyright (C) 2006-2015 Eyeo GmbH |
6 # | 6 # |
7 # Adblock Plus is free software: you can redistribute it and/or modify | 7 # Adblock Plus is free software: you can redistribute it and/or modify |
8 # it under the terms of the GNU General Public License version 3 as | 8 # it under the terms of the GNU General Public License version 3 as |
9 # published by the Free Software Foundation. | 9 # published by the Free Software Foundation. |
10 # | 10 # |
(...skipping 27 matching lines...) Expand all Loading... | |
38 stdout=devnull) | 38 stdout=devnull) |
39 else: | 39 else: |
40 subprocess.check_call(("hg", "clone", config["abp2blocklist_url"], | 40 subprocess.check_call(("hg", "clone", config["abp2blocklist_url"], |
41 abp2blocklist_path), stdout=devnull) | 41 abp2blocklist_path), stdout=devnull) |
42 subprocess.check_call(("npm", "install"), cwd=abp2blocklist_path, | 42 subprocess.check_call(("npm", "install"), cwd=abp2blocklist_path, |
43 stdout=devnull) | 43 stdout=devnull) |
44 | 44 |
45 def download_filter_list(url): | 45 def download_filter_list(url): |
46 with closing(urllib2.urlopen(url)) as response: | 46 with closing(urllib2.urlopen(url)) as response: |
47 body = response.read() | 47 body = response.read() |
48 version = re.search(r"^(?:[^[!])|!\s*Version:\s*(.+)$", | 48 version = re.search(r"^(?:[^[!])|^!\s*Version:\s*(.+)$", |
Sebastian Noack
2015/12/08 15:08:38
Indeed, we can simply use re.search instead iterat
kzar
2015/12/08 15:37:43
Well it's true about the "! foo ! Version: foo" ma
Sebastian Noack
2015/12/08 15:45:51
Well, theoretically the filter list can be empty.
| |
49 body, re.MULTILINE).group(1) | 49 body, re.MULTILINE).group(1) |
50 return body, url, version | 50 return body, url, version |
51 | 51 |
52 def generate_metadata(filter_lists, expires): | 52 def generate_metadata(filter_lists, expires): |
53 metadata = OrderedDict(( | 53 metadata = OrderedDict(( |
54 ("version", time.strftime("%Y%m%d%H%M", time.gmtime())), | 54 ("version", time.strftime("%Y%m%d%H%M", time.gmtime())), |
55 ("expires", expires), | 55 ("expires", expires), |
56 ("sources", []) | 56 ("sources", []) |
57 )) | 57 )) |
58 for body, url, version in filter_lists: | 58 for body, url, version in filter_lists: |
(...skipping 25 matching lines...) Expand all Loading... | |
84 | 84 |
85 easylist = download_filter_list(config["easylist_url"]) | 85 easylist = download_filter_list(config["easylist_url"]) |
86 exceptionrules = download_filter_list(config["exceptionrules_url"]) | 86 exceptionrules = download_filter_list(config["exceptionrules_url"]) |
87 | 87 |
88 write_block_list([easylist], | 88 write_block_list([easylist], |
89 config["easylist_content_blocker_path"], | 89 config["easylist_content_blocker_path"], |
90 config["easylist_content_blocker_expires"]) | 90 config["easylist_content_blocker_expires"]) |
91 write_block_list([easylist, exceptionrules], | 91 write_block_list([easylist, exceptionrules], |
92 config["combined_content_blocker_path"], | 92 config["combined_content_blocker_path"], |
93 config["combined_content_blocker_expires"]) | 93 config["combined_content_blocker_expires"]) |
LEFT | RIGHT |