def _build_compile_queue(self, single_template=None): """ Build a list of all the templates to be compiled. """ # Create compile queue queue = set() # Use a set, avoid duplication of records. if self.verbosity >= 2: print 'Building queue' # Now compile all templates to the cache directory for dir, t in template_iterator(): input_path = os.path.normpath(os.path.join(dir, t)) # Compile this template if: if ( # We are compiling *everything* not single_template or # Or this is the only template that we want to compile (single_template and t in single_template)): queue.add( (t, input_path) ) # Return ordered queue queue = list(queue) queue.sort() return queue
def _build_compile_queue(self, single_template=None): """ Build a list of all the templates to be compiled. """ # Create compile queue queue = set() # Use a set, avoid duplication of records. if self.verbosity >= 2: print 'Building queue' # Now compile all templates to the cache directory for dir, t in template_iterator(): input_path = os.path.normpath(os.path.join(dir, t)) # Compile this template if: if ( # We are compiling *everything* not single_template or # Or this is the only template that we want to compile (single_template and t in single_template)): queue.add((t, input_path)) # Return ordered queue queue = list(queue) queue.sort() return queue
def handle(self, *args, **options): # Default verbosity self.verbosity = int(options.get('verbosity', 1)) self.strings = { } # Maps msgid -> list of paths # Build queue queue = set() print 'Building queue' # Build list of all templates for dir, t in template_iterator(): input_path = os.path.join(dir, t) queue.add( (t, input_path) ) queue = list(queue) queue.sort() # Process queue for i in range(0, len(queue)): if self.verbosity >= 2: sys.stderr.write(termcolor.colored('%i / %i |' % (i, len(queue)), 'yellow')) sys.stderr.write(termcolor.colored(queue[i][1], 'green')) self.process_template(*queue[i]) # Output string to stdout for s in self.strings: for l in self.strings[s]: print l print 'msgid "%s"' % s.replace('"', r'\"') print 'msgstr ""' print
def handle(self, *args, **options): all_templates = options['all_templates'] print WARNING # Default verbosity self.verbosity = int(options.get('verbosity', 1)) # All languages by default languages = [l[0] for l in settings.LANGUAGES] if options['languages'] is None: options['languages'] = languages self._errors = [] cache_dir = os.path.join(settings.TEMPLATE_CACHE_DIR, 'compiled_to_code') # Delete previously compiled templates # (This is to be sure that no template loaders were configured to # load files from this cache.) if all_templates: for root, dirs, files in os.walk(cache_dir): for f in files: path = os.path.join(root, f) if self.verbosity >= 1: print ('Deleting old code: %s' % path) os.remove(path) # Create compile queue queue = set() if self.verbosity >= 2: print 'Building queue' for lang in options['languages']: # Now compile all templates to the cache directory for dir, t in template_iterator(): input_path = os.path.join(dir, t) output_path = os.path.join(cache_dir, lang, t) if ( all_templates or not os.path.exists(output_path) or os.path.getmtime(output_path) < os.path.getmtime(input_path)): queue.add( (lang, input_path, output_path) ) queue = list(queue) queue.sort() for i in range(0, len(queue)): lang = queue[i][0] with language(lang): if self.verbosity >= 2: print termcolor.colored('%i / %i |' % (i, len(queue)), 'yellow'), print termcolor.colored('(%s)' % lang, 'yellow'), print termcolor.colored(queue[i][1], 'green') self._compile_template(*queue[i]) # Show all errors once again. print u'\n*** %i Files processed, %i compile errors ***' % (len(queue), len(self._errors))
def setUp(self): self.template_paths = {} self.app_template_dir = os.path.join(settings.PROJECT_DIR, "testapp") for dir, template_path in template_iterator(): if template_path not in self.template_paths: self.template_paths[template_path] = [dir] else: self.template_paths[template_path].append(template_path) self.app_template_name = "app-template.html" self.project_template_name = "project-template.html"
def setUp(self): self.template_paths = {} self.app_template_dir = os.path.join(settings.PROJECT_DIR, 'testapp') for dir, template_path in template_iterator(): if template_path not in self.template_paths: self.template_paths[template_path] = [dir] else: self.template_paths[template_path].append(template_path) self.app_template_name = 'app-template.html' self.project_template_name = 'project-template.html'
def _build_compile_queue(self, languages, all_templates=True, single_template=None): """ Build a list of all the templates to be compiled. """ # Create compile queue queue = set() # Use a set, avoid duplication of records. if self.verbosity >= 2: print 'Building queue' for lang in languages: # Now compile all templates to the cache directory for dir, t in template_iterator(): input_path = os.path.normpath(os.path.join(dir, t)) output_path = self._make_output_path(lang, t) # Compile this template if: if ( # We are compiling *everything* all_templates or # Or this is the only template that we want to compile (single_template and t in single_template) or # Or we are compiling changed files ( not single_template and ( # Compiled file does not exist not os.path.exists(output_path) or # Compiled file has been marked for recompilation os.path.exists(output_path + '-c-recompile') or # Compiled file is outdated os.path.getmtime(output_path) < os.path.getmtime(input_path)))): queue.add((lang, t, input_path, output_path)) # When this file has to be compiled, and other files depend # on this template also compile the other templates. if os.path.exists(output_path + '-c-used-by'): for t2 in open(output_path + '-c-used-by', 'r').read().split('\n'): if t2: try: queue.add( (lang, t2, get_template_path(t2), self._make_output_path(lang, t2))) except TemplateDoesNotExist, e: pass # Reference to non-existing template
def handle(self, *args, **options): self._errors = [] # Default verbosity self.verbosity = int(options.get('verbosity', 1)) # Now compile all templates to the cache directory for dir, t in template_iterator(): input_path = os.path.join(dir, t) self._spellcheck(input_path) # Show all errors once again. print u'\n*** %i spelling errors ***' % len(self._errors)
def _build_compile_queue(self, languages, all_templates=True, single_template=None): """ Build a list of all the templates to be compiled. """ # Create compile queue queue = set() # Use a set, avoid duplication of records. if self.verbosity >= 2: print 'Building queue' for lang in languages: # Now compile all templates to the cache directory for dir, t in template_iterator(): input_path = os.path.normpath(os.path.join(dir, t)) output_path = self._make_output_path(lang, t) # Compile this template if: if ( # We are compiling *everything* all_templates or # Or this is the only template that we want to compile (single_template and t in single_template) or # Or we are compiling changed files (not single_template and ( # Compiled file does not exist not os.path.exists(output_path) or # Compiled file has been marked for recompilation os.path.exists(output_path + '-c-recompile') or # Compiled file is outdated os.path.getmtime(output_path) < os.path.getmtime(input_path)) )): queue.add( (lang, t, input_path, output_path) ) # When this file has to be compiled, and other files depend # on this template also compile the other templates. if os.path.exists(output_path + '-c-used-by'): for t2 in open(output_path + '-c-used-by', 'r').read().split('\n'): if t2: try: queue.add( (lang, t2, get_template_path(t2), self._make_output_path(lang, t2)) ) except TemplateDoesNotExist, e: pass # Reference to non-existing template
def handle(self, *args, **options): self._errors = [] # Default verbosity self.verbosity = int(options.get('verbosity', 1)) # Now compile all templates to the cache directory for dir, t in template_iterator(): input_path = os.path.join(dir, t) self._spellcheck(input_path) # Show all errors once again. print u'\n*** %i spelling errors ***' % len(self._errors) # Ring bell :) print '\x07'
def handle(self, *args, **options): all_templates = options['all_templates'] # Default verbosity self.verbosity = int(options.get('verbosity', 1)) # All languages by default languages = [l[0] for l in settings.LANGUAGES] if options['languages'] is None: options['languages'] = languages self._errors = [] if languages.sort() != options['languages'].sort(): print termcolor.colored('Warning: all template languages are deleted while we won\'t generate them again.', 'white', 'on_red') # Delete previously compiled templates # (This is to be sure that no template loaders were configured to # load files from this cache.) if all_templates: for root, dirs, files in os.walk(settings.TEMPLATE_CACHE_DIR): for f in files: path = os.path.join(root, f) if self.verbosity >= 1: print ('Deleting old template: %s' % path) os.remove(path) # Create compile queue queue = set() if self.verbosity >= 2: print 'Building queue' for lang in options['languages']: # Now compile all templates to the cache directory for dir, t in template_iterator(): input_path = os.path.join(dir, t) output_path = os.path.join(settings.TEMPLATE_CACHE_DIR, lang, t) # Compile this template if: if ( # We are compiling *everything* all_templates or # Compiled file does not exist not os.path.exists(output_path) or # Compiled file has been marked for recompilation os.path.exists(output_path + '-c-recompile') or # Compiled file is outdated os.path.getmtime(output_path) < os.path.getmtime(input_path)): queue.add( (lang, input_path, output_path) ) queue = list(queue) queue.sort() for i in range(0, len(queue)): lang = queue[i][0] with language(lang): if self.verbosity >= 2: print termcolor.colored('%i / %i |' % (i, len(queue)), 'yellow'), print termcolor.colored('(%s)' % lang, 'yellow'), print termcolor.colored(queue[i][1], 'green') self._compile_template(*queue[i]) # Show all errors once again. print u'\n*** %i Files processed, %i compile errors ***' % (len(queue), len(self._errors))
def handle(self, *args, **options): directory = (options.get('directory', ['']) or [''])[0] exclude_directory = (options.get('exclude_directory', []) or []) g = Graph('Template dependencies', True) g.layout('neato') g.landscape = True g.rotate = 90 g.label = str(datetime.datetime.now()) #g.scale = 0.7 #g.overlap = 'prism' #g.overlap = False g.overlap = 'scale' g.ranksep = 1.8 g.overlap = 'compress' g.ratio = 1. / math.sqrt(2) g.sep = 0.1 g.mindist = 0.1 nodes = set() edges = [] nodes_in_edges = set() # Retreive all nodes/edges for dir, t in template_iterator(): if t.startswith(directory) and not any( [t.startswith(x) for x in exclude_directory]): nodes.add(t) # {% include "..." %} includes = self._make_output_path(t) + '-c-includes' if os.path.exists(includes): for t2 in open(includes, 'r').read().split('\n'): if t2: nodes.add(t2) edges.append((t, t2, False)) nodes_in_edges.add(t) nodes_in_edges.add(t2) # {% extends "..." %} extends = self._make_output_path(t) + '-c-extends' if os.path.exists(extends): for t2 in open(extends, 'r').read().split('\n'): if t2: nodes.add(t2) edges.append((t, t2, True)) nodes_in_edges.add(t) nodes_in_edges.add(t2) # Remove orphan nodes for n in list(nodes): if not n in nodes_in_edges: nodes.remove(n) # Create graphvis nodes nodes2 = {} for t in nodes: node = self._create_node(t, g, nodes2) # Create graphvis edges for t1, t2, is_extends in edges: print 'from ', t1, ' to ', t2 node_a = self._create_node(t1, g, nodes2) node_b = self._create_node(t2, g, nodes2) edge = g.add_edge(node_a, node_b) edge.color = 'black' edge.arrowhead = 'normal' edge.arrowsize = 1.1 if is_extends: edge.style = 'solid' else: edge.style = 'dotted' #g.layout('neato') g.layout('twopi') g.render(settings.ROOT + 'template_dependency_graph.pdf', 'pdf', None) g.render(settings.ROOT + 'template_dependency_graph.jpg', 'jpg', None)
def handle(self, *args, **options): directory = (options.get('directory', ['']) or [''])[0] exclude_directory = (options.get('exclude_directory', []) or []) g = Graph('Template dependencies', True) g.layout('neato') g.landscape = True g.rotate = 90 g.label = str(datetime.datetime.now()) #g.scale = 0.7 #g.overlap = 'prism' #g.overlap = False g.overlap = 'scale' g.ranksep = 1.8 g.overlap = 'compress' g.ratio = 1. / math.sqrt(2) g.sep = 0.1 g.mindist = 0.1 nodes = set() edges = [ ] nodes_in_edges = set() # Retreive all nodes/edges for dir, t in template_iterator(): if t.startswith(directory) and not any([ t.startswith(x) for x in exclude_directory ]): nodes.add(t) # {% include "..." %} includes = self._make_output_path(t) + '-c-includes' if os.path.exists(includes): for t2 in open(includes, 'r').read().split('\n'): if t2: nodes.add(t2) edges.append( (t, t2, False) ) nodes_in_edges.add(t) nodes_in_edges.add(t2) # {% extends "..." %} extends = self._make_output_path(t) + '-c-extends' if os.path.exists(extends): for t2 in open(extends, 'r').read().split('\n'): if t2: nodes.add(t2) edges.append( (t, t2, True) ) nodes_in_edges.add(t) nodes_in_edges.add(t2) # Remove orphan nodes for n in list(nodes): if not n in nodes_in_edges: nodes.remove(n) # Create graphvis nodes nodes2 = { } for t in nodes: node = self._create_node(t, g, nodes2) # Create graphvis edges for t1, t2, is_extends in edges: print 'from ', t1, ' to ', t2 node_a = self._create_node(t1, g, nodes2) node_b = self._create_node(t2, g, nodes2) edge = g.add_edge(node_a, node_b) edge.color = 'black' edge.arrowhead = 'normal' edge.arrowsize = 1.1 if is_extends: edge.style = 'solid' else: edge.style = 'dotted' #g.layout('neato') g.layout('twopi') g.render(settings.ROOT + 'template_dependency_graph.pdf', 'pdf', None) g.render(settings.ROOT + 'template_dependency_graph.jpg', 'jpg', None)