Commit b5b8309d authored by Guido Trotter's avatar Guido Trotter
Browse files

ListVisibleFiles: do not sort output

Among all users, turns out just one *may* need the output to be sorted.
All the others can cope without.
Signed-off-by: default avatarGuido Trotter <>
Reviewed-by: default avatarIustin Pop <>
parent d8e0dc17
......@@ -2162,7 +2162,7 @@ def ListExports():
if os.path.isdir(constants.EXPORT_DIR):
return utils.ListVisibleFiles(constants.EXPORT_DIR)
return sorted(utils.ListVisibleFiles(constants.EXPORT_DIR))
_Fail("No exports directory")
......@@ -913,7 +913,7 @@ class JobQueue(object):
jlist = []
for filename in utils.ListVisibleFiles(constants.QUEUE_DIR, sort=False):
for filename in utils.ListVisibleFiles(constants.QUEUE_DIR):
m = self._RE_JOB_FILE.match(filename)
if m:
......@@ -1741,13 +1741,11 @@ def OwnIpAddress(address):
def ListVisibleFiles(path, sort=True):
def ListVisibleFiles(path):
"""Returns a list of visible files in a directory.
@type path: str
@param path: the directory to enumerate
@type sort: boolean
@param sort: whether to provide a sorted output
@rtype: list
@return: the list of all files not starting with a dot
@raise ProgrammerError: if L{path} is not an absolue and normalized path
......@@ -1757,8 +1755,6 @@ def ListVisibleFiles(path, sort=True):
raise errors.ProgrammerError("Path passed to ListVisibleFiles is not"
" absolute/normalized: '%s'" % path)
files = [i for i in os.listdir(path) if not i.startswith(".")]
if sort:
return files
......@@ -1341,8 +1341,7 @@ class TestListVisibleFiles(unittest.TestCase):
def _test(self, files, expected):
found = ListVisibleFiles(self.path)
# by default ListVisibleFiles sorts its output
self.assertEqual(found, sorted(expected))
self.assertEqual(set(found), set(expected))
def testAllVisible(self):
files = ["a", "b", "c"]
......@@ -1359,20 +1358,6 @@ class TestListVisibleFiles(unittest.TestCase):
expected = ["a", "b"]
self._test(files, expected)
def testForceSort(self):
files = ["c", "b", "a"]
found = ListVisibleFiles(self.path, sort=True)
self.assertEqual(found, sorted(files))
def testForceNonSort(self):
files = ["c", "b", "a"]
found = ListVisibleFiles(self.path, sort=False)
# We can't actually check that they weren't sorted, because they might come
# out sorted by chance
self.assertEqual(set(found), set(files))
def testNonAbsolutePath(self):
self.failUnlessRaises(errors.ProgrammerError, ListVisibleFiles, "abc")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment