Example #1
0
def render_all():
    """
    Render HTML templates and compile assets.
    """
    from flask import g

    require('slug', provided_by=['post'])

    less()
    app_config_js()
    copytext_js(env.slug)

    compiled_includes = {}

    app_config.configure_targets(env.get('settings', None))

    with app.app.test_request_context():
        path = 'posts/%s/www/index.html' % env.slug

    with app.app.test_request_context(path=env.static_path):
        print 'Rendering %s' % path

        g.compile_includes = True
        g.compiled_includes = compiled_includes

        view = app.__dict__['_post']
        content = view(env.slug).data

    with open(path, 'w') as f:
        f.write(content)
def staging():
    """
    Run as though on staging.
    """
    env.settings = 'staging'
    app_config.configure_targets(env.settings)
    env.hosts = app_config.SERVERS
Example #3
0
def _render_iterable(iterable, model, lookup):
    """
    View should be named _model_detail().
    Path should be model-lookup.html.
    Template is handled from the view.
    """

    from flask import g

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    compiled_includes = []

    for instance in iterable:
        path = '%s-%s.html' % (model, getattr(instance, lookup))
        with app.app.test_request_context(path=path):

            g.compile_includes = True
            g.compiled_includes = compiled_includes

            view = app.__dict__['_%s_detail' % model]
            content = view(getattr(instance, lookup))

            compiled_includes = g.compiled_includes

        with open('www/%s' % path, 'w') as f:
            f.write(content.encode('utf-8'))

    # Un-fake-out deployment target
    app_config.configure_targets(env.settings)
def production():
    """
    Run as though on production.
    """
    env.settings = 'production'
    app_config.configure_targets(env.settings)
    env.hosts = app_config.SERVERS
Example #5
0
def deploy_data():
    """
    Deploy the latest data to S3.
    """
    write_data_csv()
    write_data_json()

    require("settings", provided_by=[production, staging])

    if env.settings == "production" and env.branch != "stable":
        _confirm(
            "You are trying to deploy the '%(branch)s' branch to production.\nYou should really only deploy a stable branch.\nDo you know what you're doing?"
            % env
        )

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get("settings", None))

    for filename in ["npr-accessible-playgrounds.csv", "npr-accessible-playgrounds.json"]:
        s3cmd = "s3cmd -P --add-header=Cache-Control:max-age=5 --guess-mime-type --recursive sync %s %s"

        for bucket in app_config.S3_BUCKETS:
            os.system(s3cmd % ("www/%s" % filename, "s3://%s/" % (bucket)))

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
def _render_iterable(iterable, model, lookup):
    """
    View should be named _model_detail().
    Path should be model-lookup.html.
    Template is handled from the view.
    """

    from flask import g

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    compiled_includes = []

    for instance in iterable:
        path = '%s-%s.html' % (model, getattr(instance, lookup))
        with app.app.test_request_context(path=path):

            g.compile_includes = True
            g.compiled_includes = compiled_includes

            view = app.__dict__['_%s_detail' % model]
            content = view(getattr(instance, lookup))

            compiled_includes = g.compiled_includes

        with open('www/%s' % path, 'w') as f:
            f.write(content.encode('utf-8'))

    # Un-fake-out deployment target
    app_config.configure_targets(env.settings)
Example #7
0
def write_snapshots():
    require("settings", provided_by=[production, staging])

    if env.settings == "production" and env.branch != "stable":
        _confirm(
            "You are trying to deploy the '%(branch)s' branch to production.\nYou should really only deploy a stable branch.\nDo you know what you're doing?"
            % env
        )

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get("settings", None))

    os.system("rm -rf .backups_gzip")
    os.system("rm -rf data/backups/.placeholder")

    data.gzip("data/backups", ".backups_gzip")

    s3cmd = "s3cmd -P --add-header=Cache-Control:max-age=5 --guess-mime-type --recursive --exclude-from gzip_types.txt sync %s/ %s"
    s3cmd_gzip = 's3cmd -P --add-header=Cache-Control:max-age=5 --add-header=Content-encoding:gzip --guess-mime-type --recursive --exclude "*" --include-from gzip_types.txt sync %s/ %s'

    for bucket in app_config.S3_BUCKETS:
        os.system(s3cmd % (".backups_gzip", "s3://%s/backups/" % (bucket)))
        os.system(s3cmd_gzip % (".backups_gzip", "s3://%s/backups/" % (bucket)))

    os.system("rm -rf .backups_gzip")
    os.system("rm -rf data/backups")
    os.system("mkdir -p data/backups")
    os.system("touch data/backups/.placeholder")

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #8
0
def deploy_playgrounds():
    require("settings", provided_by=[production, staging])

    if env.settings == "production" and env.branch != "stable":
        _confirm(
            "You are trying to deploy the '%(branch)s' branch to production.\nYou should really only deploy a stable branch.\nDo you know what you're doing?"
            % env
        )

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get("settings", None))

    os.system("rm -rf .playgrounds_html")
    os.system("rm -rf .playgrounds_gzip")

    render_playgrounds()
    _gzip(".playgrounds_html", ".playgrounds_gzip")
    _deploy_to_s3(".playgrounds_gzip")

    _gzip()
    _deploy_to_s3()

    os.system("rm -rf .playgrounds_html")
    os.system("rm -rf .playgrounds_gzip")

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #9
0
def deploy(remote="origin"):
    """
    Deploy the latest app to S3 and, if configured, to our servers.
    """
    require("settings", provided_by=[production, staging])

    if env.get("deploy_to_servers", False):
        require("branch", provided_by=[stable, master, branch])

    if env.settings == "production" and env.branch != "stable":
        _confirm(
            "You are trying to deploy the '%(branch)s' branch to production.\nYou should really only deploy a stable branch.\nDo you know what you're doing?"
            % env
        )

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get("settings", None))

    render()
    _gzip()
    _deploy_to_s3()

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)

    if env["deploy_to_servers"]:
        install_google_oauth_creds()
        checkout_latest(remote)

        if env["deploy_crontab"]:
            install_crontab()

        if env["deploy_services"]:
            deploy_confs()
Example #10
0
def render():
    """
    Render HTML templates and compile assets.
    """
    update_index()

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    for rule in app.app.url_map.iter_rules():
        rule_string = rule.rule
        name = rule.endpoint

        if name == 'static':
            continue

        filename = 'www' + rule_string

        print 'Rendering %s' % (filename)

        with app.app.test_request_context(path=rule_string):
            view = app.__dict__[name]
            content = view()[0]

        with open(filename, 'w') as f:
            f.write(content.encode('utf-8'))

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #11
0
def deploy(remote='origin'):
    """
    Deploy the latest app to S3 and, if configured, to our servers.
    """
    require('settings', provided_by=[production, staging])

    if env.get('deploy_to_servers', False):
        require('branch', provided_by=[stable, master, branch])

    if (env.settings == 'production' and env.branch != 'stable'):
        _confirm("You are trying to deploy the '%(branch)s' branch to production.\nYou should really only deploy a stable branch.\nDo you know what you're doing?" % env)

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get('settings', None))

    render()
    _gzip()
    _deploy_to_s3()

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)

    if env['deploy_to_servers']:
        checkout_latest(remote)

        if env['deploy_crontab']:
            install_crontab()

        if env['deploy_services']:
            deploy_confs()
Example #12
0
def render_theme(slug):
    """
    Renders the tumblr theme.
    Requires knowing what environment you want.
    """
    require('settings', provided_by=[production, staging, development])

    from flask import g

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    compiled_includes = []

    path = '%s-theme.html' % slug
    with app.app.test_request_context(path=path):

        g.compile_includes = True
        g.compiled_includes = compiled_includes

        view = app.__dict__['_render_tumblr_theme']
        content = view(slug)

        compiled_includes = g.compiled_includes

    with open(path, 'w') as f:
        f.write(content.encode('utf-8'))

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #13
0
def render():
    """
    Render the Tumblr theme.
    """
    from flask import g
    
    less()
    app_config_js()

    compiled_includes = {}

    app_config.configure_targets(env.get('settings', None))

    path = 'theme/www/index.html'

    with app.app.test_request_context(path='/theme'):
        print 'Rendering %s' % path

        if env.settings not in ['staging', 'production']:
            g.compile_includes = False
        else:
            g.compile_includes = True

        g.compiled_includes = compiled_includes

        view = static_theme.__dict__['_theme']
        content = view()

    with open(path, 'w') as f:
        f.write(content.encode('utf-8'))

    local('pbcopy < theme/www/index.html')
    print 'The Tumblr theme HTML has been copied to your clipboard.'
    local('open https://www.tumblr.com/customize/%s' % app_config.TUMBLR_NAME)
Example #14
0
def production():
    """
    Run as though on production.
    """
    env.settings = 'production'
    app_config.configure_targets(env.settings)
    env.hosts = app_config.SERVERS
Example #15
0
def development():
    """
    Run as though on staging.
    """
    env.settings = 'development'
    app_config.configure_targets(env.settings)
    env.hosts = app_config.SERVERS
Example #16
0
def render():
    from flask import g

    require('static_path', provided_by=['tumblr'])
    require('settings', provided_by=['staging', 'production', 'development'])
    less()
    app_config_js()
    copytext_js('theme')

    compiled_includes = {}

    app_config.configure_targets(env.get('settings', None))

    with app.app.test_request_context():
        path = 'tumblr/www/index.html'

    with app.app.test_request_context(path=env.static_path):
        print 'Rendering %s' % path

        if env.settings == 'development':
            g.compile_includes = False
        else:
            g.compile_includes = True

        g.compiled_includes = compiled_includes

        view = static_theme.__dict__['_theme']
        content = view().data

    with open(path, 'w') as f:
        f.write(content)

    local('pbcopy < tumblr/www/index.html')
    print 'The Tumblr theme HTML has been copied to your clipboard.'
    local('open https://www.tumblr.com/customize/%s' % app_config.TUMBLR_NAME)
Example #17
0
def _render_graphics(paths):
    """
    Render a set of graphics
    """
    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    for path in paths:
        slug = path.split('%s/' % app_config.GRAPHICS_PATH)[1].split('/')[0]

        with app.app.test_request_context(path='graphics/%s/' % slug):
            view = app.__dict__['_graphics_detail']
            content = view(slug)

        with open('%s/index.html' % path, 'w') as writefile:
            writefile.write(content.encode('utf-8'))

        # Fallback for legacy projects w/o child templates
        if not os.path.exists('%s/child_template.html' % path):
            continue

        download_copy(slug)

        with app.app.test_request_context(path='graphics/%s/child.html' % slug):
            view = app.__dict__['_graphics_child']
            content = view(slug)

        with open('%s/child.html' % path, 'w') as writefile:
            writefile.write(content.encode('utf-8'))

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #18
0
    def test_remove_from_search_index(self):
        app_config.configure_targets('staging')

        utils.load_test_playgrounds()

        playground = Playground.select()[0]

        sdf = playground.sdf()
        sdf['id'] = 'test_%i' % playground.id
        sdf['fields']['name'] = 'THIS IS NOT A PLAYGROUND NAME axerqwak'
        sdf['fields']['deployment_target'] = 'test'

        response = requests.post('http://%s/2011-02-01/documents/batch' % app_config.CLOUD_SEARCH_DOC_DOMAIN, data=json.dumps([sdf]), headers={ 'Content-Type': 'application/json' })

        self.assertEqual(response.status_code, 200)

        # Monkey patch delete_sdf to so it return test id
        delete_sdf = playground.delete_sdf()
        delete_sdf['id'] = 'test_%i' % playground.id
        delete_sdf['version'] = sdf['version'] + 1

        old_func = playground.delete_sdf
        playground.delete_sdf = lambda: delete_sdf

        playground.remove_from_search_index()

        playground.delete_sdf = old_func

        response = requests.get('http://%s/2011-02-01/search' % app_config.CLOUD_SEARCH_DOMAIN, params={ 'q': 'axerqwak' }, headers={ 'Cache-Control': 'revalidate' })

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['hits']['found'], 0)

        app_config.configure_targets(None)
Example #19
0
def deploy_playgrounds():
    require('settings', provided_by=[production, staging])

    if (env.settings == 'production' and env.branch != 'stable'):
        _confirm("You are trying to deploy the '%(branch)s' branch to production.\nYou should really only deploy a stable branch.\nDo you know what you're doing?" % env)

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get('settings', None))

    os.system('rm -rf .playgrounds_html')
    os.system('rm -rf .playgrounds_gzip')

    render_playgrounds()
    _gzip('.playgrounds_html', '.playgrounds_gzip')
    _deploy_to_s3('.playgrounds_gzip')

    _gzip()
    _deploy_to_s3()

    os.system('rm -rf .playgrounds_html')
    os.system('rm -rf .playgrounds_gzip')

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #20
0
def deploy_data():
    """
    Deploy the latest data to S3.
    """
    write_data_csv()
    write_data_json()

    require('settings', provided_by=[production, staging])

    if (env.settings == 'production' and env.branch != 'stable'):
        _confirm(
            "You are trying to deploy the '%(branch)s' branch to production.\nYou should really only deploy a stable branch.\nDo you know what you're doing?"
            % env)

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get('settings', None))

    for filename in [
            'npr-accessible-playgrounds.csv', 'npr-accessible-playgrounds.json'
    ]:
        s3cmd = 's3cmd -P --add-header=Cache-Control:max-age=5 --guess-mime-type --recursive sync %s %s'

        for bucket in app_config.S3_BUCKETS:
            os.system(s3cmd % ('www/%s' % filename, 's3://%s/' % (bucket)))

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #21
0
def write_snapshots():
    require('settings', provided_by=[production, staging])

    if (env.settings == 'production' and env.branch != 'stable'):
        _confirm("You are trying to deploy the '%(branch)s' branch to production.\nYou should really only deploy a stable branch.\nDo you know what you're doing?" % env)

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get('settings', None))

    os.system('rm -rf .backups_gzip')
    os.system('rm -rf data/backups/.placeholder')

    data.gzip('data/backups', '.backups_gzip')

    s3cmd = 's3cmd -P --add-header=Cache-Control:max-age=5 --guess-mime-type --recursive --exclude-from gzip_types.txt sync %s/ %s'
    s3cmd_gzip = 's3cmd -P --add-header=Cache-Control:max-age=5 --add-header=Content-encoding:gzip --guess-mime-type --recursive --exclude "*" --include-from gzip_types.txt sync %s/ %s'

    for bucket in app_config.S3_BUCKETS:
        os.system(s3cmd % ('.backups_gzip', 's3://%s/%s/backups/' % (bucket, app_config.PROJECT_SLUG)))
        os.system(s3cmd_gzip % ('.backups_gzip', 's3://%s/%s/backups/' % (bucket, app_config.PROJECT_SLUG)))

    os.system('rm -rf .backups_gzip')
    os.system('rm -rf data/backups')
    os.system('mkdir -p data/backups')
    os.system('touch data/backups/.placeholder')

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #22
0
def _render_graphics(paths):
    """
    Render a set of graphics
    """
    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    for path in paths:
        slug = path.split('%s/' % app_config.GRAPHICS_PATH)[1].split('/')[0]

        with flat_app.app.test_request_context(path='graphics/%s/' % slug):
            view = flat_app.__dict__['_graphics_detail']
            content = view(slug).data

        with open('%s/index.html' % path, 'w') as writefile:
            writefile.write(content)

        # Fallback for legacy projects w/o child templates
        if not os.path.exists('%s/child_template.html' % path):
            continue

        download_copy(slug)

        with flat_app.app.test_request_context(path='graphics/%s/child.html' % slug):
            view = flat_app.__dict__['_graphics_child']
            content = view(slug).data

        with open('%s/child.html' % path, 'w') as writefile:
            writefile.write(content)

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #23
0
def sitemap():
    """
    Render and deploy sitemap.
    """
    require('settings', provided_by=[staging, production])

    app_config.configure_targets(env.get('settings', None))

    with flat_app.app.test_request_context(path='sitemap.xml'):
        print 'Rendering sitemap.xml'

        view = flat_app.__dict__['_sitemap']
        content = view().data

    with open('.sitemap.xml', 'w') as f:
        f.write(content)

    s3 = boto.connect_s3()

    flat.deploy_file(
        s3,
        '.sitemap.xml',
        app_config.PROJECT_SLUG,
        app_config.DEFAULT_MAX_AGE
    )
Example #24
0
def staging():
    """
    Run as though on staging.
    """
    env.settings = 'staging'
    app_config.configure_targets(env.settings)
    env.hosts = app_config.SERVERS
Example #25
0
def production():
    """
    Run as though on production.
    """
    env.settings = 'production'
    app_config.configure_targets(env.settings)
    logger.setLevel(app_config.LOG_LEVEL)
    env.hosts = app_config.SERVERS
Example #26
0
def staging():
    """
    Run as though on staging.
    """
    env.settings = 'staging'
    app_config.configure_targets(env.settings)
    logger.setLevel(app_config.LOG_LEVEL)
    env.hosts = app_config.SERVERS
Example #27
0
def production():
    """
    Run as though on production.
    """
    env.settings = 'production'
    app_config.configure_targets(env.settings)
    env.hosts = app_config.SERVERS
    env.tumblr_blog_name = 'lookatthis'
Example #28
0
def deploy_aggregates():
    """
    Deploys aggregates JSON to S3.
    Calls write_aggregates().
    """
    require('settings', provided_by=[production, staging])
    app_config.configure_targets(env.get('settings', None))
    write_aggregates()
    tumblr_utils.deploy_aggregates(env.s3_buckets)
Example #29
0
def random_prod():
    """
    Run as though on production but with randomness added to the slug so
    that it is not traceable.
    """
    env.settings = 'random_prod'
    app_config.configure_targets(env.settings)
    logger.setLevel(app_config.LOG_LEVEL)
    env.hosts = app_config.SERVERS
Example #30
0
def deploy_aggregates():
    """
    Deploys aggregates JSON to S3.
    Calls write_aggregates().
    """
    require('settings', provided_by=[production, staging])
    app_config.configure_targets(env.get('settings', None))
    write_aggregates()
    tumblr_utils.deploy_aggregates(env.s3_buckets)
Example #31
0
def render():
    """
    Render HTML templates and compile assets.
    """
    from flask import g

    # COMMENTING THIS OUT B/C THIS PROJECT NEEDS TO BE UPDATED TO SUPPORT
    # XLSX FILES. NOW RELYING ON /data/copy.xls FILE STORED W/ REPO
    # update_copy()
    less()
    jst()

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    app_config_js()

    compiled_includes = []

    for rule in app.app.url_map.iter_rules():
        rule_string = rule.rule
        name = rule.endpoint

        if name == 'static' or name.startswith('_'):
            print 'Skipping %s' % name
            continue

        if rule_string.endswith('/'):
            filename = 'www' + rule_string + 'index.html'
        elif rule_string.endswith('.html'):
            filename = 'www' + rule_string
        else:
            print 'Skipping %s' % name
            continue

        dirname = os.path.dirname(filename)

        if not (os.path.exists(dirname)):
            os.makedirs(dirname)

        print 'Rendering %s' % (filename)

        with app.app.test_request_context(path=rule_string):
            g.compile_includes = True
            g.compiled_includes = compiled_includes

            view = app.__dict__[name]
            content = view()

            compiled_includes = g.compiled_includes

        with open(filename, 'w') as f:
            f.write(content.encode('utf-8'))

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #32
0
def render():
    """
    Render HTML templates and compile assets.
    """
    from flask import g

    update_copy()
    less()
    jst()

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    app_config_js()

    compiled_includes = []

    for rule in app.app.url_map.iter_rules():
        rule_string = rule.rule
        name = rule.endpoint

        if name == 'static' or name.startswith('_'):
            print 'Skipping %s' % name
            continue

        if rule_string.endswith('/'):
            filename = 'www' + rule_string + 'index.html'
        elif rule_string.endswith('.html'):
            filename = 'www' + rule_string
        elif rule_string.endswith('.json'):
            filename = 'www' + rule_string
        else:
            print 'Skipping %s' % name
            continue

        dirname = os.path.dirname(filename)

        if not (os.path.exists(dirname)):
            os.makedirs(dirname)

        print 'Rendering %s' % (filename)

        with app.app.test_request_context(path=rule_string):
            g.compile_includes = True
            g.compiled_includes = compiled_includes

            view = app.__dict__[name]
            content = view()

            compiled_includes = g.compiled_includes

        with open(filename, 'w') as f:
            f.write(content.encode('utf-8'))

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #33
0
    def test_app_config_production(self):
        app_config.configure_targets('production')

        response = self.client.get('/js/app_config.js')

        data = self.parse_data(response)

        assert data['DEBUG'] == False

        app_config.configure_targets('staging')
Example #34
0
    def test_app_config_production(self):
        app_config.configure_targets("production")

        response = self.client.get("/js/app_config.js")

        data = self.parse_data(response)

        assert data["DEBUG"] is False

        app_config.configure_targets("staging")
Example #35
0
    def test_app_config_production(self):
        app_config.configure_targets('production')

        response = self.client.get('/js/app_config.js')

        data = self.parse_data(response)

        assert data['DEBUG'] is False

        app_config.configure_targets('staging')
Example #36
0
def render():
    """
    Render HTML templates and compile assets.
    """
    from flask import g

    update_copy()
    less()
    jst()

    # Fake out deployment target
    app_config.configure_targets(env.get("settings", None))

    app_config_js()

    compiled_includes = []

    for rule in app.app.url_map.iter_rules():
        rule_string = rule.rule
        name = rule.endpoint

        if name == "static" or name.startswith("_"):
            print "Skipping %s" % name
            continue

        if rule_string.endswith("/"):
            filename = "www" + rule_string + "index.html"
        elif rule_string.endswith(".html"):
            filename = "www" + rule_string
        else:
            print "Skipping %s" % name
            continue

        dirname = os.path.dirname(filename)

        if not (os.path.exists(dirname)):
            os.makedirs(dirname)

        print "Rendering %s" % (filename)

        with app.app.test_request_context(path=rule_string):
            g.compile_includes = True
            g.compiled_includes = compiled_includes

            view = app.__dict__[name]
            content = view()

            compiled_includes = g.compiled_includes

        with open(filename, "w") as f:
            f.write(content.encode("utf-8"))

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #37
0
def render():
    """
    Render HTML templates and compile assets.
    """
    from flask import g

    less()
    jst()

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    app_config_js()

    compiled_includes = []

    for rule in app.app.url_map.iter_rules():
        rule_string = rule.rule
        name = rule.endpoint

        if name == 'static' or name.startswith('_'):
            print 'Skipping %s' % name
            continue

        if rule_string.endswith('/'):
            filename = 'www' + rule_string + 'index.html'
        elif rule_string.endswith('.html'):
            filename = 'www' + rule_string
        else:
            print 'Skipping %s' % name
            continue

        dirname = os.path.dirname(filename)

        if not (os.path.exists(dirname)):
            os.makedirs(dirname)

        print 'Rendering %s' % (filename)

        with app.app.test_request_context(path=rule_string):
            g.compile_includes = True
            g.compiled_includes = compiled_includes

            view = app.__dict__[name]
            content = view()

            compiled_includes = g.compiled_includes

        with open(filename, 'w') as f:
            f.write(content)

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #38
0
def render():
    """
    Render HTML templates and compile assets.
    """
    from flask import g

    less()
    jst()

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    app_config_js()

    compiled_includes = []

    for rule in app.app.url_map.iter_rules():
        rule_string = rule.rule
        name = rule.endpoint

        if name == 'static':
            print 'Skipping %s' % name
            continue

        if name.startswith('_'):
            print 'Skipping %s' % name
            continue

        if rule_string.endswith('/'):
            filename = 'www' + rule_string + 'index.html'
        else:
            filename = 'www' + rule_string

        print 'Rendering %s' % (filename)

        with app.app.test_request_context(path=rule_string):
            g.compile_includes = True
            g.compiled_includes = compiled_includes

            view = app.__dict__[name]
            content = view()

            compiled_includes = g.compiled_includes

        if not isinstance(content, basestring):
            content = content[0]

        with open(filename, 'w') as f:
            f.write(content)

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #39
0
def update_search_index(playgrounds=None):
    """
    Batch upload playgrounds to CloudSearch as SDF.
    """
    require("settings", provided_by=[production, staging])

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get("settings", None))

    data.update_search_index(playgrounds)

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #40
0
def update_search_index(playgrounds=None):
    """
    Batch upload playgrounds to CloudSearch as SDF.
    """
    require('settings', provided_by=[production, staging])

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get('settings', None))

    data.update_search_index(playgrounds)

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #41
0
def _render_graphics(paths, custom_location=False):
    """
    Render a set of graphics
    """
    from flask import g

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    for path in paths:
        slug = path.split('/')[-1]
        with app.app.test_request_context(path='graphics/%s/' % slug):
            g.compile_includes = True
            g.compiled_includes = {}
            if custom_location:
                # warning message
                g.custom_location = True
                g.alt_path = path
                # Test if there's a local pym copy
                if os.path.exists('%s/js/lib/pym.js' % path):
                    g.local_pym = True
            view = app.graphic.__dict__['_graphics_detail']
            content = view(slug).data

        with open('%s/index.html' % path, 'w') as writefile:
            writefile.write(content)

        # Fallback for legacy projects w/o child templates
        if not os.path.exists('%s/child_template.html' % path):
            continue

        with app.app.test_request_context(path='graphics/%s/child.html' % (
                slug)):
            g.compile_includes = True
            g.compiled_includes = {}
            if custom_location:
                g.alt_path = path
            view = app.graphic.__dict__['_graphics_child']
            content = view(slug).data

        with open('%s/child.html' % path, 'w') as writefile:
            writefile.write(content)

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #42
0
def _render_graphics(paths, custom_location=False):
    """
    Render a set of graphics
    """
    from flask import g

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    for path in paths:
        slug = path.split('/')[-1]
        with app.app.test_request_context(path='graphics/%s/' % slug):
            g.compile_includes = True
            g.compiled_includes = {}
            if custom_location:
                # warning message
                g.custom_location = True
                g.alt_path = path
                # Test if there's a local pym copy
                if os.path.exists('%s/js/lib/pym.js' % path):
                    g.local_pym = True
            view = app.graphic.__dict__['_graphics_detail']
            content = view(slug).data

        with open('%s/index.html' % path, 'w') as writefile:
            writefile.write(content)

        # Fallback for legacy projects w/o child templates
        if not os.path.exists('%s/child_template.html' % path):
            continue

        with app.app.test_request_context(path='graphics/%s/child.html' %
                                          (slug)):
            g.compile_includes = True
            g.compiled_includes = {}
            if custom_location:
                g.alt_path = path
            view = app.graphic.__dict__['_graphics_child']
            content = view(slug).data

        with open('%s/child.html' % path, 'w') as writefile:
            writefile.write(content)

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #43
0
    def test_delete_playground_confirm(self):
        utils.load_test_playgrounds()

        app_config.configure_targets('staging')

        s3 = boto.connect_s3()
        bucket = s3.get_bucket(app_config.S3_BUCKETS[0])
        k = Key(bucket)
        k.key = '%s/playground/%s.html' % (app_config.PROJECT_SLUG, Playground.get(id=1).slug)
        k.set_contents_from_string('foo')

        response = self.client.get(url_for('delete_playground_confirm', playground_slug=Playground.get(id=1).slug))

        self.assertEqual(response.status_code, 200)
        self.assertFalse(Playground.get(id=1).active)

        self.assertIsNone(bucket.get_key(k.key))
        app_config.configure_targets(None)
Example #44
0
def render_embed():
    """
    Render pym embed and copy to clipboard
    """

    require('settings', provided_by=['development', 'staging', 'production'])
    app_config.configure_targets(env.get('settings', None))

    with app.app.test_request_context():
        filename = 'www/pym_embed.html'
        view = app.__dict__['embed']
        content = view()

    with open(filename, 'w') as f:
        f.write(content.encode('utf-8'))

    local('pbcopy < www/pym_embed.html')
    print 'The pym embed HTML has been copied to your clipboard.'
Example #45
0
def render_embed():
    """
    Render pym embed and copy to clipboard
    """

    require('settings', provided_by=['development', 'staging', 'production'])
    app_config.configure_targets(env.get('settings', None))

    with app.app.test_request_context():
        filename = 'www/pym_embed.html'
        view = app.__dict__['embed']
        content = view()

    with open(filename, 'w') as f:
        f.write(content.encode('utf-8'))

    local('pbcopy < www/pym_embed.html')
    print 'The pym embed HTML has been copied to your clipboard.'
Example #46
0
def clear_search_index():
    """
    Clear all documents from the search index. We use a hack for this:
    Iterate through a wide range of unique id's and issue a delete for
    all of them. This way we pick up one's that might not be in our
    local database anymore.
    """
    require('settings', provided_by=[production, staging])

    _confirm(
        "You are about to delete the %(settings)s search index for this project.\nDo you know what you're doing?"
        % env)

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get('settings', None))

    print 'Generating SDF batch...'
    sdf = []

    for i in range(0, 10000):
        sdf.append({
            'type': 'delete',
            'id': '%s_%i' % (app_config.DEPLOYMENT_TARGET, i),
            'version': int(time.time())
        })

    payload = json.dumps(sdf)

    if len(payload) > 5000 * 1024:
        print 'Exceeded 5MB limit for SDF uploads!'
        return

    print 'Uploading to CloudSearch...'
    response = requests.post('http://%s/2011-02-01/documents/batch' %
                             app_config.CLOUD_SEARCH_DOC_DOMAIN,
                             data=payload,
                             headers={'Content-Type': 'application/json'})

    print response.status_code
    print response.text

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #47
0
def _render_graphics(paths):
    """
    Render a set of graphics
    """
    from flask import g

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    for path in paths:
        filename = os.path.split(path)[-1]
        slug = os.path.splitext(filename)[0]

        with app.app.test_request_context(path='%s/' % slug):
            g.compile_includes = True
            g.compiled_includes = {}

            view = app.__dict__['parent']
            content = view(slug).data

        if not os.path.exists('www/%s' % slug):
            os.makedirs('www/%s' % slug)

        with open('www/%s/index.html' % slug, 'w') as writefile:
            writefile.write(content)

        with app.app.test_request_context(path='%s/child.html' % slug):
            g.compile_includes = True
            g.compiled_includes = {}

            view = app.__dict__['child']
            content = view(slug).data

        with open('www/%s/child.html' % slug, 'w') as writefile:
            writefile.write(content)

    app_config_js()
    copytext_js()
    local('npm run build')

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #48
0
def clear_search_index():
    """
    Clear all documents from the search index. We use a hack for this:
    Iterate through a wide range of unique id's and issue a delete for
    all of them. This way we pick up one's that might not be in our
    local database anymore.
    """
    require("settings", provided_by=[production, staging])

    _confirm(
        "You are about to delete the %(settings)s search index for this project.\nDo you know what you're doing?" % env
    )

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get("settings", None))

    print "Generating SDF batch..."
    sdf = []

    for i in range(0, 10000):
        sdf.append({"type": "delete", "id": "%s_%i" % (app_config.DEPLOYMENT_TARGET, i), "version": int(time.time())})

    payload = json.dumps(sdf)

    if len(payload) > 5000 * 1024:
        print "Exceeded 5MB limit for SDF uploads!"
        return

    print "Uploading to CloudSearch..."
    response = requests.post(
        "http://%s/2011-02-01/documents/batch" % app_config.CLOUD_SEARCH_DOC_DOMAIN,
        data=payload,
        headers={"Content-Type": "application/json"},
    )

    print response.status_code
    print response.text

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #49
0
def sitemap():
    """
    Render and deploy sitemap.
    """
    require('settings', provided_by=[staging, production])

    app_config.configure_targets(env.get('settings', None))

    with flat_app.app.test_request_context(path='sitemap.xml'):
        print 'Rendering sitemap.xml'

        view = flat_app.__dict__['_sitemap']
        content = view().data

    with open('.sitemap.xml', 'w') as f:
        f.write(content)

    s3 = boto.connect_s3()

    flat.deploy_file(s3, '.sitemap.xml', app_config.PROJECT_SLUG,
                     app_config.DEFAULT_MAX_AGE)
Example #50
0
    def test_delete_playground_confirm(self):
        utils.load_test_playgrounds()

        app_config.configure_targets('staging')

        s3 = boto.connect_s3()
        bucket = s3.get_bucket(app_config.S3_BUCKETS[0])
        k = Key(bucket)
        k.key = '%s/playground/%s.html' % (app_config.PROJECT_SLUG,
                                           Playground.get(id=1).slug)
        k.set_contents_from_string('foo')

        response = self.client.get(
            url_for('delete_playground_confirm',
                    playground_slug=Playground.get(id=1).slug))

        self.assertEqual(response.status_code, 200)
        self.assertFalse(Playground.get(id=1).active)

        self.assertIsNone(bucket.get_key(k.key))
        app_config.configure_targets(None)
Example #51
0
    def test_remove_from_search_index(self):
        app_config.configure_targets('staging')

        utils.load_test_playgrounds()

        playground = Playground.select()[0]

        sdf = playground.sdf()
        sdf['id'] = 'test_%i' % playground.id
        sdf['fields']['name'] = 'THIS IS NOT A PLAYGROUND NAME axerqwak'
        sdf['fields']['deployment_target'] = 'test'

        response = requests.post('http://%s/2011-02-01/documents/batch' %
                                 app_config.CLOUD_SEARCH_DOC_DOMAIN,
                                 data=json.dumps([sdf]),
                                 headers={'Content-Type': 'application/json'})

        self.assertEqual(response.status_code, 200)

        # Monkey patch delete_sdf to so it return test id
        delete_sdf = playground.delete_sdf()
        delete_sdf['id'] = 'test_%i' % playground.id
        delete_sdf['version'] = sdf['version'] + 1

        old_func = playground.delete_sdf
        playground.delete_sdf = lambda: delete_sdf

        playground.remove_from_search_index()

        playground.delete_sdf = old_func

        response = requests.get('http://%s/2011-02-01/search' %
                                app_config.CLOUD_SEARCH_DOMAIN,
                                params={'q': 'axerqwak'},
                                headers={'Cache-Control': 'revalidate'})

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['hits']['found'], 0)

        app_config.configure_targets(None)
Example #52
0
def _render_graphics(paths):
    """
    Render a set of graphics
    """
    from flask import g

    # Fake out deployment target
    app_config.configure_targets(env.get('settings', None))

    for path in paths:
        slug = path.split('%s/' % app_config.GRAPHICS_PATH)[1].split('/')[0]

        with app.app.test_request_context(path='graphics/%s/' % slug):
            g.compile_includes = True
            g.compiled_includes = {}

            view = app.graphic.__dict__['_graphics_detail']
            content = view(slug).data

        with open('%s/index.html' % path, 'w') as writefile:
            writefile.write(content)

        # Fallback for legacy projects w/o child templates
        if not os.path.exists('%s/child_template.html' % path):
            continue

        with app.app.test_request_context(path='graphics/%s/child.html' %
                                          slug):
            g.compile_includes = True
            g.compiled_includes = {}

            view = app.graphic.__dict__['_graphics_child']
            content = view(slug).data

        with open('%s/child.html' % path, 'w') as writefile:
            writefile.write(content)

    # Un-fake-out deployment target
    app_config.configure_targets(app_config.DEPLOYMENT_TARGET)
Example #53
0
def write_aggregates():
    app_config.configure_targets(env.get('settings', None))
    tumblr_utils.write_aggregates()
Example #54
0
def render():
    """
    Render HTML templates and compile assets.
    """
    from flask import g

    update_copy()
    less()
    jst()

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get("settings", None))

    app_config_js()

    compiled_includes = []

    for rule in app.app.url_map.iter_rules():
        rule_string = rule.rule
        name = rule.endpoint

        if name == "static" or name.startswith("_"):
            print "Skipping %s" % name
            continue

        if rule_string.endswith("/"):
            filename = "www" + rule_string + "index.html"
        elif rule_string.endswith(".html") or rule_string.endswith(".xml") or rule_string.endswith(".js"):
            filename = "www" + rule_string
        else:
            print "Skipping %s" % name
            continue

        dirname = os.path.dirname(filename)

        if not (os.path.exists(dirname)):
            os.makedirs(dirname)

        print "Rendering %s" % (filename)

        with app.app.test_request_context(path=rule_string):
            g.compile_includes = True
            g.compiled_includes = compiled_includes

            view = app.__dict__[name]
            content = view()

            if isinstance(content, tuple):
                content = content[0]

            compiled_includes = g.compiled_includes

        with open(filename, "w") as f:
            f.write(content.encode("utf-8"))

    # We choose a sample playground to render so its JS will
    # be rendered. We don't deploy it.
    sample_playgrounds = models.Playground.select().limit(1)
    data.render_playgrounds(sample_playgrounds, compiled_includes)

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #55
0
def fileserver():
    """
    Run as though building electron app.
    """
    env.settings = 'fileserver'
    app_config.configure_targets(env.settings)
Example #56
0
def electron():
    """
    Run as though building electron app.
    """
    env.settings = 'electron'
    app_config.configure_targets(env.settings)
Example #57
0
 def test_app_config_production(self):
     app_config.configure_targets('production')
     response = self.client.get('/js/app_config.js')
     data = self.parse_data(response)
     app_config.configure_targets('test')
     self.assertFalse(data['DEBUG'])