Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Change the source URLs to be like MXR's. Addresses bug 834509.
Browse files Browse the repository at this point in the history
Also rename fetch_results() to results() for consistency with direct_result().
  • Loading branch information
erikrose committed Mar 12, 2013
1 parent 6ec9134 commit b902f06
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 32 deletions.
10 changes: 5 additions & 5 deletions dxr/app.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down
21 changes: 11 additions & 10 deletions dxr/build.py
Expand Up @@ -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 = []
Expand All @@ -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,
Expand Down
20 changes: 15 additions & 5 deletions dxr/query.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions dxr/static/search.js
Expand Up @@ -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>"
Expand Down Expand Up @@ -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 + "/\"";
Expand Down
2 changes: 1 addition & 1 deletion dxr/templates/folder.html
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion dxr/templates/layout.html
Expand Up @@ -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>
Expand Down
14 changes: 7 additions & 7 deletions dxr/templates/search.html
Expand Up @@ -101,7 +101,7 @@ <h1>Case Insensitive Suffix Matching</h1>
<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 %}
Expand All @@ -111,12 +111,12 @@ <h1>Case Insensitive Suffix Matching</h1>
{%- 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 %}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ignores/test_ignores.py
Expand Up @@ -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."""
Expand Down

0 comments on commit b902f06

Please sign in to comment.