Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(4)  |  Call(2)  |  Derive(0)  |  Import(2)
Find a file in one of several relative locations

Arguments:

  prefix -- The location, relative to some home, to look for the
            file

  name -- The name of the file.  This must not be a path.

  checkProduct -- a flag indicating whether product directories(more...)

        def getPath(prefix, name, checkProduct=1, suffixes=('',), cfg=None):
    """Find a file in one of several relative locations

    Arguments:

      prefix -- The location, relative to some home, to look for the
                file

      name -- The name of the file.  This must not be a path.

      checkProduct -- a flag indicating whether product directories
        should be used as additional hope ares to be searched. This
        defaults to a true value.

        If this is true and the name contains a dot, then the
        text before the dot is treated as a product name and
        the product package directory is used as anothe rhome.

      suffixes -- a sequences of file suffixes to check.
        By default, the name is used without a suffix.

      cfg -- ease testing (not part of the API)

    The search takes on multiple homes which are the instance home,
    the directory containing the directory containing the software
    home, and possibly product areas.
    """
    dir, ignored = os.path.split(name)
    if dir:
        raise ValueError('The file name, %s, should be a simple file name'
                            % name)

    result = None
    if checkProduct:
        dot = name.find('.')
        if dot > 0:
            product = name[:dot]
            extname = name[dot + 1:]
            for product_dir in Products.__path__:
                found = _getPath(product_dir, os.path.join(product, prefix),
                                 extname, suffixes)
                if found is not None:
                    return found

    if cfg is None:
        import App.config
        cfg = App.config.getConfiguration()

    if prefix == "Extensions" and getattr(cfg, 'extensions', None) is not None:
        found = _getPath(cfg.extensions, '', name, suffixes)
        if found is not None:
            return found

    locations = [cfg.instancehome]

    softwarehome = getattr(cfg, 'softwarehome', None)
    if softwarehome is not None:
        zopehome = os.path.dirname(softwarehome)
        locations.append(zopehome)

    for home in locations:
        found = _getPath(home, prefix, name, suffixes)
        if found is not None:
            return found

    try:
        dot = name.rfind('.')
        if dot > 0:
            realName = name[dot+1:]
            toplevel = name[:dot]
            
            rdot = toplevel.rfind('.')
            if rdot > -1:
                module = __import__(toplevel, globals(), {}, toplevel[rdot+1:])
            else:
                module = __import__(toplevel)
    
            prefix = os.path.join(module.__path__[0], prefix, realName)
            
            for suffix in suffixes:
                if suffix:
                    fn = "%s.%s" % (prefix, suffix)
                else:
                    fn = prefix
                if os.path.exists(fn): 
                    return fn
    except:
        pass
        


src/p/r/Products.ExternalMethod-2.13.0/src/Products/ExternalMethod/ExternalMethod.py   Products.ExternalMethod(Download)
from Acquisition import Explicit
from App.Extensions import getObject
from App.Extensions import getPath
from App.Extensions import FuncCode
from App.special_dtml import DTMLFile
    def filepath(self):
        if not hasattr(self, '_v_filepath'):
            self._v_filepath=getPath('Extensions', self._module,
                                     suffixes=('', 'py', 'pyc', 'pyp'))
        return self._v_filepath

src/z/o/Zope2-2.13.22/src/App/tests/test_Extensions.py   Zope2(Download)
    def _callFUT(self, prefix, name, checkProduct=1, suffixes=('',), cfg=None):
        from App.Extensions import getPath
        return getPath(prefix, name, checkProduct, suffixes, cfg)
 
    def _makeConfig(self, **kw):