返回介绍

3.3.7. Utilities

发布于 2023-09-20 23:50:40 字数 5671 浏览 0 评论 0 收藏 0

Caution

Buildbot no longer supports Python 2.7 on the Buildbot master.

3.3.7. Utilities

Several small utilities are available at the top-level

class buildbot.util.lru.LRUCache(miss_fn, max_size=50)

This package provides a few useful collection objects.

Note

This module used to be named collections, but without absolute imports (PEP 328), this precluded using the standard library’s collections module.

class buildbot.util.bbcollections.defaultdict

This function provides a simple way to say “please do this later”. For example

from buildbot.util.eventual import eventually
def do_what_I_say(what, where):
    # ...
    return d
eventually(do_what_I_say, "clean up", "your bedroom")

The package defines “later” as “next time the reactor has control”, so this is a good way to avoid long loops that block another activity in the reactor.

buildbot.util.eventual.eventually(cb, *args, **kwargs)

It’s often necessary to perform some action in response to a particular type of event. For example, steps need to update their status after updates arrive from the worker. However, when many events arrive in quick succession, it’s more efficient to only perform the action once, after the last event has occurred.

The debounce.method(wait) decorator is the tool for the job.

buildbot.util.debounce.method(wait, get_reactor)

Many Buildbot services perform some periodic, asynchronous operation. Change sources, for example, contact the repositories they monitor on a regular basis. The tricky bit is, the periodic operation must complete before the service stops.

The @poll.method decorator makes this behavior easy and reliable.

buildbot.util.poll.method()

Several Buildbot components make use of maildirs to hand off messages between components. On the receiving end, there’s a need to watch a maildir for incoming messages and trigger some action when one arrives.

class buildbot.util.maildir.MaildirService(basedir)
buildbot.util.misc.deferredLocked(lock)

Similar to maildirs, netstrings are used occasionally in Buildbot to encode data for interchange. While Twisted supports a basic netstring receiver protocol, it does not have a simple way to apply that to a non-network situation.

class buildbot.util.netstrings.NetstringParser

This module contains a few utilities that are not included with SQLAlchemy.

class buildbot.util.sautils.InsertFromSelect(table, select)
class buildbot.util.pathmatch.Matcher
class buildbot.util.topicmatch.TopicMatcher(topics)

The classes in the buildbot.util.subscription module are used for master-local subscriptions. In the near future, all uses of this module will be replaced with message-queueing implementations that allow subscriptions and subscribers to span multiple masters.

3.3.7.13. buildbot.util.croniter

This module is a copy of https://github.com/taichino/croniter, and provides support for converting cron-like time specifications to actual times.

3.3.7.14.

The classes in the

This module makes it easy to manipulate identifiers.

buildbot.util.identifiers.isIdentifier(maxLength, object)
class buildbot.util.lineboundaries.LineBoundaryFinder

This module implements some useful subclasses of Twisted services.

The first two classes are more robust implementations of two Twisted classes, and should be used universally in Buildbot code.

class buildbot.util.service.AsyncMultiService
class buildbot.util.httpclientservice.HTTPClientService
class buildbot.test.fake.httpclientservice.HTTPClientService

This module is a copy of twisted.internet.ssl except it won’t crash with ImportError if pyopenssl is not installed. If you need to use twisted.internet.ssl, please instead use buildbot.util.ssl, and call ssl.ensureHasSSL in checkConfig to provide helpful message to the user, only if they enabled SSL for your plugin.

buildbot.util.ssl.ensureHasSSL(plugin_name)
Parameters:

plugin_name – name of the plugin. Usually self.__class__.__name__

Call this function to provide helpful config error to the user in case of OpenSSL not installed.

buildbot.util.ssl.skipUnless(f)
Parameters:

f – decorated test

Test decorator which will skip the test if OpenSSL is not installed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文