Store the list of directories and loop on directories in reversed order, to

process subdirectories before their parent (fix #6).
This commit is contained in:
Simon
2012-12-11 00:05:52 +01:00
parent 2d5407d073
commit 3c7d6449d2
2 changed files with 9 additions and 4 deletions

View File

@@ -51,10 +51,11 @@ class Gallery:
def build_paths(self):
"Build the list of directories with images"
self.paths = {}
self.paths = {'paths_list': []}
for path, dirnames, filenames in os.walk(self.input_dir):
relpath = os.path.relpath(path, self.input_dir)
self.paths['paths_list'].append(relpath)
# sort images and sub-albums by name
filenames.sort(key=str.lower)
@@ -95,8 +96,9 @@ class Gallery:
self.build_paths()
check_or_create_dir(self.output_dir)
# loop on directories
for path in self.paths.keys():
# loop on directories in reversed order, to process subdirectories
# before their parent
for path in reversed(self.paths['paths_list']):
imglist = [os.path.join(self.input_dir, path, f)
for f in self.paths[path]['img']]

View File

@@ -29,7 +29,10 @@ class TestGallery(unittest.TestCase):
def test_filelist(self):
paths = self.gal.paths
self.assertItemsEqual(paths.keys(), ['.', 'dir1', 'dir2', 'dir1/test'])
self.assertItemsEqual(paths.keys(),
['paths_list', '.', 'dir1', 'dir2', 'dir1/test'])
self.assertListEqual(paths['paths_list'],
['.', 'dir1', 'dir1/test', 'dir2'])
self.assertListEqual(paths['.']['img'], [])
self.assertItemsEqual(paths['.']['subdir'], ['dir1', 'dir2'])