def handle_label(self, label, **options): self._errors = [] args = label.split('.') if not len(args) == 3: print 'Not enough items (app_label.model.field)' print self.__doc__ return app_label, model, field = args class_ = ContentType.objects.get(app_label=app_label, model=model).model_class() total = 0 succes = 0 for lang in ('en', 'fr', 'nl'): with language(lang): for i in class_.objects.all(): total += 1 print termcolor.colored('(%s) %s %i' % (lang, unicode(i), i.id), 'green') try: # TODO: maybe pass preprocessor options somehow. # at the moment, the default settings are working. compile_html_string(getattr(i, field), path='%s (%i)' % (unicode(i), i.id) ) succes += 1 except CompileException, e: self.print_error(unicode(e))
def handle_label(self, label, **options): self._errors = [] args = label.split('.') if not len(args) == 3: print 'Not enough items (app_label.model.field)' print self.__doc__ return app_label, model, field = args class_ = ContentType.objects.get(app_label=app_label, model=model).model_class() total = 0 succes = 0 for lang in ('en', 'fr', 'nl'): with language(lang): for i in class_.objects.all(): total += 1 print termcolor.colored( '(%s) %s %i' % (lang, unicode(i), i.id), 'green') try: # TODO: maybe pass preprocessor options somehow. # at the moment, the default settings are working. compile_html_string(getattr(i, field), path='%s (%i)' % (unicode(i), i.id)) succes += 1 except CompileException, e: self.print_error(unicode(e))
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 handle(self, *args, **options): all_templates = options['all_templates'] interactive = options['interactive'] self.insert_debug_symbols = options['insert_debug_symbols'] # Default verbosity self.verbosity = int(options.get('verbosity', 1)) # Colors? self.boring = bool(options.get('boring')) # 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 self.colored('Warning: all template languages are deleted while we won\'t generate them again.', 'white', 'on_red') # Delete previously compiled templates and media files # (This is to be sure that no template loaders were configured to # load files from this cache.) if all_templates: if not interactive or raw_input('\nDelete all files in template cache directory: %s? [y/N] ' % settings.TEMPLATE_CACHE_DIR).lower() == 'y': for root, dirs, files in os.walk(settings.TEMPLATE_CACHE_DIR): for f in files: if not f[0] == '.': # Skip hidden files path = os.path.join(root, f) if self.verbosity >= 1: print ('Deleting old template: %s' % path) os.remove(path) if not interactive or raw_input('\nDelete all files in media cache directory %s? [y/N] ' % settings.MEDIA_CACHE_DIR).lower() == 'y': for root, dirs, files in os.walk(settings.MEDIA_CACHE_DIR): for f in files: if not f[0] == '.': # Skip hidden files path = os.path.join(root, f) if self.verbosity >= 1: print ('Deleting old media file: %s' % path) os.remove(path) # Build compile queue queue = self._build_compile_queue(options['languages'], all_templates) # Precompile command execute_precompile_command() # Compile queue for i in range(0, len(queue)): lang = queue[i][0] with language(lang): if self.verbosity >= 2: print self.colored('%i / %i |' % (i+1, len(queue)), 'yellow'), print self.colored('(%s)' % lang, 'yellow'), print self.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)) # Build media compile queue media_queue = self._build_compile_media_queue(options['languages']) # Compile media queue self._errors = [] for i in range(0, len(media_queue)): lang = media_queue[i][0] with language(lang): if self.verbosity >= 2: print self.colored('%i / %i |' % (i+1, len(media_queue)), 'yellow'), print self.colored('(%s)' % lang, 'yellow'), print self.colored(','.join(media_queue[i][1]), 'green') self._compile_media(*media_queue[i]) # Show all errors once again. print u'\n*** %i Media files processed, %i compile errors ***' % (len(media_queue), 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 real_handle(self, *args, **options): all_templates = options['all_templates'] single_template = options['single_template'] interactive = options['interactive'] self.insert_debug_symbols = options['insert_debug_symbols'] # Default verbosity self.verbosity = int(options.get('verbosity', 1)) # Colors? self.boring = bool(options.get('boring')) # 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 self.colored( 'Warning: all template languages are deleted while we won\'t generate them again.', 'white', 'on_red') # Delete previously compiled templates and media files # (This is to be sure that no template loaders were configured to # load files from this cache.) if all_templates: if not interactive or raw_input( '\nDelete all files in template cache directory: %s? [y/N] ' % settings.TEMPLATE_CACHE_DIR).lower() in ('y', 'yes'): for root, dirs, files in os.walk(settings.TEMPLATE_CACHE_DIR): for f in files: if not f[0] == '.': # Skip hidden files path = os.path.join(root, f) if self.verbosity >= 1: print('Deleting old template: %s' % path) os.remove(path) if not interactive or raw_input( '\nDelete all files in media cache directory %s? [y/N] ' % settings.MEDIA_CACHE_DIR).lower() in ('y', 'yes'): for root, dirs, files in os.walk(settings.MEDIA_CACHE_DIR): for f in files: if not f[0] == '.': # Skip hidden files path = os.path.join(root, f) if self.verbosity >= 1: print('Deleting old media file: %s' % path) os.remove(path) # Build compile queue queue = self._build_compile_queue(options['languages'], all_templates, single_template) # Precompile command execute_precompile_command() # Compile queue for i in range(0, len(queue)): lang = queue[i][0] with language(lang): if self.verbosity >= 2: print self.colored('%i / %i |' % (i + 1, len(queue)), 'yellow'), print self.colored('(%s)' % lang, 'yellow'), print self.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)) # Build media compile queue media_queue = self._build_compile_media_queue(options['languages']) # Compile media queue self._errors = [] for i in range(0, len(media_queue)): lang = media_queue[i][0] with language(lang): if self.verbosity >= 2: print self.colored('%i / %i |' % (i + 1, len(media_queue)), 'yellow'), print self.colored('(%s)' % lang, 'yellow'), print self.colored(','.join(media_queue[i][1]), 'green') self._compile_media(*media_queue[i]) # Show all errors once again. print u'\n*** %i Media files processed, %i compile errors ***' % ( len(media_queue), len(self._errors)) # Ring bell :) print '\x07'