示例#1
0
def walk_resources(package_or_requirement,
                   resource_name,
                   recurse=True,
                   base=''):
    """ Yield paths of files in the given resource directory, all paths start with '/'.
    """
    base = base.rstrip('/') + '/'
    resource_base = (resource_name.rstrip('/') + '/' +
                     base.strip('/')).rstrip('/')

    # Create default configuration files
    for filename in pymagic.resource_listdir(package_or_requirement,
                                             resource_base):
        # Skip hidden and other trashy names
        if filename.startswith('.') or any(
                filename.endswith(i) for i in (".pyc", ".pyo", "~")):
            continue

        # Handle subdirectories
        if pymagic.resource_isdir(package_or_requirement,
                                  resource_base + '/' + filename):
            if recurse:
                for i in walk_resources(package_or_requirement,
                                        resource_name,
                                        recurse,
                                        base=base + filename):
                    yield i
        else:
            yield base + filename
示例#2
0
def load_plugin_classes():
    """ From all modules in this package, load a dict of the plugin classes.
    """
    plugins = {}
    modules = set(os.path.splitext(module_file)[0]
        for module_file in pymagic.resource_listdir(__name__, '')
        if not module_file.startswith('_') and module_file.endswith(".py")
    )
    
    for module in modules:
        for name, obj in vars(pymagic.import_name(__name__, module)).items():
            if isinstance(obj, type) and issubclass(obj, plugin.Plugin) and not name.endswith("PluginBase"):
                plugins[name] = obj

    return plugins
示例#3
0
def walk_resources(package_or_requirement, resource_name, recurse=True, base=''):
    """ Yield paths of files in the given resource directory, all paths start with '/'.
    """
    base = base.rstrip('/') + '/' 
    resource_base = (resource_name.rstrip('/') + '/' + base.strip('/')).rstrip('/')
    
    # Create default configuration files
    for filename in pymagic.resource_listdir(package_or_requirement, resource_base):
        # Skip hidden and other trashy names
        if filename.startswith('.') or any(filename.endswith(i) for i in (".pyc", ".pyo", "~")):
            continue

        # Handle subdirectories
        if pymagic.resource_isdir(package_or_requirement, resource_base + '/' + filename):
            if recurse:
                for i in walk_resources(package_or_requirement, resource_name, recurse, base=base + filename):
                    yield i
        else:
            yield base + filename