def findRecipes(branch_or_repository, revspecs=None):
        """Find recipes for a given branch or repository.

        :param branch_or_repository: The branch or repository to search for.
        :param revspecs: If not None, return only recipes whose `revspec` is
            in this sequence.
        :return: a collection of `ISourcePackageRecipe`s.
        """
        from lp.code.model.sourcepackagerecipe import SourcePackageRecipe
        store = Store.of(branch_or_repository)
        if IGitRepository.providedBy(branch_or_repository):
            data_clause = (SourcePackageRecipeData.base_git_repository ==
                           branch_or_repository)
            insn_clause = (_SourcePackageRecipeDataInstruction.git_repository
                           == branch_or_repository)
        elif IBranch.providedBy(branch_or_repository):
            data_clause = (
                SourcePackageRecipeData.base_branch == branch_or_repository)
            insn_clause = (_SourcePackageRecipeDataInstruction.branch ==
                           branch_or_repository)
        else:
            raise AssertionError("Unsupported source: %r" %
                                 (branch_or_repository, ))
        if revspecs is not None:
            concrete_revspecs = [
                revspec for revspec in revspecs if revspec is not None
            ]
            data_revspec_clause = In(SourcePackageRecipeData.revspec,
                                     concrete_revspecs)
            insn_revspec_clause = In(
                _SourcePackageRecipeDataInstruction.revspec, concrete_revspecs)
            if None in revspecs:
                data_revspec_clause = Or(
                    data_revspec_clause,
                    SourcePackageRecipeData.revspec == None)
                insn_revspec_clause = Or(
                    insn_revspec_clause,
                    _SourcePackageRecipeDataInstruction.revspec == None)
            data_clause = And(data_clause, data_revspec_clause)
            insn_clause = And(insn_clause, insn_revspec_clause)
        return store.find(
            SourcePackageRecipe,
            SourcePackageRecipe.id.is_in(
                Union(
                    Select(SourcePackageRecipeData.sourcepackage_recipe_id,
                           data_clause),
                    Select(
                        SourcePackageRecipeData.sourcepackage_recipe_id,
                        And(
                            _SourcePackageRecipeDataInstruction.recipe_data_id
                            == SourcePackageRecipeData.id, insn_clause)))))
Exemple #2
0
    def search(self, query, vocab_filter=None):
        """Return a resultset of archives.

        This is a helper required by `SQLObjectVocabularyBase.searchForTerms`.
        """
        if not query:
            return self.emptySelectResults()

        query = query.lower()

        if query.startswith('~'):
            query = query.strip('~')
        if query.startswith('ppa:'):
            query = query[4:]
        try:
            query_split = query.split('/')
            if len(query_split) == 3:
                owner_name, distro_name, archive_name = query_split
            else:
                owner_name, archive_name = query_split
        except ValueError:
            search_clause = Or(
                fti_search(Archive, query), fti_search(Person, query))
        else:
            search_clause = And(
                Person.name == owner_name, Archive.name == archive_name)

        clause = And(
            self._filter,
            get_enabled_archive_filter(
                getUtility(ILaunchBag).user, purpose=ArchivePurpose.PPA,
                include_public=True),
            search_clause)
        return self._table.select(
            clause, orderBy=self._orderBy, clauseTables=self._clauseTables)
    def searchBinaryPackages(self, text):
        """See `IDistroArchSeries`."""
        from lp.soyuz.model.publishing import BinaryPackagePublishingHistory

        origin = [
            BinaryPackageRelease,
            Join(
                BinaryPackagePublishingHistory,
                BinaryPackagePublishingHistory.binarypackagerelease ==
                    BinaryPackageRelease.id),
            Join(
                BinaryPackageName,
                BinaryPackageRelease.binarypackagename ==
                    BinaryPackageName.id)]

        find_spec = [BinaryPackageRelease, BinaryPackageName]
        archives = self.distroseries.distribution.getArchiveIDList()

        clauses = [
            BinaryPackagePublishingHistory.distroarchseries == self,
            BinaryPackagePublishingHistory.archiveID.is_in(archives),
            BinaryPackagePublishingHistory.status.is_in(
                active_publishing_status)]
        order_by = [BinaryPackageName.name]
        if text:
            ranking = rank_by_fti(BinaryPackageRelease, text)
            find_spec.append(ranking)
            clauses.append(
                Or(
                    fti_search(BinaryPackageRelease, text),
                    BinaryPackageName.name.contains_string(text.lower())))
            order_by.insert(0, ranking)
        result = IStore(BinaryPackageName).using(*origin).find(
            tuple(find_spec), *clauses).config(distinct=True).order_by(
                *order_by)

        # import here to avoid circular import problems
        from lp.soyuz.model.distroarchseriesbinarypackagerelease import (
            DistroArchSeriesBinaryPackageRelease)

        # Create a function that will decorate the results, converting
        # them from the find_spec above into DASBPRs.
        def result_to_dasbpr(row):
            return DistroArchSeriesBinaryPackageRelease(
                distroarchseries=self, binarypackagerelease=row[0])

        # Return the decorated result set so the consumer of these
        # results will only see DSPs.
        return DecoratedResultSet(result, result_to_dasbpr)
Exemple #4
0
    def getForUser(self,
                   username,
                   limit=20,
                   olderThan=None,
                   newerThan=None,
                   filterTags=None,
                   filterAbout=None,
                   additionalTags=None):
        """Get the comments made by a particular user or on the user object.

        @param username: The user to get the comments for.
        @param limit: Optionally, The maximum number of comments to return.
        @param olderThan: Optionally a C{datetime} indicating to return only
            comments older than it.
        @param filterTags: Optionally a C{list} of tag paths. If not C{None},
            return only comment objects with _all_ of the specified tag paths.
        @param filterAbout: Optionally, return only comments made on a
            given object.
        @param additionalTags: Optionally, a list of paths of additional tags
            to retrieve.
        @return: A C{list} of comments represented by a C{dict} with the
            following format::

            {
                'fluidinfo.com/info/about': <about-value-list>,
                'fluidinfo.com/info/text': <comment-text>,
                'fluidinfo.com/info/timestamp': <float-timestamp>,
                'fluidinfo.com/info/url': <url>,
                'fluidinfo.com/info/username': <username>,
            }
        """
        store = getMainStore()
        result = store.find(
            CommentObjectLink.commentID,
            CommentObjectLink.objectID == AboutTagValue.objectID,
            AboutTagValue.value == u'@' + username)
        subselect = result.get_select_expr(CommentObjectLink.commentID)

        where = [
            Or(Comment.username == username, Comment.objectID.is_in(subselect))
        ]
        return self._findComments(where,
                                  limit,
                                  olderThan,
                                  newerThan,
                                  filterTags=filterTags,
                                  filterAbout=filterAbout,
                                  additionalTags=additionalTags)
Exemple #5
0
def getTagValues(values=None):
    """Get L{TagValue}s.

    @param values: Optionally, a sequence of C{(objectID, Tag.id)} 2-tuples to
        filter the result with.
    @return: A C{ResultSet} with L{TagValue}s.
    """
    store = getMainStore()
    where = []
    if values:
        expressions = [
            And(TagValue.objectID == objectID, TagValue.tagID == tagID)
            for objectID, tagID in values
        ]
        where = [Or(*expressions)]
    return store.find(TagValue, *where)
Exemple #6
0
def getRecentActivity(objectIDs=None, usernames=None, limit=20):
    """Get information about recent tag values.

    @param objectIDs: Optionally, a sequence of L{TagValue.objectID} to get
        recent tag value information for.
    @param usernames: Optionally, a sequence of L{User.username}s to get
        recent tag value information for.
    @param limit: Optionally, a limit to the number of rows returned by this
        function.
    @return: A generator yielding C{(Tag.path, TagValue.objectID,
        AboutTagValue.value, TagValue.value, User.username,
        value.creationTime)} 6-tuples with the information about the recent
        tag values. The tuples are sorted by creation time.
    """
    if objectIDs and usernames:
        mainCondition = Or(User.username.is_in(usernames),
                           TagValue.objectID.is_in(objectIDs))
    elif objectIDs:
        mainCondition = (TagValue.objectID.is_in(objectIDs))
    elif usernames:
        # If we're only requesting one user, we use a special query which is
        # optimized by the use the tag_values_creator_creation_idx two-column
        # index in Postgres.
        if len(usernames) == 1:
            [username] = usernames
            subselect = Select(User.id, User.username == username)
            mainCondition = (TagValue.creatorID == subselect)
        else:
            mainCondition = (User.username.is_in(usernames))
    else:
        return

    store = getMainStore()
    join = LeftJoin(TagValue, AboutTagValue,
                    TagValue.objectID == AboutTagValue.objectID)
    result = store.using(User, Tag, join).find(
        (Tag, TagValue, AboutTagValue, User), mainCondition,
        TagValue.creatorID == User.id, TagValue.tagID == Tag.id)
    result = result.order_by(Desc(TagValue.creationTime))
    result = result.config(limit=limit)

    # FIXME: We have to do this because Storm doesn's support getting null
    # values for about_tag_values in the LEFT JOIN.
    for tag, value, aboutValue, user in result:
        about = aboutValue.value if aboutValue else None
        yield (tag.path, value.objectID, about, value.value, user.username,
               value.creationTime)
Exemple #7
0
    def spec_filter_clause(self, user, filter=None):
        """Figure out the appropriate query for specifications on a sprint.

        We separate out the query generation from the normal
        specifications() method because we want to reuse this query in the
        specificationLinks() method.
        """
        # Avoid circular imports.
        from lp.blueprints.model.specification import Specification
        tables, query = get_specification_active_product_filter(self)
        tables.insert(0, Specification)
        query.append(get_specification_privacy_filter(user))
        tables.append(
            Join(SprintSpecification,
                 SprintSpecification.specification == Specification.id))
        query.append(SprintSpecification.sprintID == self.id)

        if not filter:
            # filter could be None or [] then we decide the default
            # which for a sprint is to show everything approved
            filter = [SpecificationFilter.ACCEPTED]

        # figure out what set of specifications we are interested in. for
        # sprint, we need to be able to filter on the basis of:
        #
        #  - completeness.
        #  - acceptance for sprint agenda.
        #  - informational.
        #

        sprint_status = []
        # look for specs that have a particular SprintSpecification
        # status (proposed, accepted or declined)
        if SpecificationFilter.ACCEPTED in filter:
            sprint_status.append(SprintSpecificationStatus.ACCEPTED)
        if SpecificationFilter.PROPOSED in filter:
            sprint_status.append(SprintSpecificationStatus.PROPOSED)
        if SpecificationFilter.DECLINED in filter:
            sprint_status.append(SprintSpecificationStatus.DECLINED)
        statuses = [
            SprintSpecification.status == status for status in sprint_status
        ]
        if len(statuses) > 0:
            query.append(Or(*statuses))
        # Filter for specification text
        query.extend(get_specification_filters(filter, goalstatus=False))
        return tables, query
Exemple #8
0
    def getAllFollowed(self,
                       username,
                       limit=20,
                       olderThan=None,
                       newerThan=None):
        """
        Get all the comments on the followed objects, by the followed users and
        by the requested user.

        @param username: The user to get the comments for.
        @param limit: Optionally, The maximum number of comments to return.
        @param olderThan: Optionally a C{datetime} indicating to return only
            comments older than it.
        @param newerThan: A C{datetime} indicating to return only
            comments newer than it.
        @return: A C{list} of comments represented by a C{dict} with the
            following format::

            {
                'fluidinfo.com/info/about': <about-value-list>,
                'fluidinfo.com/info/text': <comment-text>,
                'fluidinfo.com/info/timestamp': <float-timestamp>,
                'fluidinfo.com/info/url': <url>,
                'fluidinfo.com/info/username': <username>,
            }
        """
        store = getMainStore()
        result = getObjectIDs([username + u'/follows'])
        objectsSubselect = result.get_select_expr(TagValue.objectID)

        result = store.find(User.username, User.objectID == TagValue.objectID,
                            Tag.id == TagValue.tagID,
                            Tag.path == username + u'/follows')
        usersSubselect = result.get_select_expr(User.username)

        where = [
            Comment.objectID == CommentObjectLink.commentID,
            Or(CommentObjectLink.objectID.is_in(objectsSubselect),
               Comment.username.is_in(usersSubselect),
               Comment.username == username)
        ]

        if olderThan is not None:
            where.append(Comment.creationTime < olderThan)

        return self._findComments(where, limit, olderThan, newerThan)
Exemple #9
0
def getAboutTagValues(objectIDs=None, values=None):
    """Get L{AboutTagValue}s.

    @param objectIDs: Optionally, a sequence of C{objectID}s to filter the
        result with.
    @param values: Optionally, a sequence of C{AboutTagValue.value}s to filter
        the result with.
    """
    store = getMainStore()
    where = []
    if objectIDs:
        where.append(AboutTagValue.objectID.is_in(objectIDs))
    if values:
        where.append(AboutTagValue.value.is_in(values))
    if where:
        # Can't pass an Or expression to store.find if where is empty
        # i.e, no filtering is requested
        return store.find(AboutTagValue, Or(*where))
    return store.find(AboutTagValue)
Exemple #10
0
    def testCreate(self):
        """L{User.create} creates new L{User}s based on the provided data."""
        users = [(u'fred', u'fred-secret', u'Fred', u'*****@*****.**'),
                 (u'joe', u'joe-secret', u'Joe', u'*****@*****.**')]
        self.users.create(users)
        result = self.store.find(
            User,
            Not(
                Or(User.username == u'fluiddb',
                   User.username == u'fluidinfo.com',
                   User.username == u'anon')))
        result.order_by(User.username)
        [user1, user2] = list(result)
        self.assertEqual(u'fred', user1.username)
        self.assertEqual(hashPassword(u'fred-secret', user1.passwordHash),
                         user1.passwordHash)
        self.assertEqual(u'Fred', user1.fullname)
        self.assertEqual(u'*****@*****.**', user1.email)

        self.assertEqual(u'joe', user2.username)
        self.assertEqual(hashPassword(u'joe-secret', user2.passwordHash),
                         user2.passwordHash)
        self.assertEqual(u'Joe', user2.fullname)
        self.assertEqual(u'*****@*****.**', user2.email)
Exemple #11
0
                                           _err=lambda l: 0)
            time.sleep(settings.AIRODUMP_SCAN_WAIT)
            airodump_process.terminate()
            networks = Reader('data/scan-01.csv').get_sorted_networks()
        except UnicodeDecodeError, e:
            logger.warning(
                'Decoding the output of airodump failed, trying again from scratch (Error: %s)',
                e)
    local = local_db()
    excluded = None
    for net in networks:
        if net['bssid'] in exclude and excluded is None:
            excluded = net
        known_net = local.find(
            Network,
            And(Or(Network.bssid.like(u'_%'), Network.bssid == net['bssid']),
                Network.essid == net['essid']))
        if known_net.is_empty():
            return net
    return excluded


def airodump(ch, interface):
    return airodump_ng('-c',
                       ch,
                       '-w',
                       'data/inj',
                       interface.dev,
                       _err=lambda l: 0)