Skip to content

Instantly share code, notes, and snippets.

@alexpearce
Created May 6, 2015 14:08
Show Gist options
  • Select an option

  • Save alexpearce/90a9ca0c236dcb799517 to your computer and use it in GitHub Desktop.

Select an option

Save alexpearce/90a9ca0c236dcb799517 to your computer and use it in GitHub Desktop.
Check the status of the LHCb nightlies
#!/usr/bin/env python
from __future__ import print_function
import argparse
import os
import re
import ssl
import sys
import urllib
from xml.dom import minidom
# {0}: Project name e.g. DaVinci
RSS_URL = (
'https://buildlhcb.cern.ch/nightlies/rss'
'?slotlist=all;projectlist={0};platformlist=all'
)
WINDOWS = sys.platform == 'windows'
def are_nightlies_healthy(project, branch=None, platform=None):
"""Print the status of the nightlies for the project name.
Keyword arguments:
project -- LHCb software project, e.g. 'DaVinci'
"""
# Disable SSL certificate check
ssl._create_default_https_context = ssl._create_unverified_context
# Fetch the response
request = urllib.urlopen(RSS_URL.format(project))
if request.getcode() != 200:
print('Could not fetch status for project "{0}"'.format(project),
file=sys.stderr)
return 1
tree = minidom.parse(request)
items = tree.getElementsByTagName('item')
if not items:
print('Could not fetch status for project "{0}"'.format(project),
file=sys.stderr)
return 1
for item in tree.getElementsByTagName('item'):
for title in item.getElementsByTagName('title'):
nv = title.firstChild.nodeValue
if branch and not re.search(branch, nv):
continue
if platform and not re.search(platform, nv):
continue
if 'FAIL' in nv or 'ERROR' in nv and not WINDOWS:
nv = '\033[01;31m{0}\033[01;0m'.format(nv)
if 'WARNING' in nv and not WINDOWS:
nv = '\033[01;33m{0}\033[01;0m'.format(nv)
if 'PASS' in nv and not WINDOWS:
nv = '\033[01;32m{0}\033[01;0m'.format(nv)
print(nv)
return 0
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="Print status of nightlies")
parser.add_argument('project',
help='Software project name, e.g. DaVinci')
parser.add_argument('--branch',
help=(
'Filter by build branch, e.g. lhcb-cmt. '
'Accepts regular expressions.'
))
parser.add_argument('--platform',
help=(
'Filter by build platform, e.g. '
'x86_64-slc6-gcc-opt. '
'Accepts regular expressions.'
))
parser.add_argument('--current-platform',
action='store_true',
help=(
'Only check the status for the current platform,'
'taken from $CMTCONFIG. Overrides --platform.'
))
args = parser.parse_args()
# Filter by $CMTCONFIG is requested
# If $CMTCONFIG is not set, don't filter by platform
if args.current_platform:
try:
platform = os.environ['CMTCONFIG']
except KeyError:
print('Could not find $CMTCONFIG, will display all platforms',
file=sys.stderr)
platform = args.platform
else:
platform = args.platform
sys.exit(are_nightlies_healthy(args.project, args.branch, platform))
@alexpearce
Copy link
Copy Markdown
Author

Example usage:

# Download the gist and make it executable
$ wget https://gist.githubusercontent.com/alexpearce/90a9ca0c236dcb799517/raw/2e02eaa326dd017268fe9c063cf5a5744934264f/are_nightlies_healthy.py
$ chmod +x are_nightlies_healthy.py
# Run it!
$ ./are_nightlies_healthy.py DaVinci --current-platform
[PASS-TEST] lhcb-lcg-head  DaVinci  x86_64-slc6-gcc48-opt
[PASS-TEST] lhcb-testing  DaVinci  x86_64-slc6-gcc48-opt
[ERROR-BUILD] lhcb-lcg-head  DaVinci  x86_64-slc6-gcc48-opt
[ERROR-BUILD] lhcb-testing  DaVinci  x86_64-slc6-gcc48-opt
[FAIL-TEST] lhcb-patches2  DaVinci  x86_64-slc6-gcc48-opt
[PASS-TEST] lhcb-gaudi-head  DaVinci  x86_64-slc6-gcc48-opt
[FAIL-TEST] lhcb-cmt  DaVinci  x86_64-slc6-gcc48-opt
[PASS-TEST] lhcb-head  DaVinci  x86_64-slc6-gcc48-opt
[PASS-TEST] lhcb-prerelease  DaVinci  x86_64-slc6-gcc48-opt
[WARNINGS-BUILD] lhcb-cmt  DaVinci  x86_64-slc6-gcc48-opt
[ERROR-BUILD] lhcb-head  DaVinci  x86_64-slc6-gcc48-opt
[ERROR-BUILD] lhcb-gaudi-head  DaVinci  x86_64-slc6-gcc48-opt
[ERROR-BUILD] lhcb-prerelease  DaVinci  x86_64-slc6-gcc48-opt
[ERROR-BUILD] lhcb-patches2  DaVinci  x86_64-slc6-gcc48-opt

Filter by branch or platform with regular expressions:

$ ./are_nightlies_healthy.py Gauss --branch=lhcb-cmt --platform=".*gcc49.*"
[WARNINGS-BUILD] lhcb-cmt  Gauss  x86_64-slc6-gcc49-dbg
[FAIL-TEST] lhcb-cmt  Gauss  x86_64-slc6-gcc49-opt
[WARNINGS-BUILD] lhcb-cmt  Gauss  x86_64-slc6-gcc49-opt

For help:

$ ./are_nightlies_healthy.py --help

@alexpearce
Copy link
Copy Markdown
Author

This gist is licensed under the MIT license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment