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

Delta Between Two Patch Sets: cms/sources.py

Issue 29972568: Issue 5828 - Additional paths require settings.ini (Closed) Base URL: https://hg.adblockplus.org/cms/
Left Patch Set: Created Jan. 3, 2019, 11:43 p.m.
Right Patch Set: Address comments on PS1 Created Jan. 8, 2019, 12:16 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | tests/test_additional_paths.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present 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
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 parts = page.split('/') 64 parts = page.split('/')
65 if parts[-1] == default_page: 65 if parts[-1] == default_page:
66 page = '/'.join(parts[:-1]) 66 page = '/'.join(parts[:-1])
67 if locale: 67 if locale:
68 path = '/{}/{}'.format(locale, page) 68 path = '/{}/{}'.format(locale, page)
69 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3: ]) 69 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3: ])
70 return locale, '/' + page 70 return locale, '/' + page
71 71
72 def read_config(self): 72 def read_config(self):
73 try: 73 configdata = self.read_file('settings.ini')[0]
74 configdata = self.read_file('settings.ini')[0] 74 config = ConfigParser.SafeConfigParser()
75 config = ConfigParser.SafeConfigParser() 75 config.readfp(StringIO(configdata))
76 config.readfp(StringIO(configdata)) 76 return config
77 return config
78 except IOError:
79 return ConfigParser.SafeConfigParser()
Vasily Kuznetsov 2019/01/04 18:46:03 This will do the trick, however, I'm worried that
rhowell 2019/01/08 00:19:25 Yeah, this seems clearer. Done.
80 77
81 def exec_file(self, filename): 78 def exec_file(self, filename):
82 source, filename = self.read_file(filename) 79 source, filename = self.read_file(filename)
83 code = compile(source, filename, 'exec') 80 code = compile(source, filename, 'exec')
84 namespace = {} 81 namespace = {}
85 exec code in namespace 82 exec code in namespace
86 return namespace 83 return namespace
87 84
88 # 85 #
89 # Page helpers 86 # Page helpers
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 If `settings.ini` in the source contains `[paths]` section with an 370 If `settings.ini` in the source contains `[paths]` section with an
374 `additional-paths` key that contains the list of additional root folders, 371 `additional-paths` key that contains the list of additional root folders,
375 `MultiSource` will be instantiated and its bases will be the original 372 `MultiSource` will be instantiated and its bases will be the original
376 source plus an additional source for each additional root folder. 373 source plus an additional source for each additional root folder.
377 `MultiSource` looks up files in its base sources in the order they are 374 `MultiSource` looks up files in its base sources in the order they are
378 provided, so the files in the additional folders will only be used if the 375 provided, so the files in the additional folders will only be used if the
379 original source doesn't contain that file. 376 original source doesn't contain that file.
380 """ 377 """
381 source = FileSource(path) 378 source = FileSource(path)
382 379
383 config = source.read_config()
384 try: 380 try:
381 config = source.read_config()
385 ap = config.get('paths', 'additional-paths').strip() 382 ap = config.get('paths', 'additional-paths').strip()
386 additional_paths = filter(None, ap.split()) 383 additional_paths = filter(None, ap.split())
387 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): 384 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, IOError):
388 additional_paths = [] 385 additional_paths = []
389 386
390 if additional_paths: 387 if additional_paths:
391 additional_sources = [ 388 additional_sources = [
392 create_source(os.path.join(path, p)) 389 create_source(os.path.join(path, p))
393 for p in additional_paths 390 for p in additional_paths
394 ] 391 ]
395 source = MultiSource([source] + additional_sources) 392 source = MultiSource([source] + additional_sources)
396 393
397 if cached: 394 if cached:
398 for fname in [ 395 for fname in [
399 'list_files', 396 'list_files',
400 'list_locales', 397 'list_locales',
401 'resolve_link', 398 'resolve_link',
402 'read_config', 399 'read_config',
403 'read_template', 400 'read_template',
404 'read_locale', 401 'read_locale',
405 'read_file', 402 'read_file',
406 'read_include', 403 'read_include',
407 'exec_file', 404 'exec_file',
408 ]: 405 ]:
409 setattr(source, fname, utils.memoize(getattr(source, fname))) 406 setattr(source, fname, utils.memoize(getattr(source, fname)))
410 407
411 return source 408 return source
LEFTRIGHT

Powered by Google App Engine
This is Rietveld