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

Side by Side Diff: cms/converters.py

Issue 5488197752586240: Issue 2440 - implement Source.get_cache_dir() to be used by custom filters/globals (Closed)
Patch Set: Created April 30, 2015, 1:49 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 | cms/sources.py » ('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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 "translate": self.translate, 301 "translate": self.translate,
302 "linkify": self.linkify, 302 "linkify": self.linkify,
303 "toclist": self.toclist, 303 "toclist": self.toclist,
304 } 304 }
305 305
306 globals = { 306 globals = {
307 "get_string": self.get_string, 307 "get_string": self.get_string,
308 "get_page_content": self.get_page_content, 308 "get_page_content": self.get_page_content,
309 } 309 }
310 310
311 source = self._params["source"]
311 self._module_refs = [] 312 self._module_refs = []
312 for dirname, dictionary in [("filters", filters), ("globals", globals)]: 313 for dirname, dictionary in [("filters", filters), ("globals", globals)]:
313 for filename in self._params["source"].list_files(dirname): 314 for filename in source.list_files(dirname):
314 root, ext = os.path.splitext(filename) 315 root, ext = os.path.splitext(filename)
315 if ext.lower() != ".py": 316 if ext.lower() != ".py":
316 continue 317 continue
317 318
318 path = "%s/%s" % (dirname, filename) 319 path = "%s/%s" % (dirname, filename)
319 code = self._params["source"].read_file(path) 320 code = source.read_file(path)
320 module = imp.new_module(root.replace("/", ".")) 321 module = imp.new_module(root.replace("/", "."))
322 if hasattr(source, "get_cache_dir"):
323 module.CMS_CACHE_DIR = source.get_cache_dir()
321 exec code in module.__dict__ 324 exec code in module.__dict__
322 325
323 name = os.path.basename(root) 326 name = os.path.basename(root)
324 if not hasattr(module, name): 327 if not hasattr(module, name):
325 raise Exception("Expected symbol %s not found in %s file %s" % (name, dirname, filename)) 328 raise Exception("Expected symbol %s not found in %s file %s" % (name, dirname, filename))
326 dictionary[name] = getattr(module, name) 329 dictionary[name] = getattr(module, name)
327 330
328 # HACK: The module we created here can be garbage collected because it 331 # HACK: The module we created here can be garbage collected because it
329 # isn't added to sys.modules. If a function is called and its module is 332 # isn't added to sys.modules. If a function is called and its module is
330 # gone it might cause weird errors (imports and module variables 333 # gone it might cause weird errors (imports and module variables
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 stack.pop() 396 stack.pop()
394 stack[-1]["subitems"].append(item) 397 stack[-1]["subitems"].append(item)
395 stack.append(item) 398 stack.append(item)
396 return structured 399 return structured
397 400
398 converters = { 401 converters = {
399 "html": RawConverter, 402 "html": RawConverter,
400 "md": MarkdownConverter, 403 "md": MarkdownConverter,
401 "tmpl": TemplateConverter, 404 "tmpl": TemplateConverter,
402 } 405 }
OLDNEW
« no previous file with comments | « no previous file | cms/sources.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld