コード例 #1
0
ファイル: pur.py プロジェクト: Cloudef/PUR
def get_recipe_revision_file(pkgname=None, revision=None, recipefile=None):
    '''fetch recipe revision file'''
    if revision:
        recipe = RECIPEMANAGER.get_revision(pkgname, revision)
    else:
        recipe = RECIPEMANAGER.get_recipe(pkgname)
    if not recipe:
        abort(404)
    path = os.path.join('userdata/recipes', recipe['pkgname'], recipe['directory'])
    if recipefile == 'PNDBUILD':
        if request.query.get('syntax'):
            data = None
            with open(os.path.join(path, recipefile), 'r') as fle:
                data = fle.read()
            if not data:
                abort(404, _('PNDBUILD file not found'))
            syntax = replace.syntax(data, 'bash')
            return syntax if is_ajax_request() else template('syntax', title='PNDBUILD', syntax=syntax)
        return static_file(recipefile, root=path, mimetype='text/plain')
    return static_file(recipefile, root=path, download=True, mimetype='application/octet-stream')
コード例 #2
0
ファイル: pur.py プロジェクト: Cloudef/PUR
def setup():
    '''setup method'''
    # set template globals
    BaseTemplate.defaults['PURVERSION'] = VERSION
    BaseTemplate.defaults['PURSTYLES'] = STYLES
    BaseTemplate.defaults['PURTRANSLATIONS'] = TRANSLATIONS
    BaseTemplate.defaults['PURBETA'] = BETA
    BaseTemplate.defaults['LEVELS'] = LEVELS

    # template functions
    csrf_input = lambda: '<input type="hidden" name="CSRF" value="{}"/>'.format(SESSION['CSRF'])
    referrer_input = lambda: '<input type="hidden" name="REFERRER" value="{}"/>'.format(request.path)
    BaseTemplate.defaults['CL'] = comment_markup
    BaseTemplate.defaults['ML'] = markup
    BaseTemplate.defaults['_ML'] = lambda x: markup(_(x))
    BaseTemplate.defaults['get_session'] = SESSIONMANAGER.get_session
    BaseTemplate.defaults['js_togglable'] = js_togglable
    BaseTemplate.defaults['linkify'] = replace.html_linkify_and_escape
    BaseTemplate.defaults['link'] = replace.html_link
    BaseTemplate.defaults['csrf_input'] = csrf_input
    BaseTemplate.defaults['referrer_input'] = referrer_input
    BaseTemplate.defaults['csrf_link'] = lambda x, y: '<form class="link" action="{}" method="POST"><input type="submit" class="link" value="{}"/>{}</form>'.format(x, x if not y else y, csrf_input())
    BaseTemplate.defaults['referrer_csrf_link'] = lambda x, y: '<form class="link" action="{}" method="POST"><input type="submit" class="link" value="{}"/>{}{}</form>'.format(x, x if not y else y, csrf_input(), referrer_input())
    BaseTemplate.defaults['diff'] = lambda x: replace.syntax(x, 'diff')
コード例 #3
0
ファイル: pur.py プロジェクト: Cloudef/PUR
def replace_togglable_code(expr, start, end, data):
    '''replace code block found by iter_callback'''
    lang = expr.group(1)
    code = expr.group(2)
    header = '{} {}'.format(lang, _('code')) if lang else _('Code')
    return replace.replace_range(data, start, end, '</pre>{}<pre>'.format(js_togglable(header, replace.syntax(code, lang), hidden=True)))