def resolve_source_to_url(self, filepath, item): request = get_current_request() env = self.env # Copied from webassets 0.8. Reproduced here for backwards # compatibility with the previous webassets release. # This ensures files which do not require building are still served # with proper versioning of URLs. # This can likely be removed once miracle2k/webassets#117 is fixed. # Only query the version if we need to for performance version = None if has_placeholder(filepath) or env.url_expire is not False: # If auto-build is enabled, we must not use a cached version # value, or we might serve old versions. bundle = Bundle(item, output=filepath) version = bundle.get_version(env, refresh=env.auto_build) url = filepath if has_placeholder(url): url = url % {'version': version} # This part is different from webassets. Try to resolve with an asset # spec first, then try the base class source URL resolver. resolved = False if request is not None: # Attempt to resolve the filepath as passed (but after versioning). # If this fails, it may be because the static route was registered # with an asset spec. In this case, the original item may also be # an asset spec contained therein, so try to resolve that. for attempt in (url, item): try: url = request.static_url(attempt) except ValueError: continue else: resolved = True break if not resolved: url = super(PyramidResolver, self).resolve_source_to_url( url, item ) if env.url_expire or ( env.url_expire is None and not has_placeholder(filepath)): url = "%s?%s" % (url, version) return url
def determine_version(self, bundle, env, hunk=None): if not hunk: if not has_placeholder(bundle.output): hunk = FileHunk(bundle.resolve_output(env)) else: # Can cannot determine the version of placeholder files. raise VersionIndeterminableError( 'output target has a placeholder') hasher = self.hasher() hasher.update(hunk.data()) return hasher.hexdigest()[:self.length]
def determine_version(self, bundle, ctx, hunk=None): if not hunk: from webassets.bundle import has_placeholder if not has_placeholder(bundle.output): hunk = FileHunk(bundle.resolve_output(ctx)) else: # Can cannot determine the version of placeholder files. raise VersionIndeterminableError( 'output target has a placeholder') hasher = self.hasher() hasher.update(hunk.data().encode('utf-8')) return hasher.hexdigest()[:self.length]
def determine_version(self, bundle, env, hunk=None): if not hunk and not has_placeholder(bundle.output): hunks = [FileHunk(bundle.resolve_output(env)), ] elif not hunk: src = sum(map(env.resolver.resolve_source, bundle.contents), []) hunks = [FileHunk(hunk) for hunk in src + bundle.resolve_depends(env)] else: hunks = [hunk, ] hasher = self.hasher() for hunk in hunks: hasher.update(hunk.data()) return hasher.hexdigest()[:self.length]
def determine_version(self, bundle, env, hunk=None): if not hunk and not has_placeholder(bundle.output): hunks = [ FileHunk(bundle.resolve_output(env)), ] elif not hunk: src = sum(map(env.resolver.resolve_source, bundle.contents), []) hunks = [ FileHunk(hunk) for hunk in src + bundle.resolve_depends(env) ] else: hunks = [ hunk, ] hasher = self.hasher() for hunk in hunks: hasher.update(hunk.data()) return hasher.hexdigest()[:self.length]
def determine_version(self, bundle, env, hunk=None): # Only look at an existing output file if we are not about to # overwrite it with a new version. But if we can, simply using the # timestamp of the final file is the fastest way to do this. # Note that this works because of our ``save_done`` hook. if not hunk: if not has_placeholder(bundle.output): return self.get_timestamp(bundle.resolve_output(env)) # If we need the timestamp for the file we just built (hunk!=None), # or if we need the timestamp for a bundle with a placeholder, # the way to get it is by looking at the source files. try: return self.find_recent_most_timestamp(bundle, env) except OSError: # Source files are missing. Under these circumstances, we cannot # return a proper version. assert hunk is None raise VersionIndeterminableError( 'source files are missing and output target has a ' 'placeholder')