예제 #1
0
    def get_objects(self, packagename, version):
        try:
            sources_path = helper.get_sources_path(session, packagename,
                                                   version,
                                                   current_app.config)
        except (FileOrFolderNotFound, InvalidPackageOrVersionError) as e:
            if isinstance(e, FileOrFolderNotFound):
                raise Http404MissingCopyright(packagename, version, '')
            else:
                raise Http404ErrorSuggestions(packagename, version, '')

        try:
            c = helper.parse_license(sources_path)
        except Exception:
            # non machine readable license
            sourcefile = SourceCodeIterator(sources_path)
            return dict(package=packagename,
                        version=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))
예제 #2
0
파일: views.py 프로젝트: Debian/debsources
    def get_objects(self, packagename, version):
        try:
            sources_path = helper.get_sources_path(session, packagename,
                                                   version, current_app.config)
        except (FileOrFolderNotFound, InvalidPackageOrVersionError) as e:
            if isinstance(e, FileOrFolderNotFound):
                raise Http404MissingCopyright(packagename, version, "")
            else:
                raise Http404ErrorSuggestions(packagename, version, "")

        try:
            c = helper.parse_license(sources_path)
        except Exception:
            # non machine readable license
            sourcefile = SourceCodeIterator(sources_path)
            return dict(
                package=packagename,
                version=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),
        )
예제 #3
0
    def get_objects(self, path_to):
        path_dict = path_to.split('/')

        package = path_dict[0]
        version = path_dict[1]

        if len(path_dict) > 2:
            raise Http404ErrorSuggestions(package, version, '')

        path = '/'.join(path_dict[2:])

        if version == "latest":  # we search the latest available version
            return self._handle_latest_version(request.endpoint,
                                               package, path)

        versions = self.handle_versions(version, package, path)
        if versions:
            redirect_url_parts = [package, versions[-1]]
            if path:
                redirect_url_parts.append(path)
            redirect_url = '/'.join(redirect_url_parts)
            return self._redirect_to_url(request.endpoint,
                                         redirect_url, redirect_code=302)

        try:
            sources_path = helper.get_sources_path(session, package, version,
                                                   current_app.config)
        except (FileOrFolderNotFound, InvalidPackageOrVersionError) as e:
            if isinstance(e, FileOrFolderNotFound):
                raise Http404MissingCopyright(package, version, '')
            else:
                raise Http404ErrorSuggestions(package, version, '')

        try:
            c = helper.parse_license(sources_path)
        except Exception:
            # non machine readable license
            sourcefile = SourceCodeIterator(sources_path)
            return dict(package=package,
                        version=version,
                        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))