Example #1
0
    def find_req(self, reqstr, order_by='distro_id'):
        ses = self.sessionmaker()
        query = ses.query(model.SQLDistro)

        pkgreqs = [x for x in pkg_resources.parse_requirements(reqstr)]
        reqs = [model.SQLDistro.distro_id == \
                  utils.make_distro_id(x.project_name)
                for x in pkgreqs]
        query = query.filter(sa.or_(*reqs))

        if order_by is not None:
            vals = []
            for x in order_by.split(','):
                vals.append('distros_'+x.strip())
            query = query.order_by(','.join(vals))

        distros = [x for x in query
                   if self.has_role(x.distro_id,
                                    READER_ROLE, MANAGER_ROLE,
                                    model.OWNER_ROLE)]

        res = []
        for distro in distros:
            entries = []
            for f in self.get_files(distro.distro_id):
                version = utils.parse_version(f)
                if version:
                    for r in pkgreqs:
                        if version in r:
                            entries.append((f, version))
                            break
            if entries:
                res.append((distro, entries))

        return res
    def get_index_dict(self, base_url):
        index = self.pypi.get_index(self.distro.distro_id, self.indexname)
        entries = []
        for target_distro, distro, filename in index:
            target_distro_id = get_distro_id(target_distro)
            url = None
            name = None
            if filename is not None:
                url = '%s%s/f/%s' % (base_url, target_distro_id, filename)
                name = target_distro.name

            if not name:
                utils.logger.warn('Bad distro for: '+target_distro_id)
                continue

            req = name+'=='+utils.parse_version(filename)
            entries.append({'target_distro_id': target_distro_id,
                            'name': name,
                            'req': req,
                            'url': url})
        return {'indexname': self.indexname,
                'id': self.indexname,
                'entries': entries}