Permalink
Browse files

Change the source URLs to be like MXR's. Addresses bug 834509.

Also rename fetch_results() to results() for consistency with direct_result().
  • Loading branch information...
1 parent 6ec9134 commit b902f06a3b265b8e4b4c9c7eab9002bbf4e8b47e @erikrose erikrose committed Mar 11, 2013
Showing with 43 additions and 32 deletions.
  1. +5 −5 dxr/app.py
  2. +11 −10 dxr/build.py
  3. +15 −5 dxr/query.py
  4. +2 −2 dxr/static/search.js
  5. +1 −1 dxr/templates/folder.html
  6. +1 −1 dxr/templates/layout.html
  7. +7 −7 dxr/templates/search.html
  8. +1 −1 tests/test_ignores/test_ignores.py
View
@@ -80,14 +80,14 @@ def search():
path, line = result
# TODO: Does this escape qtext properly?
return redirect(
- '%s/%s/%s?from=%s#l%i' %
+ '%s/%s/source/%s?from=%s#l%i' %
(config['WWW_ROOT'], tree, path, qtext, line))
# Return multiple results:
template = 'search.html'
start = time()
try:
- results = list(q.fetch_results(offset, limit))
+ results = list(q.results(offset, limit))
except OperationalError as e:
if e.message.startswith('REGEXP:'):
# Malformed regex
@@ -137,10 +137,10 @@ def search():
**arguments)
-@dxr_blueprint.route('/<path:tree_and_path>')
-def browse(tree_and_path):
+@dxr_blueprint.route('/<tree>/source/')
+@dxr_blueprint.route('/<tree>/source/<path:path>')
+def browse(tree, path=''):
"""Show a directory listing or a single file from one of the trees."""
- tree, _, path = tree_and_path.partition('/')
tree_folder = os.path.join(current_app.instance_path, 'trees', tree)
if isdir(os.path.join(tree_folder, path)):
View
@@ -236,12 +236,13 @@ def build_folder(tree, conn, folder, indexed_files, indexed_folders):
# Generate list of folders and their mod dates:
folders = [('folder',
- f,
- datetime.fromtimestamp(stat(os.path.join(tree.source_folder,
- folder,
- f)).st_mtime),
- _join_url(tree.name, folder, f))
- for f in indexed_folders]
+ f,
+ datetime.fromtimestamp(stat(os.path.join(tree.source_folder,
+ folder,
+ f)).st_mtime),
+ # TODO: DRY with Flask route. Use url_for:
+ _join_url(tree.name, 'source', folder, f))
+ for f in indexed_folders]
# Generate list of files:
files = []
@@ -250,10 +251,10 @@ def build_folder(tree, conn, folder, indexed_files, indexed_folders):
path = os.path.join(tree.source_folder, folder, f)
file_info = stat(path)
files.append((dxr.mime.icon(path),
- f,
- datetime.fromtimestamp(file_info.st_mtime),
- file_info.st_size,
- _join_url(tree.name, folder, f)))
+ f,
+ datetime.fromtimestamp(file_info.st_mtime),
+ file_info.st_size,
+ _join_url(tree.name, 'source', folder, f)))
# Lay down the HTML:
jinja_env = load_template_env(tree.config.temp_folder,
View
@@ -121,9 +121,16 @@ def execute_sql(self, sql, *parameters):
# Fetch results using a query,
# See: queryparser.py for details in query specification
- def fetch_results(self,
- offset = 0, limit = 100,
- markup = "<b>", markdown = "</b>"):
+ def results(self,
+ offset=0, limit=100,
+ markup='<b>', markdown='</b>'):
+ """Return search results as an iterable of these::
+
+ (icon,
+ path within tree,
+ (line_number, highlighted_line_of_code)), ...
+
+ """
sql = """
SELECT files.path, files.icon, trg_index.text, files.id,
extents(trg_index.contents)
@@ -253,8 +260,11 @@ def number_lines(arr):
def direct_result(self):
- """ Get a direct result as tuple of (path, line) or None if not direct result
- for query, ie. complex query
+ """Return a single search result that is an exact match for the query.
+
+ If there is such a result, return a tuple of (path from root of tree,
+ line number). Otherwise, return None.
+
"""
term = self.single_term()
if not term:
View
@@ -13,7 +13,7 @@ var result_template = ""
var lines_template = ""
+ "<a class=\"snippet\" "
- + " href=\"{{wwwroot}}/{{tree}}/{{path}}#l{{line_number}}\">"
+ + " href=\"{{wwwroot}}/{{tree}}/source/{{path}}#l{{line_number}}\">"
+ " <div class=\"line-numbers\">"
+ " <pre><span class=\"ln\">{{line_number}}</span></pre>"
+ " </div>"
@@ -47,7 +47,7 @@ function format_results(data){
for(var j = 0; j < folders.length; j++){
var folder = folders[j];
var p = folders.slice(0, j + 1).join('/');
- var href = wwwroot + '/' + dxr.tree() + '/' + p;
+ var href = wwwroot + '/' + dxr.tree() + '/source/' + p;
pathline += "<a href=\"" + href + "\" ";
if(j + 1 < folders.length){
pathline += "data-path=\"" + p + "/\"";
@@ -8,7 +8,7 @@
<table class="folder-content">
<tr><th style="padding-left: 24px;">Name</th><th>Modified</th><th>Size</th></tr>
<tr>
- <td><a href="{{ wwwroot }}/{{ tree }}/{{ path }}/.."
+ <td><a href="{{ wwwroot }}/{{ tree }}/source/{{ path }}/.."
style="background-image: url('{{ wwwroot }}/static/icons/folder.png')">
Parent directory</a></td>
<td></td>
@@ -81,7 +81,7 @@
{% elif not loop.first and trees|length > 1 -%}
,
{% endif -%}
- <a href="{{ t }}/">{{ t }}</a>
+ <a href="{{ t }}/source/">{{ t }}</a>
{%- endfor -%}
.
</div>
View
@@ -101,7 +101,7 @@
<div class="path" style="background-image: url({{ wwwroot }}/static/icons/{{ icon }}.png);">
{%- set folders = path.split('/') -%}
{%- for folder in folders -%}
- <a href="{{ wwwroot }}/{{ tree }}/{{ "/".join(folders[0:loop.index]) }}"
+ <a href="{{ wwwroot }}/{{ tree }}/source/{{ "/".join(folders[0:loop.index]) }}"
{% if not loop.last %}
data-path="{{ "/".join(folders[0:loop.index]) }}/"
{% endif %}
@@ -111,12 +111,12 @@
{%- endfor -%}
</div>
{% for number, line in lines %}
- <a class="snippet" href="{{ wwwroot }}/{{ tree }}/{{ path }}#l{{ number }}">
- <div class="line-numbers">
- <pre><span class="ln">{{ number }}</span></pre>
- </div>
- <div class="file-lines"><pre><code>{{ line|safe }}</code></pre></div>
- </a>
+ <a class="snippet" href="{{ wwwroot }}/{{ tree }}/source/{{ path }}#l{{ number }}">
+ <div class="line-numbers">
+ <pre><span class="ln">{{ number }}</span></pre>
+ </div>
+ <div class="file-lines"><pre><code>{{ line|safe }}</code></pre></div>
+ </a>
{%- endfor %}
</div>
{% else %}
@@ -8,7 +8,7 @@ class IgnorePatternTests(DxrInstanceTestCase):
def _top_level_index(self):
"""Return the HTML of the front browse page."""
- return self.client().get('/code').data
+ return self.client().get('/code/source/').data
def test_non_path(self):
"""Test that non-path-based ignore patterns are obeyed."""

0 comments on commit b902f06

Please sign in to comment.