Created
May 6, 2015 14:08
-
-
Save alexpearce/90a9ca0c236dcb799517 to your computer and use it in GitHub Desktop.
Check the status of the LHCb nightlies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is licensed under the MIT license.