Пример #1
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
Пример #2
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
Пример #3
0
    def test_can_write_manifest_to_path(self):
        manifest = Manifest()
        manifest.load(compiled_asset_path=self.TEST_MANIFEST_PATH)

        #spoof a field update for now
        manifest.assets['test_field'] = "hello"

        manifest.write(compiled_asset_path=self.TEST_MANIFEST_PATH)

        with open(self.TEST_MANIFEST_PATH + '/manifest.json',
                  'r') as manifest_file:
            manifest_json = json.loads(manifest_file.read())
            for k, v in manifest_json.items():
                assert manifest._manifest.get(k) == v
Пример #4
0
    def test_can_write_manifest_to_path(self):
        manifest = Manifest()
        manifest.load(compiled_asset_path=self.TEST_MANIFEST_PATH)

        #spoof a field update for now
        manifest.assets['test_field'] = "hello"

        manifest.write(compiled_asset_path=self.TEST_MANIFEST_PATH)

        with open(self.TEST_MANIFEST_PATH + '/manifest.json', 'r') as manifest_file:
            manifest_json = json.loads(manifest_file.read())
            for k, v in manifest_json.items():
                assert manifest._manifest.get(k) == v
Пример #5
0
def run(settings):
    if not re.match(r'^/.*?/$', settings.get('static_url_prefix')):
        raise Exception(
            'static_url_prefix setting must begin and end with a slash')

    if not os.path.isdir(settings['compiled_asset_root']
                         ) and not settings['test_needs_compile']:
        logging.info('Creating output directory: %s',
                     settings['compiled_asset_root'])
        os.makedirs(settings['compiled_asset_root'])

    for d in settings['tornado_template_dirs'] + settings[
            'django_template_dirs']:
        if not os.path.isdir(d):
            raise Exception('Template directory not found: %r', d)

    if not os.path.isdir(settings['static_dir']):
        raise Exception('Static directory not found: %r',
                        settings['static_dir'])

    # Find all the templates we need to parse
    tornado_paths = list(
        iter_template_paths(settings['tornado_template_dirs'],
                            settings['template_extension']))
    django_paths = list(
        iter_template_paths(settings['django_template_dirs'],
                            settings['template_extension']))

    logging.debug('found %d tornado and %d django template paths',
                  len(tornado_paths), len(django_paths))
    if not tornado_paths and not django_paths:
        logging.warn("No templates found")

    # Load the current manifest and generate a new one
    cached_manifest = Manifest(settings).load()
    try:
        current_manifest, compilers = build_manifest(tornado_paths,
                                                     django_paths, settings)
    except ParseError, e:
        src_path, msg = e.args
        logging.error('Error parsing template %s', src_path)
        logging.error(msg)
        raise Exception
Пример #6
0
 def get_manifest(self):
     if not self._manifest:
         self._manifest = Manifest(self.settings).load()
     return self._manifest
Пример #7
0
 def test_can_get_manifest_path_from_asset_path(self):
     manifest = Manifest()
     path = manifest.get_path(self.TEST_MANIFEST_PATH)
     assert "tests/manifest.json" in path
Пример #8
0
    def test_can_open_manifest_path_from_settings(self):
        settings = Settings(compiled_asset_root=self.TEST_MANIFEST_PATH)

        manifest = Manifest(settings)
        path = manifest.get_path()
        assert "tests/manifest.json" in path
Пример #9
0
    def test_can_load_manifest_from_settings(self):
        settings = Settings(compiled_asset_root=self.TEST_MANIFEST_PATH)

        manifest = Manifest(settings).load()
        assert manifest
        assert manifest.blocks.keys()
Пример #10
0
 def test_can_load_manifest_from_asset_path(self):
     manifest = Manifest().load(self.TEST_MANIFEST_PATH)
     assert manifest
     assert manifest.blocks.keys()
Пример #11
0
 def test_can_get_manifest_path_from_asset_path(self):
     manifest = Manifest()
     path = manifest.get_path(self.TEST_MANIFEST_PATH)
     assert "tests/manifest.json" in path
Пример #12
0
    def test_can_open_manifest_path_from_settings(self):
        settings = Settings(compiled_asset_root=self.TEST_MANIFEST_PATH)

        manifest = Manifest(settings)
        path = manifest.get_path()
        assert "tests/manifest.json" in path