| Index: sitescripts/content_blocker_lists/bin/generate_lists.py |
| =================================================================== |
| --- a/sitescripts/content_blocker_lists/bin/generate_lists.py |
| +++ b/sitescripts/content_blocker_lists/bin/generate_lists.py |
| @@ -27,38 +27,38 @@ |
| from sitescripts.utils import get_config |
| -config = dict(get_config().items("content_blocker_lists")) |
| +config = dict(get_config().items('content_blocker_lists')) |
| def update_abp2blocklist(): |
| - with open(os.devnull, "w") as devnull: |
| - abp2blocklist_path = config["abp2blocklist_path"] |
| + with open(os.devnull, 'w') as devnull: |
| + abp2blocklist_path = config['abp2blocklist_path'] |
| if os.path.isdir(abp2blocklist_path): |
| - subprocess.check_call(("hg", "pull", "-u", "-R", abp2blocklist_path), |
| + subprocess.check_call(('hg', 'pull', '-u', '-R', abp2blocklist_path), |
| stdout=devnull) |
| else: |
| - subprocess.check_call(("hg", "clone", config["abp2blocklist_url"], |
| + subprocess.check_call(('hg', 'clone', config['abp2blocklist_url'], |
| abp2blocklist_path), stdout=devnull) |
| - subprocess.check_call(("npm", "install"), cwd=abp2blocklist_path, |
| + subprocess.check_call(('npm', 'install'), cwd=abp2blocklist_path, |
| stdout=devnull) |
| def download_filter_list(url): |
| with closing(urllib2.urlopen(url)) as response: |
| body = response.read() |
| - version = re.search(r"^(?:[^[!])|^!\s*Version:\s*(.+)$", |
| + version = re.search(r'^(?:[^[!])|^!\s*Version:\s*(.+)$', |
| body, re.MULTILINE).group(1) |
| return body, url, version |
| def generate_metadata(filter_lists, expires): |
| metadata = OrderedDict(( |
| - ("version", time.strftime("%Y%m%d%H%M", time.gmtime())), |
| - ("expires", expires), |
| - ("sources", []) |
| + ('version', time.strftime('%Y%m%d%H%M', time.gmtime())), |
| + ('expires', expires), |
| + ('sources', []) |
| )) |
| for body, url, version in filter_lists: |
| - metadata["sources"].append({"url": url, "version": version}) |
| + metadata['sources'].append({'url': url, 'version': version}) |
| return metadata |
| @@ -72,26 +72,26 @@ |
| def write_block_list(filter_lists, path, expires): |
| block_list = generate_metadata(filter_lists, expires) |
| - process = subprocess.Popen(("node", "abp2blocklist.js"), |
| - cwd=config["abp2blocklist_path"], |
| + process = subprocess.Popen(('node', 'abp2blocklist.js'), |
| + cwd=config['abp2blocklist_path'], |
| stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
| threading.Thread(target=pipe_in, args=(process, filter_lists)).start() |
| - block_list["rules"] = json.load(process.stdout) |
| + block_list['rules'] = json.load(process.stdout) |
| if process.wait(): |
| - raise Exception("abp2blocklist returned %s" % process.returncode) |
| + raise Exception('abp2blocklist returned %s' % process.returncode) |
| - with open(path, "wb") as destination_file: |
| - json.dump(block_list, destination_file, indent=2, separators=(",", ": ")) |
| + with open(path, 'wb') as destination_file: |
| + json.dump(block_list, destination_file, indent=2, separators=(',', ': ')) |
| -if __name__ == "__main__": |
| +if __name__ == '__main__': |
| update_abp2blocklist() |
| - easylist = download_filter_list(config["easylist_url"]) |
| - exceptionrules = download_filter_list(config["exceptionrules_url"]) |
| + easylist = download_filter_list(config['easylist_url']) |
| + exceptionrules = download_filter_list(config['exceptionrules_url']) |
| write_block_list([easylist], |
| - config["easylist_content_blocker_path"], |
| - config["easylist_content_blocker_expires"]) |
| + config['easylist_content_blocker_path'], |
| + config['easylist_content_blocker_expires']) |
| write_block_list([easylist, exceptionrules], |
| - config["combined_content_blocker_path"], |
| - config["combined_content_blocker_expires"]) |
| + config['combined_content_blocker_path'], |
| + config['combined_content_blocker_expires']) |