def assets(self): # We require assets as otput if not self.filters.outputs_assets: raise ImproperlyConfigured("""Filter chain will not output assets.""") # if hasattr(self, '_assets') and not env.is_development: # Don't ever update return self._assets # Collect all sources sources = self.expand_sources(force=True) # if hasattr(self, '_assets') and self.filters.is_relatable: if len(sources) != len(self._assets): raise Exception("""Sources and assets are not relatable""") # This filter chain can be partially updated (x(lenx) assets in == y(lenx) assets in) for i in range(len(sources)): source = sources[i] asset = self._assets[i] if source.modified_time > asset.modified_time: env.log("""Asset '%s' invalidated.""" % asset.path) self._assets[i] = self.filters.execute(sources=[source])[0] else: # (re) Filter everything self._assets = [] for asset in self.filters.execute(sources=sources): self._assets.append(asset) return self._assets
def execute(self, assets): for asset in assets: content = asset.read() try: pipe("%s --type=js --verbose" % self._executable, input=content) except PipeError as error: env.log("""Validation failed for asset '%s'""" % asset.path) env.log(error)
def expand_sources(self, force=False): expanded = [] for source in self.sources: for source in source.expand(force=force): if source not in expanded: expanded.append(source) else: env.log("""Omitted duplicated source '%s'.""" % source) return expanded
def execute(self, sources, concentate=False): if self._filters or concentate: env.log("""Executing filter chain: %s""" % describe_filter_chain(self, concentate)) if self.inputs_assets: sources = FilterChain._collect_assets(sources) # Setup initial state input = sources # Begin filtering for filter in self._filters: func = filter.execute if hasattr(func, '_inputs_assets'): output = func(assets=input) elif hasattr(func, '_inputs_string'): # Could be initial list of sources, asset output if not isinstance(input, str): input = FilterChain._concentate_sources(input) output = func(string=input) else: output = func() if hasattr(func, '_outputs_assets'): # Validate and collect output input = FilterChain._collect_assets(output) elif hasattr(func, '_outputs_string'): # Validate output if not isinstance(output, str): raise FilterError("""Invalid output by filter '%s'. String expected.""" % filter.__class__) input = output # if self._outputs_nothing and concentate: input = FilterChain._concentate_sources(input) elif self.outputs_assets and concentate: input = FilterChain._concentate_sources(input) # return input