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

Side by Side Diff: sitescripts/subscriptions/subscriptionParser.py

Issue 29325371: Issue 2822 - Added support for new subscription types (Closed)
Patch Set: Created Aug. 31, 2015, 3:17 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 | sitescripts/subscriptions/template/recommendations.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 found = False 186 found = False
187 for key in group: 187 for key in group:
188 if self._data[key] != None: 188 if self._data[key] != None:
189 found = True 189 found = True
190 if not found: 190 if not found:
191 str = ", ".join(group) 191 str = ", ".join(group)
192 warn('None of the attributes %s present in %s' % (str, path)) 192 warn('None of the attributes %s present in %s' % (str, path))
193 193
194 if len(self.variants) == 0: 194 if len(self.variants) == 0:
195 warn('No list locations given in %s' % (path)) 195 warn('No list locations given in %s' % (path))
196 if self.type != 'ads' and self.type != 'other': 196 if self.type not in ['ads', 'anti-adblock', 'other', 'malware', 'social', 'p rivacy']:
Sebastian Noack 2015/08/31 15:53:44 Nit: Please use a tuple. There is no reason to use
Thomas Greiner 2015/09/02 14:10:19 Done.
197 warn('Unknown type given in %s' % (path)) 197 warn('Unknown type given in %s' % (path))
198 if self.digest != 'daily' and self.digest != 'weekly': 198 if self.digest != 'daily' and self.digest != 'weekly':
199 warn('Unknown digest frequency given in %s' % (path)) 199 warn('Unknown digest frequency given in %s' % (path))
200 if not self.digestDay[0:3].lower() in weekdays: 200 if not self.digestDay[0:3].lower() in weekdays:
201 warn('Unknown digest day given in %s' % (path)) 201 warn('Unknown digest day given in %s' % (path))
202 self.digestDay = 'wed' 202 self.digestDay = 'wed'
203 self.digestDay = weekdays[self.digestDay[0:3].lower()] 203 self.digestDay = weekdays[self.digestDay[0:3].lower()]
204 if self.recommendation != None and (self.languages == None or not re.search( r'\S', self.languages)): 204 if self.recommendation is not None and self.type == 'ads' and (self.language s is None or not self.languages.strip()):
Sebastian Noack 2015/08/31 15:53:44 There are two ways to further simplify that check:
Thomas Greiner 2015/09/02 14:10:19 Done.
205 warn('Recommendation without languages in %s' % (path)) 205 warn('Recommendation without languages in %s' % (path))
206 if len(self.supplements) == 0: 206 if len(self.supplements) == 0:
207 for [name, url, complete] in self.variants: 207 for [name, url, complete] in self.variants:
208 if complete: 208 if complete:
209 warn('Variant marked as complete for non-supplemental subscription in %s' % (path)) 209 warn('Variant marked as complete for non-supplemental subscription in %s' % (path))
210 break 210 break
211 211
212 self.variants.sort(key=lambda variant: (self.recommendation == variant) * 2 + variant[2], reverse=True) 212 self.variants.sort(key=lambda variant: (self.recommendation == variant) * 2 + variant[2], reverse=True)
213 213
214 def parse_file(path, data): 214 def parse_file(path, data):
215 return Subscription(path, data) 215 return Subscription(path, data)
216 216
217 def calculate_supplemented(lists): 217 def calculate_supplemented(lists):
218 for filedata in lists.itervalues(): 218 for filedata in lists.itervalues():
219 for supplements in filedata.supplements: 219 for supplements in filedata.supplements:
220 if supplements in lists: 220 if supplements in lists:
221 lists[supplements].supplemented.append(filedata) 221 if lists[supplements].type == filedata.type:
222 lists[supplements].supplemented.append(filedata)
222 else: 223 else:
223 warn('Subscription %s supplements an unknown subscription %s' % (filedat a.name, supplements)) 224 warn('Subscription %s supplements an unknown subscription %s' % (filedat a.name, supplements))
224 225
225 @cached(60) 226 @cached(60)
226 def get_settings(): 227 def get_settings():
227 repo = os.path.abspath(get_config().get('subscriptions', 'repository')) 228 repo = os.path.abspath(get_config().get('subscriptions', 'repository'))
228 settingsdata = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'defaul t', os.path.join(repo, 'settings')]) 229 settingsdata = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'defaul t', os.path.join(repo, 'settings')])
229 settings = SafeConfigParser() 230 settings = SafeConfigParser()
230 settings.readfp(codecs.getreader('utf8')(StringIO(settingsdata))) 231 settings.readfp(codecs.getreader('utf8')(StringIO(settingsdata)))
231 return settings 232 return settings
(...skipping 18 matching lines...) Expand all
250 251
251 def getFallbackData(): 252 def getFallbackData():
252 repo = os.path.abspath(get_config().get('subscriptions', 'repository')) 253 repo = os.path.abspath(get_config().get('subscriptions', 'repository'))
253 redirectdata = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'defaul t', os.path.join(repo, 'redirects')]) 254 redirectdata = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'defaul t', os.path.join(repo, 'redirects')])
254 gonedata = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'default', os.path.join(repo, 'gone')]) 255 gonedata = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'default', os.path.join(repo, 'gone')])
255 return (redirectdata, gonedata) 256 return (redirectdata, gonedata)
256 257
257 def _validate_URL(url): 258 def _validate_URL(url):
258 parse_result = urlparse(url) 259 parse_result = urlparse(url)
259 return parse_result.scheme in ('http', 'https') and parse_result.netloc != '' 260 return parse_result.scheme in ('http', 'https') and parse_result.netloc != ''
OLDNEW
« no previous file with comments | « no previous file | sitescripts/subscriptions/template/recommendations.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld