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

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

Issue 11275006: Added script to generate notification.json for the emergencynotification mechanism (Closed)
Patch Set: Fixed closing and iterating through tar files Created July 29, 2013, 2:08 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 | « sitescripts/management/bin/generateNotifications.py ('k') | 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 # 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-2013 Eyeo GmbH 4 # Copyright (C) 2006-2013 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 settings = SafeConfigParser() 229 settings = SafeConfigParser()
230 settings.readfp(codecs.getreader('utf8')(StringIO(settingsData))) 230 settings.readfp(codecs.getreader('utf8')(StringIO(settingsData)))
231 return settings 231 return settings
232 232
233 def readSubscriptions(): 233 def readSubscriptions():
234 repo = os.path.abspath(get_config().get('subscriptions', 'repository')) 234 repo = os.path.abspath(get_config().get('subscriptions', 'repository'))
235 data = subprocess.check_output(['hg', 'archive', '-R', repo, '-r', 'default', '-t', 'tar', '-I', os.path.join(repo, '*.subscription'), '-']) 235 data = subprocess.check_output(['hg', 'archive', '-R', repo, '-r', 'default', '-t', 'tar', '-I', os.path.join(repo, '*.subscription'), '-'])
236 236
237 result = {} 237 result = {}
238 tarFile = tarfile.open(mode='r:', fileobj=StringIO(data)) 238 tarFile = tarfile.open(mode='r:', fileobj=StringIO(data))
239 fileInfo = tarFile.next() 239 for fileInfo in tarFile:
240 while fileInfo:
241 fileData = parseFile(fileInfo.name, codecs.getreader('utf8')(tarFile.extract file(fileInfo))) 240 fileData = parseFile(fileInfo.name, codecs.getreader('utf8')(tarFile.extract file(fileInfo)))
242 fileInfo = tarFile.next()
243 if fileData.unavailable: 241 if fileData.unavailable:
244 continue 242 continue
245 243
246 if fileData.name in result: 244 if fileData.name in result:
247 warn('Name %s is claimed by multiple files' % (fileData.name)) 245 warn('Name %s is claimed by multiple files' % (fileData.name))
248 result[fileData.name] = fileData 246 result[fileData.name] = fileData
249 tarFile.close() 247 tarFile.close()
250 248
251 calculateSupplemented(result) 249 calculateSupplemented(result)
252 return result 250 return result
253 251
254 def getFallbackData(): 252 def getFallbackData():
255 repo = os.path.abspath(get_config().get('subscriptions', 'repository')) 253 repo = os.path.abspath(get_config().get('subscriptions', 'repository'))
256 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')])
257 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')])
258 return (redirectData, goneData) 256 return (redirectData, goneData)
259 257
260 def _validateURL(url): 258 def _validateURL(url):
261 parseResult = urlparse(url) 259 parseResult = urlparse(url)
262 return (parseResult.scheme == 'http' or parseResult.scheme == 'https') and par seResult.netloc != '' 260 return (parseResult.scheme == 'http' or parseResult.scheme == 'https') and par seResult.netloc != ''
OLDNEW
« no previous file with comments | « sitescripts/management/bin/generateNotifications.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld