Skip to content

Instantly share code, notes, and snippets.

@carueda
Created June 11, 2014 23:04
Show Gist options
  • Save carueda/662486f8db418be61aa1 to your computer and use it in GitHub Desktop.
Save carueda/662486f8db418be61aa1 to your computer and use it in GitHub Desktop.
Generates an HTML document with an ng-grid table reporting test elapsed times from a builbot build
#!/usr/bin/env python
"""
Generates an HTML document with an ng-grid table reporting test elapsed times from a builbot build.
Uses the text version of a build output, eg.,
$ ./elapsed.py http://buildbot.oceanobservatories.org:8010/builders/coi_pycc/builds/2223/steps/sa/logs/stdio/text
$ open _elapsed_coi_pycc_2223_sa.html
@author Carlos Rueda
"""
import sys
import re
import urllib2
def main(url, output_filaname):
print 'loading %s' % url
data = urllib2.urlopen(url)
line_pat = re.compile(r'([^:]*): start time: (\d\d:\d\d:\d\d) elapsed: (\d*\.\d*)')
code = ""
comma = ""
total_elapsed = 0
for line in data:
res = line_pat.search(line)
if res:
test = res.group(1)
start_time = res.group(2)
elapsed = float(res.group(3))
total_elapsed += elapsed
code += '%s{"test": "%s", start_time: "%s", elapsed: "%s"}' % (
comma, test, start_time, elapsed)
comma = ',\n'
page = get_template().replace('{{url}}', url)
page = page.replace('{{code}}', code)
page = page.replace('{{total_elapsed}}', str(total_elapsed))
with open(output_filaname, 'w') as f:
f.write(page)
print '%s written. total_elapsed=%s' % (output_filaname, total_elapsed)
def get_template():
return """
<!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="utf-8">
<title>Elapsed</title>
<link rel="stylesheet" type="text/css" href="http://angular-ui.github.com/ng-grid/css/ng-grid.css" />
<style>
.gridStyle {
border: 1px solid rgb(212,212,212);
width: 100%;
height: 700px
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
<script type="text/javascript" src="http://angular-ui.github.com/ng-grid/lib/ng-grid.debug.js"></script>
<script type="text/javascript">
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.filterOptions = {
filterText: ''
};
$scope.gridOptions = {
data: 'myData'
,columnDefs: [
{field: 'test', width: '80%'},
{field: 'start_time', width: '10%'},
{field: 'elapsed', width: '10%'}
]
,filterOptions: $scope.filterOptions
,showColumnMenu: true
};
$scope.myData = [ {{code}} ];
});
</script>
</head>
<body ng-controller="MyCtrl">
<div>From: <a href="{{url}}">{{url}}</a></div>
<div><strong>Filter:</strong> </strong><input type="text" ng-model="filterOptions.filterText" /></div>
<div class="gridStyle" ng-grid="gridOptions"></div>
<div>total_elapsed: {{total_elapsed}}</div>
</body>
</html>
"""
if __name__ == "__main__":
url = sys.argv[1]
# .../builders/coi_pycc/builds/2169/steps/sa/logs/stdio/text
path_pat = re.compile(r'.*/builders/([^/]+)/builds/([^/]+)/steps/([^/]+)/')
res = path_pat.search(url)
if res:
builder = res.group(1)
build = res.group(2)
step = res.group(3)
output_filaname = '_elapsed_%s_%s_%s.html' % (builder, build, step)
else:
output_filaname = '_elapsed_table.html'
main(url, output_filaname)
@carueda
Copy link
Author

carueda commented Jun 11, 2014

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