Ejemplo n.º 1
0
    def get_query(self, query=''):
        """
        processes the search query and renders the results in a dict
        """
        query = query.replace('%', '').replace('_', '')
        suite = request.args.get("suite") or ""
        suite = suite.lower()
        if suite == "all":
            suite = ""

        try:
            exact_matching = qry.get_pkg_by_name(session, query, suite)

            other_results = qry.get_pkg_by_similar_name(session, query, suite)
        except Exception as e:
            raise Http500Error(e)  # db problem, ...

        if exact_matching is not None:
            exact_matching = exact_matching.to_dict()
        if other_results is not None:
            other_results = [o.to_dict() for o in other_results]
            # we exclude the 'exact' matching from other_results:
            other_results = [x for x in other_results if x != exact_matching]

        results = dict(exact=exact_matching, other=other_results)
        return dict(results=results, query=query, suite=suite)
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
    def _get_ctags_count(self):
        """ctags counts"""
        try:
            ctags_count = (self.session.query(Ctag).filter(
                Ctag.package_id == Package.id, Package.version == self.version,
                Package.name_id == PackageName.id,
                PackageName.name == self.package).count())
        except Exception as e:  # pragma: no cover
            raise Http500Error(e)

        return ctags_count
Ejemplo n.º 4
0
    def _get_metrics(self):
        """ metrics"""
        try:
            metric = (self.session.query(Metric).filter(
                Metric.package_id == Package.id,
                Package.version == self.version,
                Package.name_id == PackageName.id,
                PackageName.name == self.package).all())
        except Exception as e:  # pragma: no cover
            raise Http500Error(e)

        return dict([(x.metric, x.value) for x in metric])
Ejemplo n.º 5
0
    def _get_associated_suites(self):
        """ associated suites, which come from Suite """
        try:
            suites = (self.session.query(Suite.suite).filter(
                Suite.package_id == Package.id,
                Package.version == self.version,
                Package.name_id == PackageName.id,
                PackageName.name == self.package).all())
        except Exception as e:  # pragma: no cover
            raise Http500Error(e)

        return [x[0] for x in suites]
Ejemplo n.º 6
0
    def _get_direct_infos(self):
        """ information available directly in Package table """
        try:
            infos = (self.session.query(Package).filter(
                Package.version == self.version,
                Package.name_id == PackageName.id,
                PackageName.name == self.package).first())

        except Exception as e:  # pragma: no cover
            raise Http500Error(e)

        return infos
Ejemplo n.º 7
0
    def _get_sloc(self):
        """ sloccount """
        try:
            sloc = (self.session.query(SlocCount).filter(
                SlocCount.package_id == Package.id,
                Package.version == self.version,
                Package.name_id == PackageName.id,
                PackageName.name == self.package).order_by(
                    SlocCount.count.desc()).all())
        except Exception as e:  # pragma: no cover
            raise Http500Error(e)

        return [(x.language, x.count) for x in sloc]