def _build_manifest_helper(static_dir, src_paths, static_url_prefix, manifest): assert isinstance(src_paths, (list, tuple)) for src_path in src_paths: # Make sure every source path at least has the skeleton entry rel_src_path = make_relative_static_path(static_dir, src_path) logging.info('_build_manifest_helper %s (crrent %s)', src_path, manifest.assets.get(rel_src_path)) manifest.assets.setdefault(rel_src_path, empty_asset_entry()) for dep_path in iter_deps(static_dir, src_path, static_url_prefix): logging.info('%s > dependency %s', src_path, dep_path) rel_path = make_relative_static_path(static_dir, dep_path) manifest.assets[rel_src_path]['deps'].add(rel_path) _build_manifest_helper(static_dir, [dep_path], static_url_prefix, manifest)
def get_current_content_hash(self, manifest): """Gets the md5 hash for each of the files in this manager's list of assets.""" h = hashlib.md5() for path in self.get_paths(): relative_path = make_relative_static_path(self.settings['static_dir'], path) assert relative_path in manifest.assets, relative_path h.update(manifest.assets[relative_path]['version']) return h.hexdigest()
def replacer(match): prefix, rel_path = match.groups() path = make_relative_static_path(static_dir, rel_path) if path in manifest.assets: versioned_path = manifest.assets[path]['versioned_path'] if isinstance(replacement_prefix, (list, tuple)): prefix = get_shard_from_list(replacement_prefix, versioned_path) else: prefix = replacement_prefix return prefix.rstrip('/') + '/' + versioned_path.lstrip('/') logging.warn('Missing path %s in manifest, using %s', path, match.group(0)) return match.group(0)
def replacer(match): prefix, rel_path = match.groups() path = make_relative_static_path(static_dir, rel_path) if path in manifest.assets: versioned_path = manifest.assets[path]['versioned_path'] if isinstance(replacement_prefix, (list, tuple)): prefix = get_shard_from_list(replacement_prefix, versioned_path) else: prefix = replacement_prefix replacement_link = prefix.rstrip('/') + '/' + versioned_path.lstrip('/') logging.info('replacing %s -> %s', path, replacement_link) return replacement_link logging.warn('Missing path %s in manifest, using %s', path, match.group(0)) return match.group(0)
def build_manifest(tornado_paths, django_paths, settings): """Recursively builds the dependency manifest for the given list of source paths. """ assert isinstance(tornado_paths, (list, tuple)) assert isinstance(django_paths, (list, tuple)) paths = list(set(tornado_paths).union(set(django_paths))) # First, parse each template to build a list of AssetCompiler instances path_infos = [(x, 'tornado_template') for x in tornado_paths] path_infos += [(x, 'django_template') for x in django_paths] compilers = build_compilers(path_infos, settings) # Add each AssetCompiler's paths to our set of paths to search for deps paths = set(paths) for compiler in compilers: new_paths = compiler.get_paths() if settings.get('verbose'): print compiler, new_paths paths.update(new_paths) paths = list(paths) # Start building the new manifest manifest = Manifest(settings) _build_manifest_helper(settings['static_dir'], paths, settings['static_url_prefix'], manifest) assert all( make_relative_static_path(settings['static_dir'], path) in manifest.assets for path in paths) # Next, calculate the version hash for each entry in the manifest for src_path in manifest.assets: version_dependency(src_path, manifest) # Normalize and validate the manifest manifest.normalize() # Update the 'blocks' section of the manifest for each asset block for compiler in compilers: name_hash = compiler.get_hash() content_hash = compiler.get_current_content_hash(manifest) manifest.blocks[name_hash] = { 'version': content_hash, 'versioned_path': content_hash + '.' + compiler.get_ext(), } return manifest, compilers
def build_manifest(tornado_paths, django_paths, settings): """Recursively builds the dependency manifest for the given list of source paths. """ assert isinstance(tornado_paths, (list, tuple)) assert isinstance(django_paths, (list, tuple)) paths = list(set(tornado_paths).union(set(django_paths))) # First, parse each template to build a list of AssetCompiler instances path_infos = [(x, 'tornado_template') for x in tornado_paths] path_infos += [(x, 'django_template') for x in django_paths] compilers = build_compilers(path_infos, settings) # Add each AssetCompiler's paths to our set of paths to search for deps paths = set(paths) for compiler in compilers: new_paths = compiler.get_paths() if settings.get('verbose'): print compiler, new_paths paths.update(new_paths) paths = list(paths) # Start building the new manifest manifest = Manifest(settings) _build_manifest_helper(settings['static_dir'], paths, settings['static_url_prefix'], manifest) assert all(make_relative_static_path(settings['static_dir'], path) in manifest.assets for path in paths) # Next, calculate the version hash for each entry in the manifest for src_path in manifest.assets: version_dependency(src_path, manifest) # Normalize and validate the manifest manifest.normalize() # Update the 'blocks' section of the manifest for each asset block for compiler in compilers: name_hash = compiler.get_hash() content_hash = compiler.get_current_content_hash(manifest) manifest.blocks[name_hash] = { 'version': content_hash, 'versioned_path': content_hash + '.' + compiler.get_ext(), } return manifest, compilers