-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·115 lines (86 loc) · 3.33 KB
/
app.py
File metadata and controls
executable file
·115 lines (86 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
# pkgs.void - web catalog of Void Linux packages.
# Copyright (C) 2019-2022 Piotr Wójcik <chocimier@tlen.pl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from urllib.parse import quote, urlsplit
from flask import Flask, Response, redirect, request, send_from_directory
from settings import config
from voidhtml import (
build_log as build_log_page,
find, lists_index, longest_names, main_page, metapackages,
newest, no_page, of_day, opensearch_description,
page_generator, popular, which_package
)
from xbps import join_arch
app = Flask(__name__)
@app.route('/search/')
def search():
term = request.args.get('term')
finding = request.args.get('find')
fields = request.args.getlist('by')
if finding or fields or not term:
return find(term, fields)
term = quote(term)
return redirect(config.ROOT_URL + '/package/' + term + '/')
@app.route('/all/')
def list_all_():
return send_from_directory(config.GENERATED_FILES_PATH, 'all.html')
@app.route(config.GENERATED_FILES_URL + '/pkgs.void.tar.bz2')
def source_tarball():
directory = config.GENERATED_FILES_PATH
return send_from_directory(directory, 'pkgs.void.tar.bz2')
app.route('/')(main_page)
app.route('/toc/')(lists_index)
app.route('/of_day/')(of_day)
app.route('/newest/')(newest)
app.route('/sets/')(metapackages)
app.route('/popular/')(popular)
app.route('/longest_names/')(longest_names)
app.route('/package/')(which_package)
@app.route('/package/<pkgname>/')
def package(pkgname):
return page_generator(pkgname)
@app.route('/package/<pkgname>/<iset>-<libc>/')
def package_arch(pkgname, iset, libc):
return page_generator(pkgname, single=join_arch(iset, libc))
@app.route('/buildlog/<pkgname>/<iset>-<libc>/<version>/')
def build_log(pkgname, iset, libc, version):
result = build_log_page(pkgname, join_arch(iset, libc), version)
if result.redirect:
return redirect(result.redirect)
status = 202 if not result.error else 501
return (result.content, status)
@app.route('/opensearch.xml')
def opensearch():
urlparts = urlsplit(request.url)
print(request.url, urlparts)
response = Response(
response=opensearch_description(urlparts),
content_type='application/opensearchdescription+xml'
)
return response
@app.errorhandler(404)
def error404(err):
del err
return (no_page(), 404)
class UrlPrefixMiddleware():
def __init__(self, prefix, application):
self._app = application
self._prefix = prefix
self._prefix_len = len(prefix)
def __call__(self, env, handler):
if env['PATH_INFO'].startswith(self._prefix):
env['PATH_INFO'] = env['PATH_INFO'][self._prefix_len:]
return self._app(env, handler)
app.wsgi_app = UrlPrefixMiddleware(config.ROOT_URL, app.wsgi_app)