Revision b5b8309d
b/lib/backend.py | ||
---|---|---|
2162 | 2162 |
|
2163 | 2163 |
""" |
2164 | 2164 |
if os.path.isdir(constants.EXPORT_DIR): |
2165 |
return utils.ListVisibleFiles(constants.EXPORT_DIR)
|
|
2165 |
return sorted(utils.ListVisibleFiles(constants.EXPORT_DIR))
|
|
2166 | 2166 |
else: |
2167 | 2167 |
_Fail("No exports directory") |
2168 | 2168 |
|
b/lib/jqueue.py | ||
---|---|---|
913 | 913 |
|
914 | 914 |
""" |
915 | 915 |
jlist = [] |
916 |
for filename in utils.ListVisibleFiles(constants.QUEUE_DIR, sort=False):
|
|
916 |
for filename in utils.ListVisibleFiles(constants.QUEUE_DIR): |
|
917 | 917 |
m = self._RE_JOB_FILE.match(filename) |
918 | 918 |
if m: |
919 | 919 |
jlist.append(m.group(1)) |
b/lib/utils.py | ||
---|---|---|
1741 | 1741 |
source=constants.LOCALHOST_IP_ADDRESS) |
1742 | 1742 |
|
1743 | 1743 |
|
1744 |
def ListVisibleFiles(path, sort=True):
|
|
1744 |
def ListVisibleFiles(path): |
|
1745 | 1745 |
"""Returns a list of visible files in a directory. |
1746 | 1746 |
|
1747 | 1747 |
@type path: str |
1748 | 1748 |
@param path: the directory to enumerate |
1749 |
@type sort: boolean |
|
1750 |
@param sort: whether to provide a sorted output |
|
1751 | 1749 |
@rtype: list |
1752 | 1750 |
@return: the list of all files not starting with a dot |
1753 | 1751 |
@raise ProgrammerError: if L{path} is not an absolue and normalized path |
... | ... | |
1757 | 1755 |
raise errors.ProgrammerError("Path passed to ListVisibleFiles is not" |
1758 | 1756 |
" absolute/normalized: '%s'" % path) |
1759 | 1757 |
files = [i for i in os.listdir(path) if not i.startswith(".")] |
1760 |
if sort: |
|
1761 |
files.sort() |
|
1762 | 1758 |
return files |
1763 | 1759 |
|
1764 | 1760 |
|
b/test/ganeti.utils_unittest.py | ||
---|---|---|
1341 | 1341 |
def _test(self, files, expected): |
1342 | 1342 |
self._CreateFiles(files) |
1343 | 1343 |
found = ListVisibleFiles(self.path) |
1344 |
# by default ListVisibleFiles sorts its output |
|
1345 |
self.assertEqual(found, sorted(expected)) |
|
1344 |
self.assertEqual(set(found), set(expected)) |
|
1346 | 1345 |
|
1347 | 1346 |
def testAllVisible(self): |
1348 | 1347 |
files = ["a", "b", "c"] |
... | ... | |
1359 | 1358 |
expected = ["a", "b"] |
1360 | 1359 |
self._test(files, expected) |
1361 | 1360 |
|
1362 |
def testForceSort(self): |
|
1363 |
files = ["c", "b", "a"] |
|
1364 |
self._CreateFiles(files) |
|
1365 |
found = ListVisibleFiles(self.path, sort=True) |
|
1366 |
self.assertEqual(found, sorted(files)) |
|
1367 |
|
|
1368 |
def testForceNonSort(self): |
|
1369 |
files = ["c", "b", "a"] |
|
1370 |
self._CreateFiles(files) |
|
1371 |
found = ListVisibleFiles(self.path, sort=False) |
|
1372 |
# We can't actually check that they weren't sorted, because they might come |
|
1373 |
# out sorted by chance |
|
1374 |
self.assertEqual(set(found), set(files)) |
|
1375 |
|
|
1376 | 1361 |
def testNonAbsolutePath(self): |
1377 | 1362 |
self.failUnlessRaises(errors.ProgrammerError, ListVisibleFiles, "abc") |
1378 | 1363 |
|
Also available in: Unified diff