Exemplo n.º 1
0
        'kubernetes-e2e-gke-slow',
        'kubernetes-kubemark-5-gce',
        'kubernetes-kubemark-500-gce',
        'kubernetes-test-go',
    }
}

GCS_API_URL = 'https://storage.googleapis.com'

JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__) + '/templates'),
    extensions=['jinja2.ext.autoescape'],
    trim_blocks=True,
    autoescape=True)
JINJA_ENVIRONMENT.line_statement_prefix = '%'
filters.register(JINJA_ENVIRONMENT.filters)


def pad_numbers(s):
    """Modify a string to make its numbers suitable for natural sorting."""
    return re.sub(r'\d+', lambda m: m.group(0).rjust(16, '0'), s)


def memcache_memoize(prefix, expires=60 * 60, neg_expires=60):
    """Decorate a function to memoize its results using memcache.

    The function must take a single string as input, and return a pickleable
    type.

    Args:
        prefix: A prefix for memcache keys to use for memoization.
Exemplo n.º 2
0
from google.appengine.api import urlfetch
from google.appengine.api import memcache
from webapp2_extras import sessions
from webapp2_extras import security

import secrets
import filters as jinja_filters

JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__) + '/templates'),
    extensions=['jinja2.ext.autoescape', 'jinja2.ext.loopcontrols'],
    trim_blocks=True,
    autoescape=True)
JINJA_ENVIRONMENT.line_statement_prefix = '%'
jinja_filters.register(JINJA_ENVIRONMENT.filters)


def get_session_secret():
    try:
        return str(secrets.get('session'))
    except KeyError:
        # Make a new session key -- only happens once per hostname!
        logging.warning('creating new session key!')
        session_key = security.generate_random_string(entropy=256)
        secrets.put('session', session_key)
        return session_key


class BaseHandler(webapp2.RequestHandler):
    """Base class for Handlers that render Jinja templates."""
Exemplo n.º 3
0
        'kubernetes-e2e-gke-slow',
        'kubernetes-kubemark-5-gce',
        'kubernetes-kubemark-500-gce',
        'kubernetes-test-go',
    }
}

PR_PREFIX = 'kubernetes-jenkins/pr-logs/pull'

JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__) + '/templates'),
    extensions=['jinja2.ext.autoescape'],
    trim_blocks=True,
    autoescape=True)
JINJA_ENVIRONMENT.line_statement_prefix = '%'
jinja_filters.register(JINJA_ENVIRONMENT.filters)


def pad_numbers(s):
    """Modify a string to make its numbers suitable for natural sorting."""
    return re.sub(r'\d+', lambda m: m.group(0).rjust(16, '0'), s)


def memcache_memoize(prefix, expires=60 * 60, neg_expires=60):
    """Decorate a function to memoize its results using memcache.

    The function must take a single string as input, and return a pickleable
    type.

    Args:
        prefix: A prefix for memcache keys to use for memoization.
Exemplo n.º 4
0
        'kubernetes-e2e-gce-slow',
        'kubernetes-e2e-gke',
        'kubernetes-e2e-gke-slow',
        'kubernetes-kubemark-5-gce',
        'kubernetes-kubemark-500-gce',
        'kubernetes-test-go',
    }
}

JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__) + '/templates'),
    extensions=['jinja2.ext.autoescape'],
    trim_blocks=True,
    autoescape=True)
JINJA_ENVIRONMENT.line_statement_prefix = '%'
filters.register(JINJA_ENVIRONMENT.filters)


def pad_numbers(s):
    """Modify a string to make its numbers suitable for natural sorting."""
    return re.sub(r'\d+', lambda m: m.group(0).rjust(16, '0'), s)


def memcache_memoize(prefix, expires=60 * 60, neg_expires=60):
    """Decorate a function to memoize its results using memcache.

    The function must take a single string as input, and return a pickleable
    type.

    Args:
        prefix: A prefix for memcache keys to use for memoization.
Exemplo n.º 5
0
import json
import nmap

from models.host import Host
import db
import filters
import settings

app = Sanic(__name__)
app.static('/static', './static')
background_scan_executor = ThreadPoolExecutor()

template_env = Environment(loader=FileSystemLoader("templates/"),
                           autoescape=select_autoescape(['html', 'xml']),
                           enable_async=True)
filters.register(template_env)


# A decorator which renders the provided template file with the context returned
# from the route handler.
def use_template(template):
    def dec(f):
        async def wrap(*args, **kwargs):
            context = await f(*args, **kwargs)
            rendered = await template_env.get_template(template).render_async(
                context)
            return response.html(rendered)

        return wrap

    return dec
Exemplo n.º 6
0
from flask import Flask, render_template, redirect, url_for
import models
import scrapers
import db
import filters

app = Flask(__name__)
filters.register(app)

all_shops = [scrapers.SpellShopScraper, scrapers.BuyMagicScraper]
all_shops_route = '(%s)' % '|'.join(ash.SHOP_NAME for ash in all_shops)
cards_per_page = 40


@app.route('/')
def index():
    cards_at_page = 18
    cards_spellshop = db.get_cards(shop=scrapers.SpellShopScraper.SHOP_NAME, limit=cards_at_page)
    cards_buymagic = db.get_cards(shop=scrapers.BuyMagicScraper.SHOP_NAME, limit=cards_at_page)
    return render_template('index.html', cards_spellshop=cards_spellshop, cards_buymagic=cards_buymagic)


@app.route('/redactions')
def redactions():
    return render_template('redactions.html', redas=sorted(db.get_redas(), key=lambda r: r.name))


@app.route('/redactions/update')
def redactions_update():
    redas = scrapers.get_redactions()