nest = Nest() bn = os.path.basename # Start by mirroring the two directory levels in startersdir, and name those # directories "ethnicity" and "dietary". nest.add('ethnicity', glob.glob(os.path.join(startersdir, '*')), label_func=bn) # In the `dietary` key, the anonymous function `lambda ...` chooses as values # names of directories the current `ethnicity` directory nest.add('dietary', lambda c: glob.glob(os.path.join(c['ethnicity'], '*')), label_func=bn) ## Now get all of the starters. nest.add('starter', lambda c: glob.glob(os.path.join(c['dietary'], '*')), label_func=stripext) ## Then get the corresponding mains. nest.add('main', lambda c: [os.path.join(mainsdir, bn(c['ethnicity']) + "_stirfry.txt")], label_func=stripext) ## Take only the tasty wines. nest.add('wine', glob.glob(os.path.join(winedir, '*.tasty')), label_func=stripext) ## The wineglasses should be chosen by the wine choice, but we don't want to ## make a directory for those. nest.add('wineglass', lambda c: [stripext(c['wine']) + ' wine glasses'], create_dir=False) nest.build('runs')