示例#1
0
    def test_story_of_two_envs(self):
        """If an app is served by multiple processes, and auto_build is used,
        if one process rebuilds a bundle, the other one must know (instead of
        continuing to serve the old version.

        For this reason, if auto_build is enabled, the version will always be
        determined anew in every request, rather than using a cached version.
        (This is the reason why get_version() has the refresh=True option).
        """
        # Prepare a manifest and bundle in env1. Use a file manifest
        env1 = self.env
        env1.url_expire = True
        bundle1 = self.mkbundle('in', output='out-%(version)s')

        # Prepare an identical setup, simulating the second process
        env2 = Environment(env1.directory, env1.url)
        env2.config.update(copy.deepcopy(env1.config._dict))
        bundle2 = self.mkbundle('in', output='out-%(version)s')
        bundle2.env = env2

        # Both have auto build enabled, both are using the same manifest
        env1.auto_build = env2.auto_build = True
        env1.manifest = 'file'
        env2.manifest = 'file'
        env1.updater = 'timestamp'
        env2.updater = 'timestamp'

        # Do the initial build, both envs think they are running the
        # latest version.
        env1.versions.version = bundle1.version = 'old'
        env2.versions.version = bundle2.version = 'old'
        bundle1.build()
        assert env2.updater.needs_rebuild(bundle2, env2) == False

        # At this point, both return the old version in urls
        assert bundle1.urls() == ['/out-old?old']
        assert bundle2.urls() == ['/out-old?old']

        # Now let env1 do an update.
        env1.versions.version = 'new'
        bundle1.build(force=True)
        assert bundle1.urls() == ['/out-new?new']

        # If auto_build is False, env2 will continue to use the old version.
        env2.auto_build = False
        assert bundle2.urls() == ['/out-old?old']
        # However, if auto_build is True, env2 will know the new version.
        # This is because env1 wrote it to the manifest during build.
        env2.auto_build = True
        assert bundle2.get_version() == 'old'  # urls() causes the refresh
        assert bundle2.urls() == ['/out-new?new']
        assert bundle2.get_version() == 'new'

        # The reverse works as well.
        env2.versions.version = 'latest'
        bundle2.build(force=True)
        assert bundle1.urls() == bundle2.urls() == ['/out-latest?latest']
    def test_story_of_two_envs(self):
        """If an app is served by multiple processes, and auto_build is used,
        if one process rebuilds a bundle, the other one must know (instead of
        continuing to serve the old version.

        For this reason, if auto_build is enabled, the version will always be
        determined anew in every request, rather than using a cached version.
        (This is the reason why get_version() has the refresh=True option).
        """
        # Prepare a manifest and bundle in env1. Use a file manifest
        env1 = self.env
        env1.url_expire = True
        bundle1 = self.mkbundle('in', output='out-%(version)s')

        # Prepare an identical setup, simulating the second process
        env2 = Environment(env1.directory, env1.url)
        env2.config.update(copy.deepcopy(env1.config._dict))
        bundle2  = self.mkbundle('in', output='out-%(version)s')
        bundle2.env = env2

        # Both have auto build enabled, both are using the same manifest
        env1.auto_build = env2.auto_build = True
        env1.manifest = 'file'; env2.manifest = 'file'
        env1.updater = 'timestamp'; env2.updater = 'timestamp'

        # Do the initial build, both envs think they are running the
        # latest version.
        env1.versions.version = bundle1.version = 'old'
        env2.versions.version = bundle2.version = 'old'
        bundle1.build()
        assert env2.updater.needs_rebuild(bundle2, env2) == False

        # At this point, both return the old version in urls
        assert bundle1.urls() ==['/out-old?old']
        assert bundle2.urls() ==['/out-old?old']

        # Now let env1 do an update.
        env1.versions.version = 'new'
        bundle1.build(force=True)
        assert bundle1.urls() == ['/out-new?new']

        # If auto_build is False, env2 will continue to use the old version.
        env2.auto_build = False
        assert bundle2.urls() == ['/out-old?old']
        # However, if auto_build is True, env2 will know the new version.
        # This is because env1 wrote it to the manifest during build.
        env2.auto_build = True
        assert bundle2.get_version() == 'old'    # urls() causes the refresh
        assert bundle2.urls() == ['/out-new?new']
        assert bundle2.get_version() == 'new'

        # The reverse works as well.
        env2.versions.version = 'latest'
        bundle2.build(force=True)
        assert bundle1.urls() == bundle2.urls() == ['/out-latest?latest']
示例#3
0

config = get_config()

app = Flask(__name__, static_url_path='')

app.jinja_loader = jinja2.FileSystemLoader([
    os.path.abspath(os.path.join(app.root_path, "templates")),
    os.path.abspath(os.path.abspath("static-templates")),
])

push = PushBullet(config["pushbullet"]["api-key"])

assets = Environment(os.path.abspath(os.path.join("static", "assets")), "assets/")
assets.append_path(app.static_folder, "/")
assets.auto_build = False
assets.url_expire = True
assets.cache = False
assets.manifest = "file:{}".format(os.path.abspath(os.path.join("static", ".webassets-manifest")))

# Create assets
assets.register('bootstrap-css', 'css/bootstrap.css',
                filters='cssmin', output='bootstrap.css')

assets.register('sidebar-css', 'css/bootstrap.css', 'css/shared-sidebar.css',
                filters='cssmin', output='shared.css')

assets.register('frc-css', 'css/bootstrap.css', 'css/frc.css',
                filters='cssmin', output='frc.css')

assets.register('markdown-css', 'css/bootstrap.css', 'css/markdown-sidebar.css',
示例#4
0
config = configuration_resources.get_config()

app = Flask(__name__, static_url_path='')

app.jinja_loader = jinja2.FileSystemLoader([
    os.path.abspath(os.path.join(app.root_path, "templates")),
    os.path.abspath(os.path.abspath("static-templates")),
])

push = configuration_resources.get_pushbullet()
redis = StrictRedis()

assets = Environment(os.path.abspath(os.path.join("static", "assets")),
                     "assets/")
assets.append_path(app.static_folder, "/")
assets.auto_build = False
assets.url_expire = True
assets.cache = False
assets.manifest = "file:{}".format(
    os.path.abspath(os.path.join("static", ".webassets-manifest")))

# Create assets
assets.register('bootstrap-css',
                'css/bootstrap.css',
                filters='cssmin',
                output='bootstrap.css')

assets.register('sidebar-css',
                'css/shared-sidebar.css',
                'css/bootstrap.css',
                filters='cssmin',