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

Side by Side Diff: cms/sources.py

Issue 29886648: Issue #6942 - Add XTM integration in CMS (Closed)
Patch Set: Addressed comments on patch set #2 Created Oct. 3, 2018, 2:50 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 # 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 265
266 for filename in files: 266 for filename in files:
267 path = os.path.join(dir, filename) 267 path = os.path.join(dir, filename)
268 if os.path.isfile(path): 268 if os.path.isfile(path):
269 result.append(relpath + filename) 269 result.append(relpath + filename)
270 elif os.path.isdir(path): 270 elif os.path.isdir(path):
271 do_list(path, relpath + filename + '/') 271 do_list(path, relpath + filename + '/')
272 do_list(self.get_path(subdir), '') 272 do_list(self.get_path(subdir), '')
273 return result 273 return result
274 274
275 def write_to_config(self, section, option, value):
276 config = self.read_config()
277 try:
278 config.set(section, option, value)
279 except ConfigParser.NoSectionError:
280 config.add_section(section)
281 config.set(section, option, value)
282 with open(self.get_path('settings.ini'), 'w') as cnf:
283 config.write(cnf)
284
275 def get_cache_dir(self): 285 def get_cache_dir(self):
276 return os.path.join(self._dir, 'cache') 286 return os.path.join(self._dir, 'cache')
277 287
278 288
279 class MultiSource(Source): 289 class MultiSource(Source):
280 """A source that combines the contents of multiple other sources.""" 290 """A source that combines the contents of multiple other sources."""
281 291
282 def __init__(self, base_sources): 292 def __init__(self, base_sources):
283 self._bases = base_sources 293 self._bases = base_sources
284 294
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 `additional-paths` key that contains the list of additional root folders, 382 `additional-paths` key that contains the list of additional root folders,
373 `MultiSource` will be instantiated and its bases will be the original 383 `MultiSource` will be instantiated and its bases will be the original
374 source plus an additional source for each additional root folder. 384 source plus an additional source for each additional root folder.
375 `MultiSource` looks up files in its base sources in the order they are 385 `MultiSource` looks up files in its base sources in the order they are
376 provided, so the files in the additional folders will only be used if the 386 provided, so the files in the additional folders will only be used if the
377 original source doesn't contain that file. 387 original source doesn't contain that file.
378 """ 388 """
379 source = FileSource(path) 389 source = FileSource(path)
380 390
381 config = source.read_config() 391 config = source.read_config()
392 print(source.read_file('settings.ini')[0])
Vasily Kuznetsov 2018/10/05 10:56:26 Oops.
Tudor Avram 2018/10/05 12:34:40 haha, that was from Thursday night :))
382 try: 393 try:
383 ap = config.get('paths', 'additional-paths').strip() 394 ap = config.get('paths', 'additional-paths').strip()
384 additional_paths = filter(None, ap.split()) 395 additional_paths = filter(None, ap.split())
385 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): 396 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
386 additional_paths = [] 397 additional_paths = []
387 398
388 if additional_paths: 399 if additional_paths:
389 additional_sources = [ 400 additional_sources = [
390 create_source(os.path.join(path, p)) 401 create_source(os.path.join(path, p))
391 for p in additional_paths 402 for p in additional_paths
392 ] 403 ]
393 source = MultiSource([source] + additional_sources) 404 source = MultiSource([source] + additional_sources)
394 405
395 if cached: 406 if cached:
396 for fname in [ 407 for fname in [
397 'resolve_link', 408 'resolve_link',
398 'read_config', 409 'read_config',
399 'read_template', 410 'read_template',
400 'read_locale', 411 'read_locale',
401 'read_include', 412 'read_include',
402 'exec_file', 413 'exec_file',
403 ]: 414 ]:
404 setattr(source, fname, _memoize(getattr(source, fname))) 415 setattr(source, fname, _memoize(getattr(source, fname)))
405 416
406 return source 417 return source
OLDNEW

Powered by Google App Engine
This is Rietveld