Changeset 749

Show
Ignore:
Timestamp:
07/16/07 21:13:29 (1 year ago)
Author:
robin
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • commando/trunk/commandolite.py

    r748 r749  
    244244    return out 
    245245 
    246  
    247 def find_top_packages(where='.'): 
     246def evaluate_packagedir(path, name=''): 
     247    if (isdir(path) and '.' not in name and ( 
     248        isfile(join(path, '__init__.py')) or 
     249        isfile(join(path, '__init__.pyc')) or 
     250        isfile(join(path, '__init__.pyo'))) 
     251        ): 
     252        return name or dirname(path) 
     253    return False 
     254 
     255 
     256def find_top_packages(where='.', evaluate_packagelocation=evaluate_packagedir): 
     257    """Find all directories under `where` which contain an __init__.py""" 
     258 
    248259    tops={} 
    249260    out = [] 
     
    253264        for name in os.listdir(where): 
    254265            fn = join(where,name) 
    255             if isdir(fn): 
    256                 if ('.' not in name and isfile(join(fn,'__init__.py'))): 
    257                     tops.setdefault(where, {})[name]=fn 
    258                 else: 
    259                     stack.append(fn) 
    260     return tops 
     266            result = evaluate_packagelocation(fn, name=name) 
     267            if result: 
     268                tops.setdefault(where, []).append(result) 
     269            if isdir(fn) and not result: 
     270                stack.append(fn) 
     271 
     272    return sorted(tops.items()) 
     273 
    261274 
    262275#----------------------------------------------------------------------------- 
  • commando/trunk/tests/test_pathdiscovery.py

    r748 r749  
    2424    #print commandolite.path_moduleinfo(sys.argv[1]) 
    2525    #print commandolite.find_packages(sys.argv[1]) 
    26     print commandolite.find_top_packages(sys.argv[1]
     26    print commandolite.find_top_packages(commandolite.abs_normpath(sys.argv[1])
    2727 
    2828