Skip to content

Commit

Permalink
Expect missing copyright field and ValueError errors
Browse files Browse the repository at this point in the history
Expecting the errors enables to give better feedback to users
than just a 500 error
  • Loading branch information
oorestisime committed Jan 12, 2016
1 parent b6a5357 commit f99fc6a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{#
Copyright (C) 2015 The Debsources developers <info@sources.debian.net>.
Copyright (C) 2016 The Debsources developers <info@sources.debian.net>.
See the AUTHORS file at the top-level directory of this distribution and at
https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=AUTHORS;hb=HEAD
License: GNU Affero General Public License, version 3 or above.
#}
{% extends name+"/base.html" %}

{% block title %}404{% endblock %}
{% block title %}Error{% endblock %}
{% block content %}
<h2>{{ self.title() }}</h2>
<p>The debian/copyright file has a file paragraph without the <b>required</b> copyright field. The files paragraph is:
Expand All @@ -15,7 +15,8 @@ <h2>{{ self.title() }}</h2>
<li>{{ files }}</li>
{% endfor %}
</ul>
<a href="{{ url_for('sources.source', path_to=(package +'/'+version+'/debian/copyright'))}}">View raw copyright file</a>
</p>
<a href="/">Go home</a>
<a href="{{ url_for('.license', path_to=(package +'/'+version))}}">Go back to the license page</a>

{% endblock %}
20 changes: 20 additions & 0 deletions debsources/app/copyright/templates/copyright/value_error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{#
Copyright (C) 2016 The Debsources developers <info@sources.debian.net>.
See the AUTHORS file at the top-level directory of this distribution and at
https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=AUTHORS;hb=HEAD
License: GNU Affero General Public License, version 3 or above.
#}
{% extends name+"/base.html" %}

{% block title %}Error{% endblock %}
{% block content %}
<h2>{{ self.title() }}</h2>
<p>Parsing the debian/copyright file yields a Value error. Causes of ValueError can be:
<ul>
<li>continued line must begin with " "</li>
<li>missing value in one of the required attributes (Files, Copyright, License)</li>
</ul>

<p><a href="{{ url_for('sources.source', path_to=(package +'/'+version+'/debian/copyright'))}}">View raw copyright file</a></p>
</p>
{% endblock %}
20 changes: 12 additions & 8 deletions debsources/app/copyright/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import debsources.statistics as statistics
from debsources.excepts import (Http404ErrorSuggestions, FileOrFolderNotFound,
InvalidPackageOrVersionError,
Http404MissingCopyright, Http404Error)
Http404MissingCopyright, Http404Error,
CopyrightValueError)
from ..views import GeneralView, ChecksumView, session, app
from ..sourcecode import SourceCodeIterator
from ..pagination import Pagination
Expand Down Expand Up @@ -74,13 +75,16 @@ def get_objects(self, path_to):
code=sourcefile,
dump='True',
nlines=sourcefile.get_number_of_lines(),)
return dict(package=package,
version=version,
dump='False',
header=helper.get_copyright_header(c),
files=helper.parse_copyright_paragraphs_for_html_render(
c, "/src/" + package + "/" + version + "/"),
licenses=helper.parse_licenses_for_html_render(c))
try:
return dict(package=package,
version=version,
dump='False',
header=helper.get_copyright_header(c),
files=helper.parse_copyright_paragraphs_html_render(
c, "/src/" + package + "/" + version + "/"),
licenses=helper.parse_licenses_for_html_render(c))
except ValueError as e:
raise CopyrightValueError(package, version, e.message)


class ChecksumLicenseView(ChecksumView):
Expand Down
4 changes: 3 additions & 1 deletion debsources/app/patches/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ..views import GeneralView, session
from debsources.navigation import Location, SourceFile
from debsources.excepts import (Http404ErrorSuggestions, FileOrFolderNotFound,
InvalidPackageOrVersionError)
InvalidPackageOrVersionError, Http404Error)
from ..sourcecode import SourceCodeIterator
from . import patches_helper as helper

Expand Down Expand Up @@ -172,6 +172,8 @@ class PatchView(GeneralView):

def get_objects(self, path_to):
path_dict = path_to.split('/')
if len(path_dict) < 3:
raise Http404Error()
package = path_dict[0]
version = path_dict[1]
patch = '/'.join(path_dict[2:])
Expand Down
13 changes: 10 additions & 3 deletions debsources/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from debsources.excepts import (
Http500Error, Http404Error, Http404ErrorSuggestions, Http403Error,
InvalidPackageOrVersionError, Http404MissingCopyright,
MissingCopyrightField)
MissingCopyrightField, CopyrightValueError)
from debsources.models import Package, SuiteAlias
import debsources.query as qry
from debsources.sqla_session import _close_session
Expand Down Expand Up @@ -132,8 +132,15 @@ def error_404(self, error):
return render_template('copyright/404_missing.html',
suggestions=suggestions), 404
elif isinstance(error, MissingCopyrightField):
return render_template('copyright/404_missing_copyright.html',
paragraph=error.par)
return render_template('copyright/missing_copyright.html',
paragraph=error.par,
package=error.package,
version=error.version)
elif isinstance(error, CopyrightValueError):
return render_template('copyright/value_error.html',
error=error.error,
package=error.package,
version=error.version)
else:
return render_template('404.html'), 404

Expand Down
8 changes: 8 additions & 0 deletions debsources/excepts.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ def __init__(self, package, version, par):
self.version = version
self.par = par
super(MissingCopyrightField, self).__init__()


class CopyrightValueError(Http404Error):
def __init__(self, package, version, error):
self.package = package
self.version = version
self.error = error
super(CopyrightValueError, self).__init__()
2 changes: 1 addition & 1 deletion debsources/license_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def get_copyright_header(copyright):
return copyright.header._RestrictedWrapper__data


def parse_copyright_paragraphs_for_html_render(copyright, base_url):
def parse_copyright_paragraphs_html_render(copyright, base_url):
""" Returns list of File objects. If `base_url` is provided
then it creates links to base_url+glob
"""
Expand Down

0 comments on commit f99fc6a

Please sign in to comment.