Changeset 612

Show
Ignore:
Timestamp:
07/10/03 16:46:57 (5 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBFoundation/RBFoundation/Utilities.py

    r605 r612  
    5757 
    5858def flatten(collection, level=1): 
    59     if isIterable(collection): 
     59    if isinstance(collection, (list, tuple)): 
    6060        if level: 
    6161            return [each for item in collection for each in flatten(item, level-1)] 
  • trunk/RBFoundation/RBFoundation/XMLBuilder.py

    r576 r612  
    245245        """Creates the Expat parser in a python-OO way.""" 
    246246        parser = _ExpatParserCreate(self._encoding, self._seperator) 
     247        try:  
     248            #if using python 2.3 or above, the buffer text should speed things up 
     249            parser.buffer_text = True 
     250        except AttributeError:  
     251            # Otherwise, ignore the set attribute error 
     252            pass 
     253 
    247254        parser.returns_unicode = self._encoding != 'ASCII' and 1 or 0 
    248255        parser.StartElementHandler = WeakBindCallable(self._start_element) 
  • trunk/RBFoundation/RBFoundation/_InstallerHookUtilities.py

    r291 r612  
    2020##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2121 
     22""" 
     23Requires path.py from: 
     24    Jason Orendorff <jason@jorendorff.com> (and others - see the url!) 
     25    http://www.jorendorff.com/articles/python/path 
     26""" 
     27 
    2228#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2329#~ Imports  
     
    2531 
    2632import os 
     33try: 
     34    from path import path 
     35except ImportError, e: 
     36    print """Requires path.py from: 
     37        Jason Orendorff <jason@jorendorff.com> (and others - see the url!) 
     38        http://www.jorendorff.com/articles/python/path 
     39    """ 
     40    raise 
    2741 
    2842#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    3044#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3145 
    32 def MakePackageHook(Package, RootPackageName='Foundation', packageTypes=('.py','.pyw','.pyc','.pyo','.pyd')): 
    33     def MakeHooks(modules, dirname, dircontent): 
    34         prefix, package, packages = dirname, None, [] 
    35         while prefix and package != RootPackageName: 
    36             prefix, package = os.path.split(prefix) 
    37             assert package 
    38             packages.append(package) 
    39         packages.reverse() 
     46def MakePackageHook(Package, recurse=True, includefiletypes=('*.py','*.pyw','*.pyc','*.pyo','*.pyd'), excludedirs=('CVS',)): 
     47    def GetPyModules(packagedir): 
     48        modules = {} 
     49        for filetype in includefiletypes: 
     50            for filename in packagedir.walkfiles(filetype ): 
     51                modules[filename.splitext()[0].name] = True 
    4052 
    41         for name in dircontent: 
    42             idx = name.rfind('.py') 
    43             name, ext = name[:idx], name[idx:] 
     53        if recurse: 
     54            for dirname in packagedir.walkdirs(): 
     55                if dirname not in excludedirs: 
     56                    for result in GetPyModules(dirname): 
     57                        modules['%s.%s'%(dirname.name, result)] = True 
     58        return modules.keys() 
    4459 
    45             if ext in packageTypes: 
    46                 if name not in {'__init__':1}: 
    47                     modulename = '.'.join(packages + [name]) 
    48                 else: modulename = '.'.join(packages) 
    49                 modules[modulename] = 1 
    50  
     60    packagedir = path(Package.__file__).splitpath()[0] 
    5161    modules = {} 
    52     walkdir = os.path.split(Package.__file__)[0] 
    53     os.path.walk(walkdir, MakeHooks, modules) 
     62    for result in GetPyModules(packagedir): 
     63        modules['%s.%s'%(Package.__name__, result)] = True 
    5464    return modules.keys() 
    5565