[LNT] r293978 - More whitespace fixups
Chris Matthews via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 2 16:52:29 PST 2017
Author: cmatthews
Date: Thu Feb 2 18:52:29 2017
New Revision: 293978
URL: http://llvm.org/viewvc/llvm-project?rev=293978&view=rev
Log:
More whitespace fixups
Modified:
lnt/trunk/lnt/server/ui/util.py
Modified: lnt/trunk/lnt/server/ui/util.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/util.py?rev=293978&r1=293977&r2=293978&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/util.py (original)
+++ lnt/trunk/lnt/server/ui/util.py Thu Feb 2 18:52:29 2017
@@ -2,10 +2,12 @@ import colorsys
import math
import re
+
def toColorString(col):
- r,g,b = [clamp(int(v*255), 0, 255)
- for v in col]
- return "#%02x%02x%02x" % (r,g,b)
+ r, g, b = [clamp(int(v * 255), 0, 255)
+ for v in col]
+ return "#%02x%02x%02x" % (r, g, b)
+
def detectCPUs():
"""
@@ -19,60 +21,67 @@ def detectCPUs():
ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
if isinstance(ncpus, int) and ncpus > 0:
return ncpus
- else: # OSX:
+ else: # OSX:
return int(os.popen2("sysctl -n hw.ncpu")[1].read())
# Windows:
if os.environ.has_key("NUMBER_OF_PROCESSORS"):
ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
if ncpus > 0:
return ncpus
- return 1 # Default
+ return 1 # Default
+
def pairs(list):
- return zip(list[:-1],list[1:])
+ return zip(list[:-1], list[1:])
+
def safediv(a, b, default=None):
try:
- return a/b
+ return a / b
except ZeroDivisionError:
return default
+
def makeDarkerColor(h):
return makeDarkColor(h, 0.50)
+
def makeDarkColor(h, v=0.8):
- h = h%1.
+ h = h % 1.
s = 0.95
- return colorsys.hsv_to_rgb(h,0.9+s*.1,v)
+ return colorsys.hsv_to_rgb(h, 0.9 + s * .1, v)
+
def makeMediumColor(h):
- h = h%1.
+ h = h % 1.
s = .68
v = 0.92
- return colorsys.hsv_to_rgb(h,s,v)
+ return colorsys.hsv_to_rgb(h, s, v)
+
def makeLightColor(h):
- h = h%1.
- s = (0.5,0.4)[h>0.5 and h<0.8]
+ h = h % 1.
+ s = (0.5, 0.4)[h > 0.5 and h < 0.8]
v = 1.0
- return colorsys.hsv_to_rgb(h,s,v)
+ return colorsys.hsv_to_rgb(h, s, v)
+
def makeBetterColor(h):
- h = math.cos(h*math.pi*.5)
- s = .8 + ((math.cos(h * math.pi*.5) + 1)*.5) * .2
+ h = math.cos(h * math.pi * .5)
+ s = .8 + ((math.cos(h * math.pi * .5) + 1) * .5) * .2
v = .88
- return colorsys.hsv_to_rgb(h,s,v)
+ return colorsys.hsv_to_rgb(h, s, v)
# The hash color palette avoids green and red as these colours are already used
# in quite a few places to indicate "good" or "bad".
hash_color_palette = (
- colorsys.hsv_to_rgb(h=45./360, s=0.3, v=0.9999), # warm yellow
- colorsys.hsv_to_rgb(h=210./360, s=0.3, v=0.9999), # blue cyan
- colorsys.hsv_to_rgb(h=300./360, s=0.3, v=0.9999), # mid magenta
- colorsys.hsv_to_rgb(h=150./360, s=0.3, v=0.9999), # green cyan
- colorsys.hsv_to_rgb(h=225./360, s=0.3, v=0.9999), # cool blue
- colorsys.hsv_to_rgb(h=180./360, s=0.3, v=0.9999), # mid cyan
+ colorsys.hsv_to_rgb(h=45. / 360, s=0.3, v=0.9999), # warm yellow
+ colorsys.hsv_to_rgb(h=210. / 360, s=0.3, v=0.9999), # blue cyan
+ colorsys.hsv_to_rgb(h=300. / 360, s=0.3, v=0.9999), # mid magenta
+ colorsys.hsv_to_rgb(h=150. / 360, s=0.3, v=0.9999), # green cyan
+ colorsys.hsv_to_rgb(h=225. / 360, s=0.3, v=0.9999), # cool blue
+ colorsys.hsv_to_rgb(h=180. / 360, s=0.3, v=0.9999), # mid cyan
)
@@ -102,115 +111,137 @@ def get_rgb_colors_for_hashes(hash_strin
class multidict:
def __init__(self, elts=()):
self.data = {}
- for key,value in elts:
+ for key, value in elts:
self[key] = value
def __contains__(self, item):
return item in self.data
+
def __getitem__(self, item):
return self.data[item]
+
def __setitem__(self, key, value):
if key in self.data:
self.data[key].append(value)
else:
self.data[key] = [value]
+
def items(self):
return self.data.items()
+
def values(self):
return self.data.values()
+
def keys(self):
return self.data.keys()
+
def __len__(self):
return len(self.data)
+
def get(self, key, default=None):
return self.data.get(key, default)
+
def any_true(list, predicate):
for i in list:
if predicate(i):
return True
return False
+
def any_false(list, predicate):
return any_true(list, lambda x: not predicate(x))
+
def all_true(list, predicate):
return not any_false(list, predicate)
+
def all_false(list, predicate):
return not any_true(list, predicate)
+
def geometric_mean(l):
- iPow = 1./len(l)
- return reduce(lambda a,b: a*b, [v**iPow for v in l])
+ iPow = 1. / len(l)
+ return reduce(lambda a, b: a * b, [v ** iPow for v in l])
+
def mean(l):
return sum(l) / len(l)
+
def median(l):
l = list(l)
l.sort()
N = len(l)
- return (l[(N - 1)//2] +
- l[(N + 0)//2]) * .5
+ return (l[(N - 1) // 2] +
+ l[(N + 0) // 2]) * .5
+
def prependLines(prependStr, str):
- return ('\n'+prependStr).join(str.splitlines())
+ return ('\n' + prependStr).join(str.splitlines())
+
def pprint(object, useRepr=True):
def recur(ob):
return pprint(ob, useRepr)
+
def wrapString(prefix, string, suffix):
return '%s%s%s' % (prefix,
prependLines(' ' * len(prefix),
string),
suffix)
+
def pprintArgs(name, args):
- return wrapString(name + '(', ',\n'.join(map(recur,args)), ')')
+ return wrapString(name + '(', ',\n'.join(map(recur, args)), ')')
if isinstance(object, tuple):
- return wrapString('(', ',\n'.join(map(recur,object)),
- [')',',)'][len(object) == 1])
+ return wrapString('(', ',\n'.join(map(recur, object)),
+ [')', ',)'][len(object) == 1])
elif isinstance(object, list):
- return wrapString('[', ',\n'.join(map(recur,object)), ']')
+ return wrapString('[', ',\n'.join(map(recur, object)), ']')
elif isinstance(object, set):
return pprintArgs('set', list(object))
elif isinstance(object, dict):
elts = []
- for k,v in object.items():
+ for k, v in object.items():
kr = recur(k)
vr = recur(v)
elts.append('%s : %s' % (kr,
- prependLines(' ' * (3 + len(kr.splitlines()[-1])),
- vr)))
+ prependLines(
+ ' ' * (3 + len(kr.splitlines()[-1])),
+ vr)))
return wrapString('{', ',\n'.join(elts), '}')
else:
if useRepr:
return repr(object)
return str(object)
+
def prefixAndPPrint(prefix, object, useRepr=True):
- return prefix + prependLines(' '*len(prefix), pprint(object, useRepr))
+ return prefix + prependLines(' ' * len(prefix), pprint(object, useRepr))
+
def clamp(v, minVal, maxVal):
return min(max(v, minVal), maxVal)
-def lerp(a,b,t):
- t_ = 1. - t
- return tuple([av*t_ + bv*t for av,bv in zip(a,b)])
+def lerp(a, b, t):
+ t_ = 1. - t
+ return tuple([av * t_ + bv * t for av, bv in zip(a, b)])
class PctCell:
# Color levels
- kNeutralColor = (1,1,1)
- kNegativeColor = (0,1,0)
- kPositiveColor = (1,0,0)
+ kNeutralColor = (1, 1, 1)
+ kNegativeColor = (0, 1, 0)
+ kPositiveColor = (1, 0, 0)
# Invalid color
- kNANColor = (.86,.86,.86)
- kInvalidColor = (0,0,1)
+ kNANColor = (.86, .86, .86)
+ kInvalidColor = (0, 0, 1)
- def __init__(self, value, reverse=False, precision=2, delta=False, data=None):
+ def __init__(self, value, reverse=False, precision=2, delta=False,
+ data=None):
if delta and isinstance(value, float):
value -= 1
self.value = value
@@ -248,11 +279,11 @@ class PctCell:
return ""
if not isinstance(self.value, float):
return self.value
- return '%.*f%%' % (self.precision, self.value*100)
+ return '%.*f%%' % (self.precision, self.value * 100)
def getColorString(self):
return toColorString(self.getColor())
-
+
def render(self, class_=None, style=None, attributes=None):
bgcolor = 'background-color:%s' % (self.getColorString(),)
style = bgcolor if style is None else style + "; " + bgcolor
@@ -267,7 +298,8 @@ class PctCell:
attrs.append('%s="%s"' % (key, value))
attr_string = ' '.join(attrs)
if self.data:
- return '<td %s>%s (%s)</td>' % (attr_string, self.data, self.getValue())
+ return '<td %s>%s (%s)</td>' % (
+ attr_string, self.data, self.getValue())
else:
return '<td %s>%s</td>' % (attr_string, self.getValue())
@@ -289,13 +321,14 @@ def renderProducerAsHTML(producer):
png_url = 'http://%(url)s/png?builder=%(builder)s&number=%(build)s' % locals()
img = '<img src="%(png_url)s">' % locals()
return '<a href="%(producer)s">%(builder)s #%(build)s %(img)s</a>' % locals()
-
+
elif producer.startswith('http://'):
return '<a href="' + producer + '">Producer</a>'
-
+
else:
return producer
+
FLASH_DANGER = "alert alert-danger"
FLASH_INFO = "alert alert-info"
FLASH_SUCCESS = "alert alert-success"
@@ -308,7 +341,7 @@ def guess_test_short_name(test_name):
"""
split_name = test_name.split("/")
last_path_name = split_name[-1]
-
+
# LNT Compile tests are stragely named:
# compile/TestName/phase/(opt level)
if last_path_name.startswith("("):
More information about the llvm-commits
mailing list