"""$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/traversal.py $
$Id: traversal.py 25714 2004-12-07 23:31:55Z rmasse $
"""

from quixote import enable_ptl
enable_ptl()
from sets import Set as set
from quixote.directory import Directory
from dulcinea.site_util import get_root_directory

def check_exports():
    todo = set([get_root_directory()])
    seen = set()
    while todo:
        directory = todo.pop()
        seen.add(directory)
        exports = getattr(directory, '_q_exports', None)
        index = getattr(directory, '_q_index', None)
        resolve = getattr(directory, '_q_resolve', None)
        if exports is None:
            print directory, 'has no _q_exports'
        elif '' in exports and index is None:
            print directory, 'has "" in _q_exports, but no _q_index()'
        elif '' not in exports and index is not None:
            print directory, 'has a _q_index(), but "" is not in _q_exports'
        if resolve is None:
            for name in exports or []:
                if type(name) is tuple:
                    name = name[1]
                value = getattr(directory, name, None)
                if name and value is None:
                    print directory, (
                        'has %r in _q_exports, but no %r attribute.' % (
                        (name, name)))
                if isinstance(value, Directory) and value not in seen:
                    todo.add(value)
