# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import os
-import tempfile
import testtools
-import unittest
from buildfarm import util
-class ChangeExtensionTests(unittest.TestCase):
-
- def test_simple(self):
- self.assertEquals("foo.bar", util.ChangeExtension("foo.old", "bar"))
- self.assertEquals("foo.png", util.ChangeExtension("foo.png", "png"))
- self.assertEquals("foobar.png", util.ChangeExtension("foobar", "png"))
-
-
-class DhmTimeTests(unittest.TestCase):
+class DhmTimeTests(testtools.TestCase):
def test_simple(self):
self.assertEquals("0s", util.dhm_time(0))
self.assertEquals("-", util.dhm_time(-20))
self.assertEquals("1d 3h 1m", util.dhm_time(97265))
self.assertEquals("3h 1m", util.dhm_time(10865))
-
-
-class LoadTests(testtools.TestCase):
-
- def test_simple(self):
- fd, name = tempfile.mkstemp()
- self.addCleanup(os.remove, name)
- f = os.fdopen(fd, 'w')
- f.write("""one
-two
-three\r
-
-for
-""")
- f.close()
- l = util.load_list(name)
- self.assertEquals(4, len(l))
- self.assertEquals("three", l[2])
-
-
-class StripHtmlTests(unittest.TestCase):
-
- def test_simple(self):
- self.assertEquals("", util.strip_html("<!--foo-->"))
- self.assertEquals("bar ", util.strip_html("<!--foo-->bar <!--bloe-->"))
- self.assertEquals("bar <bloe>", util.strip_html("<bar>bar <bloe></bar>"))
- self.assertEquals("", util.strip_html("<bar><bloe></bloe></bar>"))
-
- self.assertEquals("bla", util.strip_html("<a href=\"foo\">bla</a>"))
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import re
-
def load_list(fname):
"""load a list from a file, using : to separate"""
ret = []
return ret
-def FileLoad(filename):
- """read a file into a string"""
- f = open(filename, 'r')
- try:
- return f.read()
- finally:
- f.close()
-
-
-def FileSave(filename, contents):
- """write a string into a file"""
- f = open(filename, 'w')
- try:
- f.write(contents)
- finally:
- f.close()
-
-
-def ChangeExtension(fname, ext):
- """return a filename with a changed extension"""
- try:
- (base, oldext) = fname.rsplit(".", 1)
- except ValueError:
- return "%s.%s" % (fname, ext)
- else:
- return "%s.%s" % (base, ext)
-
-
def dhm_time(sec):
"""display a time as days, hours, minutes"""
days = int(sec / (60*60*24));
if min != 0:
return "%dm" % min
return "%ds" % sec
-
-
-def strip_html(string):
- """simple html markup stripper"""
- # get rid of comments
- string = re.sub("<!\-\-(.*?)\-\->", "", string)
-
- # and remove tags.
- count = True
- while count:
- (string, count) = re.subn("<(\w+).*?>(.*?)</\\1>", "\\2", string)
-
- return string
return "<a href='%s?function=View+Build;%s'>%s</a>" % (myself, ";".join(["%s=%s" % k for k in params.iteritems()]), html_build_status(build.status()))
-def build_status_vals(status):
- """translate a status into a set of int representing status"""
- status = util.strip_html(status)
-
- status = status.replace("ok", "0")
- status = status.replace("-", "0")
- status = status.replace("?", "0.1")
- status = status.replace("PANIC", "1")
-
- return status.split("/")
-
-
def host_link(myself, host):
return "<a href='%s?function=View+Host;host=%s'>%s</a>" % (
myself, host, host)