示例#1
0
    def get_objects(self, packagename):
        suite = request.args.get("suite") or ""
        suite = suite.lower()
        if suite == "all":
            suite = ""
        # we list the version with suites it belongs to
        try:
            versions_w_suites = qry.pkg_names_list_versions_w_suites(
                session, packagename, suite, reverse=True)
        except InvalidPackageOrVersionError:
            raise Http404Error("%s not found" % packagename)

        # we simply add pathl (for use with "You are here:")
        if request.blueprint == 'sources':
            endpoint = '.source'
        elif request.blueprint == 'copyright':
            endpoint = '.versions'

        pathl = qry.location_get_path_links(endpoint, packagename)
        return dict(type="package",
                    package=packagename,
                    versions=versions_w_suites,
                    path=packagename,
                    suite=suite,
                    pathl=pathl
                    )
示例#2
0
    def get_stats_suite(self, suite, **kwargs):
        if suite not in statistics.suites(session, "all"):
            raise Http404Error()  # security, to avoid suite='../../foo',
            # to include <img>s, etc.
        stats_file = current_app.config["CACHE_DIR"] / "license_stats.data"
        res = extract_stats(filename=stats_file, filter_suites=[suite])
        licenses = [license.replace(suite + ".", "") for license in res.keys()]
        dual_stats_file = app.config["CACHE_DIR"] / "dual_license.data"
        dual_res = extract_stats(filename=dual_stats_file,
                                 filter_suites=[suite])

        dual_licenses = [
            license.replace(suite + ".", "") for license in dual_res.keys()
        ]

        info = qry.get_suite_info(session, suite)

        return dict(
            results=res,
            licenses=sorted(licenses),
            dual_results=dual_res,
            dual_licenses=sorted(dual_licenses),
            suite=suite,
            rel_date=str(info.release_date),
            rel_version=info.version,
        )
示例#3
0
def handle_latest_version(endpoint, package, path):
    """
    redirects to the latest version for the requested page,
    when 'latest' is provided instead of a version number
    """

    suite_order = consts.SUITES['all']

    try:
        versions = qry.pkg_names_list_versions(session,
                                               package,
                                               suite_order=suite_order)

    except InvalidPackageOrVersionError:
        raise Http404Error("%s not found" % package)
    # This is already sorted in the pkg_names_list_versions function.
    # So, we just extract the required value.
    version = [v.version for v in versions][-1]

    # avoids extra '/' at the end
    if path == "":
        redirect_url = '/'.join([package, version])
    else:
        redirect_url = '/'.join([package, version, path])
    return redirect_to_url(endpoint, redirect_url)
示例#4
0
    def get_objects(self, prefix='a'):
        """
        returns the packages beginning with prefix
        and belonging to suite if specified.
        """
        prefix = prefix.lower()
        suite = request.args.get("suite") or ""
        suite = suite.lower()
        if suite == "all":
            suite = ""
        if prefix in qry.pkg_names_get_packages_prefixes(
                app.config["CACHE_DIR"]):
            try:
                if not suite:
                    packages = qry.get_pkg_filter_prefix(session,
                                                         prefix).all()
                else:
                    packages = qry.get_pkg_filter_prefix(session,
                                                         prefix,
                                                         suite).all()

                packages = [p.to_dict() for p in packages]
            except Exception as e:
                raise Http500Error(e)
            return dict(packages=packages,
                        prefix=prefix,
                        suite=suite)
        else:
            raise Http404Error("prefix unknown: %s" % str(prefix))
示例#5
0
    def get_infos(self):
        """
        Retrieves information about the version of a package:
        - area
        - vcs
        - suites
        - size
        - sloc
        - pts link
        """
        pkg_infos = dict()

        infos = self._get_direct_infos()
        if infos is None:  # pragma: no cover
            raise Http404Error()

        pkg_infos["area"] = infos.area

        if infos.vcs_type and infos.vcs_browser:
            pkg_infos['vcs_type'] = infos.vcs_type
            pkg_infos['vcs_browser'] = infos.vcs_browser

        pkg_infos["suites"] = self._get_associated_suites()

        pkg_infos["sloc"] = self._get_sloc()

        pkg_infos["metric"] = self._get_metrics()

        pkg_infos["pts_link"] = self._get_pts_link()

        pkg_infos["ctags_count"] = self._get_ctags_count()

        return pkg_infos
示例#6
0
    def _handle_latest_version(self, endpoint, package, path):
        """
        redirects to the latest version for the requested page,
        when 'latest' is provided instead of a version number
        """
        try:
            versions = qry.pkg_names_list_versions(session, package)
        except InvalidPackageOrVersionError:
            raise Http404Error("%s not found" % package)
        # the latest version is the latest item in the
        # sorted list (by debian_support.version_compare)
        version = sorted([v.version for v in versions],
                         cmp=version_compare)[-1]

        # avoids extra '/' at the end
        if path == "":
            redirect_url = '/'.join([package, version])
        else:
            if request.blueprint == 'patches':
                patch = '/'.join(path.split('/')[2:])
                redirect_url = '/'.join([package, version, patch])
            else:
                redirect_url = '/'.join([package, version, path])

        return self._redirect_to_url(endpoint, redirect_url)
示例#7
0
    def get_stats_suite(self, suite, **kwargs):
        if suite not in statistics.suites(session, 'all'):
            raise Http404Error()  # security, to avoid suite='../../foo',
            # to include <img>s, etc.
        stats_file = current_app.config["CACHE_DIR"] / "stats.data"
        res = extract_stats(filename=stats_file,
                            filter_suites=["debian_" + suite])
        info = qry.get_suite_info(session, suite)

        return dict(results=res,
                    languages=SLOCCOUNT_LANGUAGES,
                    suite=suite,
                    rel_date=str(info.release_date),
                    rel_version=info.version)
示例#8
0
def handle_versions(version, package, path):
    check_for_alias = session.query(SuiteAlias) \
        .filter(SuiteAlias.alias == version).first()
    if check_for_alias:
        version = check_for_alias.suite
    try:
        versions_w_suites = qry.pkg_names_list_versions_w_suites(
            session, package)
    except InvalidPackageOrVersionError:
        raise Http404Error("%s not found" % package)

    versions = sorted(
        [v['version'] for v in versions_w_suites if version in v['suites']],
        cmp=version_compare)
    return versions
示例#9
0
    def get_objects(self, packagename):
        suite = request.args.get("suite") or ""
        suite = suite.lower()
        if suite == "all":
            suite = ""
        # we list the version with suites it belongs to
        try:
            versions_w_suites = qry.pkg_names_list_versions_w_suites(
                session, packagename, suite, reverse=True)
        except InvalidPackageOrVersionError:
            raise Http404Error("%s not found" % packagename)
        empty = False
        for i, v in enumerate(versions_w_suites):
            try:
                format_file = helper.get_patch_format(session, packagename,
                                                      v["version"],
                                                      current_app.config)
            except FileOrFolderNotFound:
                format_file = ""
                versions_w_suites[i]["supported"] = False
            if not helper.is_supported(format_file.rstrip()):
                versions_w_suites[i]["supported"] = False
            else:
                versions_w_suites[i]["supported"] = True
                try:
                    series = helper.get_patch_series(session, packagename,
                                                     v["version"],
                                                     current_app.config)
                except (FileOrFolderNotFound, InvalidPackageOrVersionError):
                    series = []
                if len(series) == 0:
                    empty = True
                versions_w_suites[i]["series"] = len(series)

        return dict(
            type="package",
            package=packagename,
            versions=versions_w_suites,
            path=packagename,
            suite=suite,
            is_empty=empty,
        )
示例#10
0
    def _render_location(self, package, version, path):
        """
        renders a location page, can be a folder or a file
        """
        try:
            location = Location(session,
                                current_app.config["SOURCES_DIR"],
                                current_app.config["SOURCES_STATIC"],
                                package, version, path)
        except (FileOrFolderNotFound, InvalidPackageOrVersionError):
            raise Http404ErrorSuggestions(package, version, path)

        if location.is_symlink():
            # check if it's secure
            symlink_dest = os.readlink(location.sources_path)
            dest = os.path.normpath(  # absolute, target file
                os.path.join(os.path.dirname(location.sources_path),
                             symlink_dest))
            # note: adding trailing slash because normpath drops them
            if dest.startswith(os.path.normpath(location.version_path) + '/'):
                # symlink is safe; redirect to its destination
                redirect_url = os.path.normpath(
                    os.path.join(os.path.dirname(location.path_to),
                                 symlink_dest))
                self.render_func = bind_redirect(url_for(request.endpoint,
                                                 path_to=redirect_url),
                                                 code=301)
                return dict(redirect=redirect_url)
            else:
                raise Http403Error(
                    'insecure symlink, pointing outside package/version/')

        if location.is_dir():  # folder, we list its content
            return self._render_directory(location)

        elif location.is_file():  # file
            return self._render_file(location)

        else:  # doesn't exist
            raise Http404Error(None)
示例#11
0
    def get_infos(self):
        """
        Retrieves information about the version of a package:
        - area
        - vcs
        - suites
        - size
        - sloc
        - pts link
        """
        pkg_infos = dict()

        infos = self._get_direct_infos()
        if infos is None:  # pragma: no cover
            raise Http404Error()

        pkg_infos["area"] = infos.area

        if infos.vcs_type and infos.vcs_browser:
                pkg_infos['vcs_type'] = infos.vcs_type
                pkg_infos['vcs_browser'] = infos.vcs_browser

        pkg_infos["suites"] = self._get_associated_suites()

        pkg_infos["sloc"] = self._get_sloc()

        pkg_infos["metric"] = self._get_metrics()

        pkg_infos["pts_link"] = self._get_pts_link()

        pkg_infos["ctags_count"] = self._get_ctags_count()

        if current_app.config.get('BLUEPRINT_COPYRIGHT'):
            pkg_infos['copyright'] = True
            pkg_infos['license'] = self._get_license_link()
        else:
            pkg_infos['copyright'] = False

        return pkg_infos