Skip to content

Commit 791cc82

Browse files
committed
Copyright: expect value error in spdx export
1 parent ca25e58 commit 791cc82

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{#
2+
Copyright (C) 2016 The Debsources developers <info@sources.debian.net>.
3+
See the AUTHORS file at the top-level directory of this distribution and at
4+
https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=AUTHORS;hb=HEAD
5+
License: GNU Affero General Public License, version 3 or above.
6+
#}
7+
{% extends name+"/base.html" %}
8+
9+
{% block title %}Error{% endblock %}
10+
{% block content %}
11+
<h2>{{ self.title() }}</h2>
12+
<p>Parsing the debian/copyright file failed due to one or more of the following causes:
13+
<ul>
14+
<li>continued line must begin with " "</li>
15+
<li>missing value in one of the required attributes (Files, Copyright, License)</li>
16+
</ul>
17+
18+
<p><a href="{{ url_for('sources.source', packagename=package, version=version) }}">View raw copyright file</a></p>
19+
</p>
20+
{% endblock %}

debsources/app/copyright/views.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import debsources.statistics as statistics
2323
from debsources.excepts import (Http404ErrorSuggestions, FileOrFolderNotFound,
2424
InvalidPackageOrVersionError,
25-
Http404MissingCopyright, Http404Error)
25+
Http404MissingCopyright, Http404Error,
26+
CopyrightValueError)
2627
from ..views import GeneralView, ChecksumView, session, app
2728
from ..sourcecode import SourceCodeIterator
2829
from ..pagination import Pagination
@@ -52,13 +53,16 @@ def get_objects(self, packagename, version):
5253
code=sourcefile,
5354
dump='True',
5455
nlines=sourcefile.get_number_of_lines(),)
55-
return dict(package=packagename,
56-
version=version,
57-
dump='False',
58-
header=helper.get_copyright_header(c),
59-
files=helper.parse_copyright_paragraphs_for_html_render(
60-
c, "/src/" + packagename + "/" + version + "/"),
61-
licenses=helper.parse_licenses_for_html_render(c))
56+
try:
57+
return dict(package=packagename,
58+
version=version,
59+
dump='False',
60+
header=helper.get_copyright_header(c),
61+
files=helper.parse_copyright_paragraphs_html_render(
62+
c, "/src/" + packagename + "/" + version + "/"),
63+
licenses=helper.parse_licenses_for_html_render(c))
64+
except ValueError as e:
65+
raise CopyrightValueError(packagename, version, e.message)
6266

6367

6468
class ChecksumLicenseView(ChecksumView):

debsources/excepts.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,11 @@ def __init__(self, package, version, par):
5454
self.version = version
5555
self.par = par
5656
super(MissingCopyrightField, self).__init__()
57+
58+
59+
class CopyrightValueError(Http404Error):
60+
def __init__(self, package, version, error):
61+
self.package = package
62+
self.version = version
63+
self.error = error
64+
super(CopyrightValueError, self).__init__()

debsources/license_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def get_copyright_header(copyright):
149149
return copyright.header._RestrictedWrapper__data
150150

151151

152-
def parse_copyright_paragraphs_for_html_render(copyright, base_url):
152+
def parse_copyright_paragraphs_html_render(copyright, base_url):
153153
""" Returns list of File objects. If `base_url` is provided
154154
then it creates links to base_url+glob
155155
"""

0 commit comments

Comments
 (0)