当前位置: 首页>>代码示例>>Python>>正文


Python IMasterStore.add方法代码示例

本文整理汇总了Python中lp.services.database.interfaces.IMasterStore.add方法的典型用法代码示例。如果您正苦于以下问题:Python IMasterStore.add方法的具体用法?Python IMasterStore.add怎么用?Python IMasterStore.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lp.services.database.interfaces.IMasterStore的用法示例。


在下文中一共展示了IMasterStore.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_LoginTokenPruner

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
    def test_LoginTokenPruner(self):
        store = IMasterStore(LoginToken)
        now = datetime.now(UTC)
        switch_dbuser('testadmin')

        # It is configured as a daily task.
        self.assertTrue(
            LoginTokenPruner in DailyDatabaseGarbageCollector.tunable_loops)

        # Create a token that will be pruned.
        old_token = LoginToken(
            email='whatever', tokentype=LoginTokenType.NEWACCOUNT)
        old_token.date_created = now - timedelta(days=666)
        old_token_id = old_token.id
        store.add(old_token)

        # Create a token that will not be pruned.
        current_token = LoginToken(
            email='whatever', tokentype=LoginTokenType.NEWACCOUNT)
        current_token_id = current_token.id
        store.add(current_token)

        # Run the pruner. Batching is tested by the BulkPruner tests so
        # no need to repeat here.
        switch_dbuser('garbo_daily')
        pruner = LoginTokenPruner(logging.getLogger('garbo'))
        while not pruner.isDone():
            pruner(10)
        pruner.cleanUp()

        # Only the old LoginToken is gone.
        self.assertEqual(
            store.find(LoginToken, id=old_token_id).count(), 0)
        self.assertEqual(
            store.find(LoginToken, id=current_token_id).count(), 1)
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:37,代码来源:test_garbo.py

示例2: new

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
 def new(cls, job_type, status=BuildStatus.NEEDSBUILD, date_created=None,
         builder=None, archive=None):
     """See `IBuildFarmJobSource`."""
     build_farm_job = BuildFarmJob(
         job_type, status, date_created, builder, archive)
     store = IMasterStore(BuildFarmJob)
     store.add(build_farm_job)
     return build_farm_job
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:10,代码来源:buildfarmjob.py

示例3: new

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
 def new(self, distribution, root_dir, base_url, copy_base_url):
     """Make and return a new `PublisherConfig`."""
     store = IMasterStore(PublisherConfig)
     pubconf = PublisherConfig()
     pubconf.distribution = distribution
     pubconf.root_dir = root_dir
     pubconf.base_url = base_url
     pubconf.copy_base_url = copy_base_url
     store.add(pubconf)
     return pubconf
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:12,代码来源:publisherconfig.py

示例4: newPackagesetUploader

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
    def newPackagesetUploader(
        self, archive, person, packageset, explicit=False):
        """See `IArchivePermissionSet`."""
        packageset = self._nameToPackageset(packageset)
        store = IMasterStore(ArchivePermission)

        # First see whether we have a matching permission in the database
        # already.
        query = '''
            SELECT ap.id
            FROM archivepermission ap, teamparticipation tp
            WHERE
                ap.person = tp.team AND tp.person = ?
                AND ap.packageset = ? AND ap.archive = ?
        '''
        query = SQL(query, (person.id, packageset.id, archive.id))
        permissions = list(
            store.find(
                ArchivePermission, ArchivePermission.id.is_in(query)))
        if len(permissions) > 0:
            # Found permissions in the database, does the 'explicit' flag
            # have the requested value?
            conflicting = [permission for permission in permissions
                           if permission.explicit != explicit]
            if len(conflicting) > 0:
                # At least one permission with conflicting 'explicit' flag
                # value exists already.
                cperm = conflicting[0]
                raise ValueError(
                    "Permission for package set '%s' already exists for %s "
                    "but with a different 'explicit' flag value (%s)." %
                    (packageset.name, cperm.person.name, cperm.explicit))
            else:
                # No conflicts, does the requested permission exist already?
                existing = [permission for permission in permissions
                            if (permission.explicit == explicit and
                                permission.person == person and
                                permission.packageset == packageset)]
                assert len(existing) <= 1, (
                    "Too many permissions for %s and %s" %
                    (person.name, packageset.name))
                if len(existing) == 1:
                    # The existing permission matches, just return it.
                    return existing[0]

        # The requested permission does not exist yet. Insert it into the
        # database.
        permission = ArchivePermission(
            archive=archive,
            person=person, packageset=packageset,
            permission=ArchivePermissionType.UPLOAD, explicit=explicit)
        store.add(permission)

        return permission
开发者ID:vitaminmoo,项目名称:unnaturalcode,代码行数:56,代码来源:archivepermission.py

示例5: storeAssociation

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
 def storeAssociation(self, server_url, association):
     """See `OpenIDStore`."""
     store = IMasterStore(self.Association)
     db_assoc = store.get(
         self.Association, (server_url.decode('UTF-8'),
                            association.handle.decode('ASCII')))
     if db_assoc is None:
         db_assoc = self.Association(server_url, association)
         store.add(db_assoc)
     else:
         db_assoc.update(association)
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:13,代码来源:baseopenidstore.py

示例6: new

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
 def new(self, derived_series, parent_series, initialized,
         is_overlay=False, pocket=None, component=None, ordering=1):
     """Make and return a new `DistroSeriesParent`."""
     store = IMasterStore(DistroSeriesParent)
     dsp = DistroSeriesParent()
     dsp.derived_series = derived_series
     dsp.parent_series = parent_series
     dsp.initialized = initialized
     dsp.is_overlay = is_overlay
     dsp.pocket = pocket
     dsp.component = component
     dsp.ordering = ordering
     store.add(dsp)
     return dsp
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:16,代码来源:distroseriesparent.py

示例7: new

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
 def new(cls, distroseries, recipe, requester, archive, pocket=None,
         date_created=None, duration=None):
     """See `ISourcePackageRecipeBuildSource`."""
     store = IMasterStore(SourcePackageRecipeBuild)
     if pocket is None:
         pocket = PackagePublishingPocket.RELEASE
     if date_created is None:
         date_created = UTC_NOW
     build_farm_job = getUtility(IBuildFarmJobSource).new(
         cls.job_type, BuildStatus.NEEDSBUILD, date_created, None, archive)
     spbuild = cls(
         build_farm_job, distroseries, recipe, requester, archive, pocket,
         date_created)
     store.add(spbuild)
     return spbuild
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:17,代码来源:sourcepackagerecipebuild.py

示例8: useNonce

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
    def useNonce(self, server_url, timestamp, salt):
        """See `OpenIDStore`."""
        # If the nonce is too far from the present time, it is not valid.
        if abs(timestamp - time.time()) > nonce.SKEW:
            return False

        server_url = server_url.decode('UTF-8')
        salt = salt.decode('ASCII')

        store = IMasterStore(self.Nonce)
        old_nonce = store.get(self.Nonce, (server_url, timestamp, salt))
        if old_nonce is not None:
            # The nonce has already been seen, so reject it.
            return False
        # Record the nonce so it can't be used again.
        store.add(self.Nonce(server_url, timestamp, salt))
        return True
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:19,代码来源:baseopenidstore.py

示例9: new

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
    def new(cls, name, owner, registrant, description=None,
            configuration=None, branches=None):
        """See `IBranchMergeQueueSource`."""
        store = IMasterStore(BranchMergeQueue)

        if configuration is None:
            configuration = unicode(simplejson.dumps({}))

        queue = cls()
        queue.name = name
        queue.owner = owner
        queue.registrant = registrant
        queue.description = description
        queue.configuration = configuration
        if branches is not None:
            for branch in branches:
                branch.addToQueue(queue)

        store.add(queue)
        return queue
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:22,代码来源:branchmergequeue.py

示例10: __init__

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
    def __init__(self, *args, **kwargs):
        """Extended version of the SQLObjectBase constructor.

        We force use of the master Store.

        We refetch any parameters from different stores from the
        correct master Store.
        """
        # Make it simple to write dumb-invalidators - initialized
        # _cached_properties to a valid list rather than just-in-time
        # creation.
        self._cached_properties = []
        store = IMasterStore(self.__class__)

        # The constructor will fail if objects from a different Store
        # are passed in. We need to refetch these objects from the correct
        # master Store if necessary so the foreign key references can be
        # constructed.
        # XXX StuartBishop 2009-03-02 bug=336867: We probably want to remove
        # this code - there are enough other places developers have to be
        # aware of the replication # set boundaries. Why should
        # Person(..., account=an_account) work but
        # some_person.account = an_account fail?
        for key, argument in kwargs.items():
            argument = removeSecurityProxy(argument)
            if not isinstance(argument, Storm):
                continue
            argument_store = Store.of(argument)
            if argument_store is not store:
                new_argument = store.find(
                    argument.__class__, id=argument.id).one()
                assert new_argument is not None, (
                    '%s not yet synced to this store' % repr(argument))
                kwargs[key] = new_argument

        store.add(self)
        try:
            self._create(None, **kwargs)
        except:
            store.remove(self)
            raise
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:43,代码来源:sqlbase.py

示例11: new

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
 def new(registrant, owner, name, recipe, description,
         distroseries=None, daily_build_archive=None, build_daily=False,
         date_created=DEFAULT):
     """See `ISourcePackageRecipeSource.new`."""
     store = IMasterStore(SourcePackageRecipe)
     sprecipe = SourcePackageRecipe()
     builder_recipe = SourcePackageRecipeData.getParsedRecipe(recipe)
     SourcePackageRecipeData(builder_recipe, sprecipe)
     sprecipe.registrant = registrant
     sprecipe.owner = owner
     sprecipe.name = name
     if distroseries is not None:
         for distroseries_item in distroseries:
             sprecipe.distroseries.add(distroseries_item)
     sprecipe.description = description
     sprecipe.daily_build_archive = daily_build_archive
     sprecipe.build_daily = build_daily
     sprecipe.date_created = date_created
     sprecipe.date_last_modified = date_created
     store.add(sprecipe)
     return sprecipe
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:23,代码来源:sourcepackagerecipe.py

示例12: test_OAuthNoncePruner

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
    def test_OAuthNoncePruner(self):
        now = datetime.now(UTC)
        timestamps = [
            now - timedelta(days=2),  # Garbage
            now - timedelta(days=1) - timedelta(seconds=60),  # Garbage
            now - timedelta(days=1) + timedelta(seconds=60),  # Not garbage
            now,  # Not garbage
            ]
        switch_dbuser('testadmin')
        store = IMasterStore(OAuthNonce)

        # Make sure we start with 0 nonces.
        self.failUnlessEqual(store.find(OAuthNonce).count(), 0)

        for timestamp in timestamps:
            store.add(OAuthNonce(
                access_token=OAuthAccessToken.get(1),
                request_timestamp=timestamp,
                nonce=str(timestamp)))
        transaction.commit()

        # Make sure we have 4 nonces now.
        self.failUnlessEqual(store.find(OAuthNonce).count(), 4)

        self.runFrequently(
            maximum_chunk_size=60)  # 1 minute maximum chunk size

        store = IMasterStore(OAuthNonce)

        # Now back to two, having removed the two garbage entries.
        self.failUnlessEqual(store.find(OAuthNonce).count(), 2)

        # And none of them are older than a day.
        # Hmm... why is it I'm putting tz aware datetimes in and getting
        # naive datetimes back? Bug in the SQLObject compatibility layer?
        # Test is still fine as we know the timezone.
        self.failUnless(
            store.find(
                Min(OAuthNonce.request_timestamp)).one().replace(tzinfo=UTC)
            >= now - timedelta(days=1))
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:42,代码来源:test_garbo.py

示例13: new

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
    def new(
        self, name, description, owner, distroseries=None, related_set=None):
        """See `IPackagesetSet`."""
        store = IMasterStore(Packageset)

        packagesetgroup = None
        if related_set is not None:
            # Use the packagesetgroup of the `related_set`.
            packagesetgroup = related_set.packagesetgroup
        else:
            # We create the related internal PackagesetGroup for this
            # packageset so that we can later see related package sets across
            # distroseries.
            packagesetgroup = PackagesetGroup()
            packagesetgroup.owner = owner
            store.add(packagesetgroup)

        if distroseries is None:
            ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
            distroseries = ubuntu.currentseries

        packageset = Packageset()
        packageset.packagesetgroup = packagesetgroup
        packageset.name = name
        packageset.description = description
        packageset.owner = owner

        packageset.distroseries = distroseries

        store.add(packageset)

        # We need to ensure that the cached statements are flushed so that
        # the duplicate name constraint gets triggered here.
        try:
            store.flush()
        except IntegrityError:
            raise DuplicatePackagesetName()

        return packageset
开发者ID:vitaminmoo,项目名称:unnaturalcode,代码行数:41,代码来源:packageset.py

示例14: test_OpenIDConsumerNoncePruner

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
    def test_OpenIDConsumerNoncePruner(self):
        now = int(time.mktime(time.gmtime()))
        MINUTES = 60
        HOURS = 60 * 60
        DAYS = 24 * HOURS
        timestamps = [
            now - 2 * DAYS,  # Garbage
            now - 1 * DAYS - 1 * MINUTES,  # Garbage
            now - 1 * DAYS + 1 * MINUTES,  # Not garbage
            now,  # Not garbage
            ]
        switch_dbuser('testadmin')

        store = IMasterStore(OpenIDConsumerNonce)

        # Make sure we start with 0 nonces.
        self.failUnlessEqual(store.find(OpenIDConsumerNonce).count(), 0)

        for timestamp in timestamps:
            store.add(OpenIDConsumerNonce(
                    u'http://server/', timestamp, u'aa'))
        transaction.commit()

        # Make sure we have 4 nonces now.
        self.failUnlessEqual(store.find(OpenIDConsumerNonce).count(), 4)

        # Run the garbage collector.
        self.runFrequently(maximum_chunk_size=60)  # 1 minute maximum chunks.

        store = IMasterStore(OpenIDConsumerNonce)

        # We should now have 2 nonces.
        self.failUnlessEqual(store.find(OpenIDConsumerNonce).count(), 2)

        # And none of them are older than 1 day
        earliest = store.find(Min(OpenIDConsumerNonce.timestamp)).one()
        self.failUnless(
            earliest >= now - 24 * 60 * 60, 'Still have old nonces')
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:40,代码来源:test_garbo.py

示例15: new

# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import add [as 别名]
    def new(distro_series_difference, owner, comment):
        """See `IDistroSeriesDifferenceCommentSource`."""
        msgid = make_msgid('distroseriesdifference')
        message = Message(
            parent=None, owner=owner, rfc822msgid=msgid,
            subject=distro_series_difference.title)
        MessageChunk(message=message, content=comment, sequence=1)

        store = IMasterStore(DistroSeriesDifferenceComment)
        dsd_comment = DistroSeriesDifferenceComment()
        dsd_comment.distro_series_difference = distro_series_difference
        dsd_comment.message = message

        comment = store.add(dsd_comment)
        store.flush()
        return comment
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:18,代码来源:distroseriesdifferencecomment.py


注:本文中的lp.services.database.interfaces.IMasterStore.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。