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 24 matching lines...) Expand all Loading... |
35 abp2blocklist_path = config["abp2blocklist_path"] | 35 abp2blocklist_path = config["abp2blocklist_path"] |
36 if os.path.isdir(abp2blocklist_path): | 36 if os.path.isdir(abp2blocklist_path): |
37 subprocess.check_call(("hg", "pull", "-u", "-R", abp2blocklist_path), | 37 subprocess.check_call(("hg", "pull", "-u", "-R", abp2blocklist_path), |
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 parse_filter_list_header(filter_list): | |
46 body_start = re.search(r"^[^![]", filter_list, re.MULTILINE).start() | |
47 field_re = re.compile(r"^!\s*([^:\s]+):\s*(.+)$", re.MULTILINE) | |
48 return {match.group(1): match.group(2) | |
49 for match in field_re.finditer(filter_list, 0, body_start)} | |
50 | |
51 def download_filter_list(url): | 45 def download_filter_list(url): |
52 with closing(urllib2.urlopen(url)) as response: | 46 with closing(urllib2.urlopen(url)) as response: |
53 body = response.read() | 47 body = response.read() |
54 header = parse_filter_list_header(body) | 48 version = re.search(r"^(?:[^[!])|^!\s*Version:\s*(.+)$", |
55 return body, url, header["Version"] | 49 body, re.MULTILINE).group(1) |
| 50 return body, url, version |
56 | 51 |
57 def generate_metadata(filter_lists, expires): | 52 def generate_metadata(filter_lists, expires): |
58 metadata = OrderedDict(( | 53 metadata = OrderedDict(( |
59 ("version", time.strftime("%Y%m%d%H%M", time.gmtime())), | 54 ("version", time.strftime("%Y%m%d%H%M", time.gmtime())), |
60 ("expires", expires), | 55 ("expires", expires), |
61 ("sources", []) | 56 ("sources", []) |
62 )) | 57 )) |
63 for body, url, version in filter_lists: | 58 for body, url, version in filter_lists: |
64 metadata["sources"].append({"url": url, "version": version}) | 59 metadata["sources"].append({"url": url, "version": version}) |
65 return metadata | 60 return metadata |
(...skipping 23 matching lines...) Expand all Loading... |
89 | 84 |
90 easylist = download_filter_list(config["easylist_url"]) | 85 easylist = download_filter_list(config["easylist_url"]) |
91 exceptionrules = download_filter_list(config["exceptionrules_url"]) | 86 exceptionrules = download_filter_list(config["exceptionrules_url"]) |
92 | 87 |
93 write_block_list([easylist], | 88 write_block_list([easylist], |
94 config["easylist_content_blocker_path"], | 89 config["easylist_content_blocker_path"], |
95 config["easylist_content_blocker_expires"]) | 90 config["easylist_content_blocker_expires"]) |
96 write_block_list([easylist, exceptionrules], | 91 write_block_list([easylist, exceptionrules], |
97 config["combined_content_blocker_path"], | 92 config["combined_content_blocker_path"], |
98 config["combined_content_blocker_expires"]) | 93 config["combined_content_blocker_expires"]) |
LEFT | RIGHT |