如何访问 XML 版本的 CruiseContol.NET Web 仪表板报告(通过 HTTP)?

发布于 2024-07-08 23:36:03 字数 398 浏览 7 评论 0原文

我需要确定上次构建的状态(成功/失败),我这样做是这样的:

report_url = 'http://.../ViewLatestBuildReport.aspx'
success_marker = '<td class="header-title" colspan="2">BUILD SUCCESSFUL</td>'
page = urllib.urlopen(report_url)
if all(success_marker not in line for line in page):
  # build is not good, do something
  ...

但这很浪费(加载整个 HTML 页面),容易出错(我已经遇到了 bytes/unicode bug)并且脆弱。

I need to determine state of last build (success/failure) and I do it like this:

report_url = 'http://.../ViewLatestBuildReport.aspx'
success_marker = '<td class="header-title" colspan="2">BUILD SUCCESSFUL</td>'
page = urllib.urlopen(report_url)
if all(success_marker not in line for line in page):
  # build is not good, do something
  ...

But this is wasteful (loads entire HTML page), error-prone (I already ran into a bytes/unicode bug) and fragile.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩饰不了的爱 2024-07-15 23:36:03

好吧,我大概明白了。 CCTray 通过轮询 XmlServerReport.aspx 来跟踪构建状态,这是(令人惊讶!)XML。

所以我当前的解决方案如下所示:

import sys, urllib, xml.sax, xml.sax.handler

report_url = 'http://.../CCNET/XmlServerReport.aspx'

class FoundBuildStatus(Exception):
  def __init__(self, status):
    self.build_status = status

class Handler(xml.sax.handler.ContentHandler):
  def startElement(self, name, attrs):
    if name == 'Project' and attrs.get('name') == '...':
      status = attrs.get('lastBuildStatus')
      if status:
        raise FoundBuildStatus(status)

page = urllib.urlopen(report_url)
try:
  xml.sax.parse(page, Handler())
except FoundBuildStatus, ex:
  if ex.build_status == 'Failure':
    # build is not good, do something
    ...

在我的环境中,它比最初的基于 HTML 的解决方案快大约 8 倍。

OK, I sort of figured it out. CCTray tracks build status by polling XmlServerReport.aspx, which is (surprise!) XML.

So my current solution looks like this:

import sys, urllib, xml.sax, xml.sax.handler

report_url = 'http://.../CCNET/XmlServerReport.aspx'

class FoundBuildStatus(Exception):
  def __init__(self, status):
    self.build_status = status

class Handler(xml.sax.handler.ContentHandler):
  def startElement(self, name, attrs):
    if name == 'Project' and attrs.get('name') == '...':
      status = attrs.get('lastBuildStatus')
      if status:
        raise FoundBuildStatus(status)

page = urllib.urlopen(report_url)
try:
  xml.sax.parse(page, Handler())
except FoundBuildStatus, ex:
  if ex.build_status == 'Failure':
    # build is not good, do something
    ...

In my environment it is about 8 times faster than initial HTML-based solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文