I ran into a little issue recently.
I got a callback on some code that should have worked, and it only took
me a few minutes to determine why.

The code, _get_available_versions in pygtk.py needs to be a bit more
careful:

The current code:

def _get_available_versions():
    versions = {}
    for dir in sys.path:
        if not dir: dir = os.getcwd()
        if _pygtk_dir_pat.match(os.path.basename(dir)):
            continue  # if the dir is a pygtk dir, skip it
        for filename in os.listdir(dir):
            pathname = os.path.join(dir, filename)
            if not os.path.isdir(pathname):
                continue  # skip non directories
            match = _pygtk_dir_pat.match(filename)
            if match and not versions.has_key(match.group(1)):
                versions[match.group(1)] = pathname
    return versions


====

The problem is that not all items in sys.path may exist (or, I suppose,
be directories).

Thusly, the os.listdir fails with a callback.  D'Oh!

Perhaps (with the appropriate imports added), and new code indicated:

def _get_available_versions():
    versions = {}
    for dir in sys.path:
        if not dir: dir = os.getcwd()
        if _pygtk_dir_pat.match(os.path.basename(dir)):
            continue  # if the dir is a pygtk dir, skip it
        # ***************
        # is dir a dir?
        try:
            s = os.stat(dir)
        except:
            continue
        if stat.S_ISDIR(s[stat.ST_MODE]) != 1:
            continue
        # ***************
        for filename in os.listdir(dir):
            pathname = os.path.join(dir, filename)
            if not os.path.isdir(pathname):
                continue  # skip non directories
            match = _pygtk_dir_pat.match(filename)
            if match and not versions.has_key(match.group(1)):
                versions[match.group(1)] = pathname
    return versions



--
Feast your Vulcan squinties on that!

Jon Nelson <[EMAIL PROTECTED]>
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to