Skip to content

Commit

Permalink
Copyright: expect value error in spdx export
Browse files Browse the repository at this point in the history
  • Loading branch information
oorestisime committed Jan 18, 2016
1 parent ca25e58 commit 791cc82
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
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 failed due to one or more of the following causes:
<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', packagename=package, version=version) }}">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 @@ -52,13 +53,16 @@ def get_objects(self, packagename, version):
code=sourcefile,
dump='True',
nlines=sourcefile.get_number_of_lines(),)
return dict(package=packagename,
version=version,
dump='False',
header=helper.get_copyright_header(c),
files=helper.parse_copyright_paragraphs_for_html_render(
c, "/src/" + packagename + "/" + version + "/"),
licenses=helper.parse_licenses_for_html_render(c))
try:
return dict(package=packagename,
version=version,
dump='False',
header=helper.get_copyright_header(c),
files=helper.parse_copyright_paragraphs_html_render(
c, "/src/" + packagename + "/" + version + "/"),
licenses=helper.parse_licenses_for_html_render(c))
except ValueError as e:
raise CopyrightValueError(packagename, version, e.message)


class ChecksumLicenseView(ChecksumView):
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 791cc82

Please sign in to comment.