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

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

Issue 10942098: Make sure subprocess calls don`t ignore result codes indicating errors. Fix JS docs generation whil… (Closed)
Patch Set: Fixed wrong argument format Created July 4, 2013, 1:01 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
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 lists[supplements].supplemented.append(fileData)
222 else: 222 else:
223 warn('Subscription %s supplements an unknown subscription %s' % (fileDat a.name, supplements)) 223 warn('Subscription %s supplements an unknown subscription %s' % (fileDat a.name, supplements))
224 224
225 @cached(60) 225 @cached(60)
226 def get_settings(): 226 def get_settings():
227 repo = os.path.abspath(get_config().get('subscriptions', 'repository')) 227 repo = os.path.abspath(get_config().get('subscriptions', 'repository'))
228 (settingsData, errors) = subprocess.Popen(['hg', '-R', repo, 'cat', '-r', 'def ault', os.path.join(repo, 'settings')], stdout=subprocess.PIPE, stderr=subproces s.PIPE).communicate() 228 settingsData = subprocess.check_output(['hg', '-q', '-R', repo, 'cat', '-r', ' default', os.path.join(repo, 'settings')])
Sebastian Noack 2013/07/04 13:57:51 The added -q parameter doesn't seem to have any af
229 if errors:
230 print >>sys.stderr, errors
231
232 settings = SafeConfigParser() 229 settings = SafeConfigParser()
233 settings.readfp(codecs.getreader('utf8')(StringIO(settingsData))) 230 settings.readfp(codecs.getreader('utf8')(StringIO(settingsData)))
234 return settings 231 return settings
235 232
236 def readSubscriptions(): 233 def readSubscriptions():
237 repo = os.path.abspath(get_config().get('subscriptions', 'repository')) 234 repo = os.path.abspath(get_config().get('subscriptions', 'repository'))
238 (data, errors) = subprocess.Popen(['hg', 'archive', '-R', repo, '-r', 'default ', '-t', 'tar', '-I', os.path.join(repo, '*.subscription'), '-'], stdout=subproc ess.PIPE, stderr=subprocess.PIPE).communicate() 235 data = subprocess.check_output(['hg', 'archive', '-q', '-R', repo, '-r', 'defa ult', '-t', 'tar', '-I', os.path.join(repo, '*.subscription'), '-'])
239 if errors:
240 print >>sys.stderr, errors
241 236
242 result = {} 237 result = {}
243 tarFile = tarfile.open(mode='r:', fileobj=StringIO(data)) 238 tarFile = tarfile.open(mode='r:', fileobj=StringIO(data))
244 fileInfo = tarFile.next() 239 fileInfo = tarFile.next()
245 while fileInfo: 240 while fileInfo:
246 fileData = parseFile(fileInfo.name, codecs.getreader('utf8')(tarFile.extract file(fileInfo))) 241 fileData = parseFile(fileInfo.name, codecs.getreader('utf8')(tarFile.extract file(fileInfo)))
247 fileInfo = tarFile.next() 242 fileInfo = tarFile.next()
248 if fileData.unavailable: 243 if fileData.unavailable:
249 continue 244 continue
250 245
251 if fileData.name in result: 246 if fileData.name in result:
252 warn('Name %s is claimed by multiple files' % (fileData.name)) 247 warn('Name %s is claimed by multiple files' % (fileData.name))
253 result[fileData.name] = fileData 248 result[fileData.name] = fileData
254 tarFile.close() 249 tarFile.close()
255 250
256 calculateSupplemented(result) 251 calculateSupplemented(result)
257 return result 252 return result
258 253
259 def getFallbackData(): 254 def getFallbackData():
260 repo = os.path.abspath(get_config().get('subscriptions', 'repository')) 255 repo = os.path.abspath(get_config().get('subscriptions', 'repository'))
261 (redirectData, errors) = subprocess.Popen(['hg', '-R', repo, 'cat', '-r', 'def ault', os.path.join(repo, 'redirects')], stdout=subprocess.PIPE, stderr=subproce ss.PIPE).communicate() 256 redirectData = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'defaul t', os.path.join(repo, 'redirects')])
262 if errors: 257 goneData = subprocess.check_output(['hg', '-R', repo, 'cat', '-r', 'default', os.path.join(repo, 'gone')])
263 print >>sys.stderr, errors
264
265 (goneData, errors) = subprocess.Popen(['hg', '-R', repo, 'cat', '-r', 'default ', os.path.join(repo, 'gone')], stdout=subprocess.PIPE, stderr=subprocess.PIPE). communicate()
266 if errors:
267 print >>sys.stderr, errors
268
269 return (redirectData, goneData) 258 return (redirectData, goneData)
270 259
271 def _validateURL(url): 260 def _validateURL(url):
272 parseResult = urlparse(url) 261 parseResult = urlparse(url)
273 return (parseResult.scheme == 'http' or parseResult.scheme == 'https') and par seResult.netloc != '' 262 return (parseResult.scheme == 'http' or parseResult.scheme == 'https') and par seResult.netloc != ''
OLDNEW

Powered by Google App Engine
This is Rietveld