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

Side by Side Diff: filters/get_subscriptions.py

Issue 29337941: Issue 3750 - Avoid re-generating subscription list for each locale (Closed)
Patch Set: Created March 8, 2016, 3:27 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of the Adblock Plus website, 1 # This file is part of the Adblock Plus website,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 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 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 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/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import codecs 16 import codecs
17 import os 17 import os
18 import tarfile 18 import tarfile
19 import urllib 19 import urllib
20 import logging 20 import logging
21 from ConfigParser import SafeConfigParser 21 from ConfigParser import SafeConfigParser
22 subscriptions = None
22 23
23 def get_subscriptions(_): 24 def get_subscriptions(_):
Wladimir Palant 2016/03/09 11:12:27 This shouldn't be a filter but rather a global fun
Sebastian Noack 2016/03/09 11:18:17 I agree that this should rather be a global. Howev
Wladimir Palant 2016/03/09 11:25:51 That's fine IMHO, with something like this functio
Sebastian Noack 2016/03/09 11:54:18 Whether you think it's safe or not, jinja's optimi
Wladimir Palant 2016/03/09 13:50:15 This makes sense because for filters same input sh
25 global subscriptions
26 if not subscriptions is None:
27 return subscriptions
24 try: 28 try:
25 from sitescripts.subscriptions import subscriptionParser 29 from sitescripts.subscriptions import subscriptionParser
26 except ImportError: 30 except ImportError:
27 logging.warning("Unable to import sitescripts, proceeding with empty " 31 logging.warning("Unable to import sitescripts, proceeding with empty "
28 "subscriptions list.") 32 "subscriptions list.")
29 return [] 33 return []
30 34
31 result = {} 35 result = {}
32 utf8_reader = codecs.getreader('utf8') 36 utf8_reader = codecs.getreader('utf8')
33 source = urllib.urlopen("https://hg.adblockplus.org/subscriptionlist/archive/d efault.tar.gz") 37 source = urllib.urlopen("https://hg.adblockplus.org/subscriptionlist/archive/d efault.tar.gz")
(...skipping 16 matching lines...) Expand all
50 filedata = subscriptionParser.parse_file(fileinfo.name, utf8_reader(arch ive.extractfile(fileinfo))) 54 filedata = subscriptionParser.parse_file(fileinfo.name, utf8_reader(arch ive.extractfile(fileinfo)))
51 if filedata.unavailable: 55 if filedata.unavailable:
52 continue 56 continue
53 57
54 result[filedata.name] = filedata 58 result[filedata.name] = filedata
55 finally: 59 finally:
56 source.close() 60 source.close()
57 subscriptionParser.get_settings = orig_get_settings 61 subscriptionParser.get_settings = orig_get_settings
58 62
59 subscriptionParser.calculate_supplemented(result) 63 subscriptionParser.calculate_supplemented(result)
60 return result.values() 64 subscriptions = result.values()
65 return subscriptions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld