コード例 #1
0
ファイル: views.py プロジェクト: chr7stos/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))
コード例 #2
0
ファイル: views.py プロジェクト: chr7stos/debsources
 def _get_license_dict(self, files):
     result = []
     for f in files:
         try:
             # once DB full, remove license path
             try:
                 license_path = helper.get_sources_path(session,
                                                        f['package'],
                                                        f['version'],
                                                        current_app.config)
             except (FileOrFolderNotFound, InvalidPackageOrVersionError):
                 raise Http404ErrorSuggestions(f['package'], f['version'],
                                               '')
             l = helper.get_license(session, f['package'],
                                    f['version'], f['path'], license_path)
             result.append(dict(oracle='debian',
                                path=f['path'],
                                package=f['package'],
                                version=f['version'],
                                license=l,
                                origin=helper.license_url(f['package'],
                                                          f['version'])))
         except Exception:
             result.append(dict(oracle='debian',
                                path=f['path'],
                                package=f['package'],
                                version=f['version'],
                                license=None,
                                origin=helper.license_url(f['package'],
                                                          f['version'])))
     return result
コード例 #3
0
 def _get_license_dict(self, files):
     result = []
     for f in files:
         try:
             # once DB full, remove license path
             try:
                 license_path = helper.get_sources_path(
                     session, f['package'], f['version'],
                     current_app.config)
             except (FileOrFolderNotFound, InvalidPackageOrVersionError):
                 raise Http404ErrorSuggestions(f['package'], f['version'],
                                               '')
             l = helper.get_license(session, f['package'], f['version'],
                                    f['path'], license_path)
             result.append(
                 dict(oracle='debian',
                      path=f['path'],
                      package=f['package'],
                      version=f['version'],
                      license=l,
                      origin=helper.license_url(f['package'],
                                                f['version'])))
         except Exception:
             result.append(
                 dict(oracle='debian',
                      path=f['path'],
                      package=f['package'],
                      version=f['version'],
                      license=None,
                      origin=helper.license_url(f['package'],
                                                f['version'])))
     return result
コード例 #4
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))
コード例 #5
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))
コード例 #6
0
 def _license_of_files(self, f):
     # once DB full, remove license path
     try:
         license_path = helper.get_sources_path(session, f.package,
                                                f.version,
                                                current_app.config)
     except (FileOrFolderNotFound, InvalidPackageOrVersionError):
         raise Http404ErrorSuggestions(f.package, f.version, '')
     return dict(oracle='debian',
                 path=f.path,
                 package=f.package,
                 version=f.version,
                 license=helper.get_license(session, f.package, f.version,
                                            f.path, license_path),
                 origin=helper.license_url(f.package, f.version))
コード例 #7
0
ファイル: views.py プロジェクト: chr7stos/debsources
 def _license_of_files(self, f):
     # once DB full, remove license path
     try:
         license_path = helper.get_sources_path(session, f.package,
                                                f.version,
                                                current_app.config)
     except (FileOrFolderNotFound, InvalidPackageOrVersionError):
         raise Http404ErrorSuggestions(f.package, f.version, '')
     return dict(oracle='debian',
                 path=f.path,
                 package=f.package,
                 version=f.version,
                 license=helper.get_license(session, f.package,
                                            f.version, f.path,
                                            license_path),
                 origin=helper.license_url(f.package, f.version))
コード例 #8
0
    def _license_of_files(self, f):
        # once DB full, remove license path
        try:
            license_path = helper.get_sources_path(session, f.package,
                                                   f.version,
                                                   current_app.config)
        except (FileOrFolderNotFound, InvalidPackageOrVersionError):
            raise Http404ErrorSuggestions(f.package, f.version, '')

        try:
            c = helper.parse_license(license_path)
            l = helper.get_license(f.package, f.version, f.path, c)
        except copyright.NotMachineReadableError:
            l = None
        return dict(oracle='debian',
                    path=f.path,
                    package=f.package,
                    version=f.version,
                    license=l,
                    origin=helper.license_url(f.package, f.version))
コード例 #9
0
ファイル: views.py プロジェクト: oorestisime/debsources
    def _license_of_files(self, f):
        # once DB full, remove license path
        try:
            license_path = helper.get_sources_path(session, f.package,
                                                   f.version,
                                                   current_app.config)
        except (FileOrFolderNotFound, InvalidPackageOrVersionError):
            raise Http404ErrorSuggestions(f.package, f.version, '')

        try:
            c = helper.parse_license(license_path)
            l = helper.get_license(f.package, f.version, f.path, c)
        except copyright.NotMachineReadableError:
            l = None
        return dict(oracle='debian',
                    path=f.path,
                    package=f.package,
                    version=f.version,
                    license=l,
                    origin=helper.license_url(f.package, f.version))
コード例 #10
0
ファイル: views.py プロジェクト: Debian/debsources
 def _get_license_dict(self, files):
     result = []
     for f in files:
         try:
             # once DB full, remove license path
             try:
                 license_path = helper.get_sources_path(
                     session, f["package"], f["version"],
                     current_app.config)
             except (FileOrFolderNotFound, InvalidPackageOrVersionError):
                 raise Http404ErrorSuggestions(f["package"], f["version"],
                                               "")
             # parse file
             try:
                 c = helper.parse_license(license_path)
                 license = helper.get_license(f["package"], f["version"],
                                              f["path"], c)
             except copyright.NotMachineReadableError:
                 license = None
             result.append(
                 dict(
                     oracle="debian",
                     path=f["path"],
                     package=f["package"],
                     version=f["version"],
                     license=license,
                     origin=helper.license_url(f["package"], f["version"]),
                 ))
         except Exception:
             result.append(
                 dict(
                     oracle="debian",
                     path=f["path"],
                     package=f["package"],
                     version=f["version"],
                     license=None,
                     origin=helper.license_url(f["package"], f["version"]),
                 ))
     return result