Browse Source

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

process subdirectories before their parent (fix #6).
pull/9/merge
Simon 13 years ago
parent
commit
3c7d6449d2
  1. 8
      sigal/gallery.py
  2. 5
      tests/test_gallery.py

8
sigal/gallery.py

@ -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']]

5
tests/test_gallery.py

@ -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'])

Loading…
Cancel
Save