Commit 1e1b6d56 authored by Antoine Beaupré's avatar Antoine Beaupré

prefer searching by pattern than all suites

parent 6381c3c6
......@@ -41,13 +41,19 @@ def search():
.. note:: inspired by http://manpages.ubuntu.com/cgi-bin/search.py?q=man
'''
# XXX: not sure this is the best structure
manpages = {} # suite -> (name, section)
manpages = {} # section -> (name, href)
i = 0
assert app.static_folder
pattern = request.values.get('pattern', None)
locale = request.values.get('locale', None)
section = request.values.get('section', None)
suite = request.values.get('suite', None)
suites = app.config['releases']
default_suite = 'sid'
if 'sid' not in suites:
# arbitrarily: last key in the list
default_suite = sorted(suites.keys())[-1]
suite = request.values.get('suite', default_suite)
logger.debug('using suite %s' % suite)
if pattern is None:
return render_template('template.html',
suites=app.config['releases'],
......@@ -58,10 +64,9 @@ def search():
name = match.group('name')
if (pattern not in name
or locale != match.group('locale')
or (section is not None
and section != match.group('section'))
or (suite is not None
and suite != match.group('suite'))):
or (suite != match.group('suite'))
or (section is not None and
section != match.group('section'))):
continue
i += 1
if match.group('section') not in manpages:
......@@ -74,13 +79,12 @@ def search():
base, ext = os.path.splitext(href)
href = base + '.html'
manpages[match.group('section')].add((name,
match.group('suite'),
href))
if i == 1:
return redirect(href)
# XXX: this should also know about all sections, probably?
return render_template('search.html', manpages=manpages, count=i,
suites=app.config['releases'])
suites=suites, suite=suite)
@app.route('/')
......
{% extends "template.html" %}
{% block content %}
{% if count > 0 %}
{{count}} manuals found.
{{count}} manuals found in suite {{suites[suite]}}.
{% else %}
No manuals found.
No manuals found in suite {{suites[suite]}}.
{% endif %}
<table>
{% for section, mans in manpages.iteritems() %}
<tr>
{% for man, suite, href in mans %}
<td><a href="{{href}}">{{ man }}</a> ({{suite}})</td>
{% endfor %}
</tr>
{%endfor%}
</table>
<ul>
{% for section, mans in manpages|dictsort %}
<li>Section {{section}}:
<ul class="subnav">
{% for man, href in mans %}
<li><a href="{{href}}">{{ man }}({{section}})</a></li>
{% endfor %}
</ul>
</li>
{%endfor%}
</ul>
{% endblock %}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment