[pypy-commit] buildbot default: merge sort-nightly-directories which sorts the nightly page by mtime of the subdirectories and puts trunk on top

mattip noreply at buildbot.pypy.org
Thu Mar 21 07:23:00 CET 2013


Author: Matti Picus <matti.picus at gmail.com>
Branch: 
Changeset: r753:c816177376d6
Date: 2013-03-20 23:22 -0700
http://bitbucket.org/pypy/buildbot/changeset/c816177376d6/

Log:	merge sort-nightly-directories which sorts the nightly page by mtime
	of the subdirectories and puts trunk on top

diff --git a/bot2/pypybuildbot/pypylist.py b/bot2/pypybuildbot/pypylist.py
--- a/bot2/pypybuildbot/pypylist.py
+++ b/bot2/pypybuildbot/pypylist.py
@@ -1,11 +1,10 @@
 import os.path
 import datetime
 import itertools
-import re
 import py
 import cgi
 import urllib
-from twisted.web import resource
+import sys
 from twisted.web.static import File, DirectoryLister
 
 class PyPyTarball(object):
@@ -103,25 +102,45 @@
     def display_in_italic(self):
         return self.vcs == 'latest'
 
+class PyPyDirectory(object):
+    def __init__(self, filePath):
+        self.filename = filePath.basename()
+        self.filePath = filePath
+        self.parse_filename()
+
+    def parse_filename(self):
+        if self.filename == 'trunk':
+            self.last_mod_time = sys.maxsize
+            return
+        self.last_mod_time = self.filePath.getmtime()
+
+    def key(self):
+        return (self.last_mod_time)
 
 class PyPyList(File):
 
-    def listNames(self):
-        names = File.listNames(self)
+    def sortBuildNames(self, names):
         items = map(PyPyTarball, names)
         items.sort(key=PyPyTarball.key, reverse=True)
         return [item.filename for item in items]
 
+    def sortDirectoryNames(self, filePaths):
+        items = map(PyPyDirectory, filePaths)
+        items.sort(key=PyPyDirectory.key, reverse=True)
+        return [item.filename for item in items]
+
     def directoryListing(self):
         def is_pypy_dir(names):
             for name in names:
                 if name.startswith('pypy-c'):
                     return True
             return False
-        names = self.listNames()
+        names = File.listNames(self)
         if is_pypy_dir(names):
+            names = self.sortBuildNames(names)
             Listener = PyPyDirectoryLister
         else:
+            names = self.sortDirectoryNames(File.listEntities(self))
             Listener = DirectoryLister
         return Listener(self.path,
                         names,
diff --git a/bot2/pypybuildbot/test/test_pypylist.py b/bot2/pypybuildbot/test/test_pypylist.py
--- a/bot2/pypybuildbot/test/test_pypylist.py
+++ b/bot2/pypybuildbot/test/test_pypylist.py
@@ -1,5 +1,5 @@
 import py
-from pypybuildbot.pypylist import PyPyTarball
+from pypybuildbot.pypylist import PyPyTarball, PyPyList
 
 def test_pypytarball_svn():
     t = PyPyTarball('pypy-c-jit-75654-linux.tar.bz2')
@@ -12,6 +12,7 @@
     assert t.platform == 'linux'
     assert t.vcs == 'svn'
 
+
 def test_pypytarball_hg():
     t = PyPyTarball('pypy-c-jit-75654-foo-linux.tar.bz2')
     assert t.filename == 'pypy-c-jit-75654-foo-linux.tar.bz2'
@@ -23,6 +24,7 @@
     assert t.platform == 'linux'
     assert t.vcs == 'hg'
 
+
 def test_invalid_filename():
     t = PyPyTarball('foo')
     assert t.vcs == None
@@ -35,8 +37,8 @@
     t2 = PyPyTarball('pypy-c-jit-75654-linux.tar.bz2')
     assert t.key() < t2.key()
 
-def test_sort():
-    files = map(PyPyTarball, [
+def test_sort(tmpdir):
+    files = [
             'pypy-c-jit-10000-linux.tar.bz2',
             'pypy-c-jit-20000-linux.tar.bz2',
             'pypy-c-nojit-10000-linux.tar.bz2',
@@ -45,11 +47,11 @@
             'pypy-c-stackless-10000-linux.tar.bz2',
             'pypy-c-jit-1000-e5b73981fc8d-linux.tar.bz2', # this is mercurial based
             'pypy-c-jit-10000-linux-armel.tar.bz2',
-            ])
-
-    files.sort(key=PyPyTarball.key, reverse=True)
-    files = [f.filename for f in files]
-    assert files == [
+            ]
+    [tmpdir.join(f).write(f) for f in files]
+    pypylist = PyPyList(tmpdir.strpath)
+    listener = pypylist.directoryListing()
+    assert listener.dirs == [
         'pypy-c-jit-1000-e5b73981fc8d-linux.tar.bz2', # mercurial first
         'pypy-c-jit-20000-linux.tar.bz2',
         'pypy-c-jit-10000-linux.tar.bz2',
@@ -60,6 +62,26 @@
         'pypy-c-stackless-10000-linux.tar.bz2',
         ]
 
+def test_pypy_list(tmpdir):
+    import os
+    pypylist = PyPyList(os.path.dirname(__file__))
+    files = pypylist.listNames()
+    assert os.path.basename(__file__) in files
+
+def test_dir_render(tmpdir):
+    # Create a bunch of directories, including one named trunk,
+    # Make sure the time order is reversed collation order
+    trunk = tmpdir.mkdir('trunk')
+    oldtime = trunk.mtime()
+    for ascii in range(ord('a'), ord('m')):
+        newdir = tmpdir.mkdir(chr(ascii) * 4)
+        newdir.setmtime(oldtime + ascii * 10)
+    pypylist = PyPyList(tmpdir.strpath)
+    listener = pypylist.directoryListing()
+    assert listener.dirs == ['trunk', 'mmmm', 'llll',
+        'kkkk','jjjj','iiii','hhhh','gggg','ffff','eeee',
+        'dddd','cccc','bbbb','aaaa']
+
 def load_BuildmasterConfig():
     import os
     from pypybuildbot import summary, builds
@@ -70,7 +92,7 @@
             return builds
         else:
             assert False
-    
+
     this = py.path.local(__file__)
     master_py = this.dirpath().dirpath().join('master.py')
     glob = {'httpPortNumber': 80,
@@ -91,13 +113,13 @@
         assert app == expected_app
         assert own in builders or own in known_exceptions
         assert app in builders or app in known_exceptions
-    
+
     t = PyPyTarball('pypy-c-jit-76867-linux.tar.bz2')
     check_builder_names(t, 'own-linux-x86-32', 'pypy-c-jit-linux-x86-32')
 
     t = PyPyTarball('pypy-c-nojit-76867-linux.tar.bz2')
     check_builder_names(t, 'own-linux-x86-32', 'pypy-c-app-level-linux-x86-32')
-    
+
     t = PyPyTarball('pypy-c-jit-76867-osx.tar.bz2')
     check_builder_names(t, 'own-macosx-x86-32', 'pypy-c-jit-macosx-x86-32')
 


More information about the pypy-commit mailing list