def text_resource_complete(self, resource, text): """ Save the file to a temporary place and run less compiler. Read the generated file and return the text as output. Set the target path to have a css extension. """ if not self._should_parse_resource(resource): return supported = [ "verbose", ("silent", "s"), ("compress", "x"), "O0", "O1", "O2", "include-path=" ] less = self.app source = File.make_temp(text) target = File.make_temp('') args = [unicode(less)] args.extend(self.process_args(supported)) args.extend([unicode(source), unicode(target)]) try: self.call_app(args) except subprocess.CalledProcessError: HydeException.reraise( "Cannot process %s. Error occurred when " "processing [%s]" % (self.app.name, resource.source_file), sys.exc_info()) return target.read_all()
def get_source(self, environment, template): """ Calls the plugins to preprocess prior to returning the source. """ template = template.strip() # Fixed so that jinja2 loader does not have issues with # seprator in windows # template = template.replace(os.sep, '/') logger.debug("Loading template [%s] and preprocessing" % template) try: (contents, filename, date) = super(HydeLoader, self).get_source( environment, template) except UnicodeDecodeError: HydeException.reraise( "Unicode error when processing %s" % template, sys.exc_info()) except TemplateError as exc: HydeException.reraise('Error when processing %s: %s' % ( template, str(exc) ), sys.exc_info()) if self.preprocessor: resource = self.site.content.resource_from_relative_path(template) if resource: contents = self.preprocessor(resource, contents) or contents return (contents, filename, date)
def get_dependencies(self, path): """ Finds dependencies hierarchically based on the included files. """ text = self.env.loader.get_source(self.env, path)[0] from jinja2.meta import find_referenced_templates try: ast = self.env.parse(text) except Exception, e: HydeException.reraise( "Error processing %s: \n%s" % (path, unicode(e)), sys.exc_info())
def get_tagger_sort_method(site): config = site.config content = site.content walker = 'walk_resources' sorter = None try: sorter = attrgetter('tagger.sorter')(config) walker = walker + '_sorted_by_%s' % sorter except AttributeError: pass try: walker = getattr(content, walker) except AttributeError: HydeException.reraise("Cannot find the sorter: %s" % sorter, sys.exc_info()) return walker
def text_resource_complete(self, resource, text): if not resource.source_file.name == 'rjs.conf': return rjs = self.app target = File.make_temp('') args = [unicode(rjs)] args.extend(['-o', unicode(resource), ("out=" + target.fully_expanded_path)]) try: self.call_app(args) except subprocess.CalledProcessError: HydeException.reraise( "Cannot process %s. Error occurred when " "processing [%s]" % (self.app.name, resource.source_file), sys.exc_info()) return target.read_all()
def get_tagger_sort_method(site): config = site.config content = site.content walker = 'walk_resources' sorter = None try: sorter = attrgetter('tagger.sorter')(config) walker = walker + '_sorted_by_%s' % sorter except AttributeError: pass try: walker = getattr(content, walker) except AttributeError: HydeException.reraise( "Cannot find the sorter: %s" % sorter, sys.exc_info()) return walker
def text_resource_complete(self, resource, text): if not resource.source_file.name == 'rjs.conf': return rjs = self.app target = File.make_temp('') args = [str(rjs)] args.extend( ['-o', str(resource), ("out=" + target.fully_expanded_path)]) try: self.call_app(args) except subprocess.CalledProcessError: HydeException.reraise( "Cannot process %s. Error occurred when " "processing [%s]" % (self.app.name, resource.source_file), sys.exc_info()) return target.read_all()
def __generate_resource__(self, resource, incremental=False): self.refresh_config() if not resource.is_processable: logger.debug("Skipping [%s]", resource) return if incremental and not self.has_resource_changed(resource): logger.debug("No changes found. Skipping resource [%s]", resource) return logger.debug("Processing [%s]", resource) with self.context_for_resource(resource) as context: target = File( self.site.config.deploy_root_path.child( resource.relative_deploy_path)) target.parent.make() if resource.simple_copy: logger.debug("Simply Copying [%s]", resource) resource.source_file.copy_to(target) elif resource.source_file.is_text: self.update_deps(resource) if resource.uses_template: logger.debug("Rendering [%s]", resource) try: text = self.template.render_resource(resource, context) except Exception as e: HydeException.reraise( "Error occurred when processing" "template: [%s]: %s" % (resource, repr(e)), sys.exc_info()) else: text = resource.source_file.read_all() text = self.events.begin_text_resource(resource, text) or text text = self.events.text_resource_complete(resource, text) or text target.write(text) copymode(resource.source_file.path, target.path) else: logger.debug("Copying binary file [%s]", resource) self.events.begin_binary_resource(resource) resource.source_file.copy_to(target) self.events.binary_resource_complete(resource)
def __generate_resource__(self, resource, incremental=False): self.refresh_config() if not resource.is_processable: logger.debug("Skipping [%s]", resource) return if incremental and not self.has_resource_changed(resource): logger.debug("No changes found. Skipping resource [%s]", resource) return logger.debug("Processing [%s]", resource) with self.context_for_resource(resource) as context: target = File(self.site.config.deploy_root_path.child( resource.relative_deploy_path)) target.parent.make() if resource.simple_copy: logger.debug("Simply Copying [%s]", resource) resource.source_file.copy_to(target) elif resource.source_file.is_text: self.update_deps(resource) if resource.uses_template: logger.debug("Rendering [%s]", resource) try: text = self.template.render_resource(resource, context) except Exception as e: HydeException.reraise("Error occurred when processing" "template: [%s]: %s" % (resource, repr(e)), sys.exc_info()) else: text = resource.source_file.read_all() text = self.events.begin_text_resource( resource, text) or text text = self.events.text_resource_complete( resource, text) or text target.write(text) copymode(resource.source_file.path, target.path) else: logger.debug("Copying binary file [%s]", resource) self.events.begin_binary_resource(resource) resource.source_file.copy_to(target) self.events.binary_resource_complete(resource)
def get_dependencies(self, path): """ Finds dependencies hierarchically based on the included files. """ text = self.env.loader.get_source(self.env, path)[0] from jinja2.meta import find_referenced_templates try: ast = self.env.parse(text) except Exception as e: HydeException.reraise("Error processing %s: \n%s" % (path, str(e)), sys.exc_info()) tpls = find_referenced_templates(ast) deps = list(self.env.globals['deps'].get('path', [])) for dep in tpls: deps.append(dep) if dep: deps.extend(self.get_dependencies(dep)) return list(set(deps))
def get_dependencies(self, path): """ Finds dependencies hierarchically based on the included files. """ text = self.env.loader.get_source(self.env, path)[0] from jinja2.meta import find_referenced_templates try: ast = self.env.parse(text) except Exception as e: HydeException.reraise("Error processing %s: \n%s" % (path, str(e)), sys.exc_info()) tpls = find_referenced_templates(ast) deps = list(self.env.globals["deps"].get("path", [])) for dep in tpls: deps.append(dep) if dep: deps.extend(self.get_dependencies(dep)) return list(set(deps))
def __call_plugins__(*args): res = None if self.site.plugins: for plugin in self.site.plugins: if hasattr(plugin, method_name): checker = getattr(plugin, 'should_call__' + method_name) if checker(*args): function = getattr(plugin, method_name) try: res = function(*args) except: HydeException.reraise( 'Error occured when calling %s' % plugin.plugin_name, sys.exc_info()) targs = list(args) if len(targs): last = targs.pop() res = res if res else last targs.append(res) args = tuple(targs) return res
def text_resource_complete(self, resource, text): """ Save the file to a temporary place and run stylus compiler. Read the generated file and return the text as output. Set the target path to have a css extension. """ if not resource.source_file.kind == 'styl': return stylus = self.app source = File.make_temp(text.strip()) supported = [("compress", "c"), ("include", "I")] args = [unicode(stylus)] args.extend(self.process_args(supported)) args.append(unicode(source)) try: self.call_app(args) except subprocess.CalledProcessError: HydeException.reraise( "Cannot process %s. Error occurred when " "processing [%s]" % (stylus.name, resource.source_file), sys.exc_info()) target = File(source.path + '.css') return target.read_all()
def text_resource_complete(self, resource, text): """ Save the file to a temporary place and run stylus compiler. Read the generated file and return the text as output. Set the target path to have a css extension. """ if not resource.source_file.kind == 'styl': return stylus = self.app source = File.make_temp(text.strip()) target = source supported = [("compress", "c"), ("include", "I")] args = [unicode(stylus)] args.extend(self.process_args(supported)) args.append(unicode(source)) try: self.call_app(args) except subprocess.CalledProcessError: HydeException.reraise( "Cannot process %s. Error occurred when " "processing [%s]" % (stylus.name, resource.source_file), sys.exc_info()) return target.read_all()