def testMultiFind(self):
     normalize = lambda f: (os.path.basename(f), get_level(f))
     with scenario(a=(0, 1, 2), b=(0, 1, 2), c=(1,), d=(0, 2), e=()) as dirs:
         self.assertEqual(
                 [('a', 0), ('a', 1), ('a', 2)],
                 [normalize(r) for r in util.find_files(('a', 'b'), dirs)])
         self.assertEqual(
                 [('b', 0), ('b', 1), ('b', 2)],
                 [normalize(r) for r in util.find_files(('b', 'a'), dirs)])
         self.assertEqual(
                 [('a', 0), ('c', 1), ('a', 2)],
                 [normalize(r) for r in util.find_files(('c', 'a'), dirs)])
         self.assertEqual(
                 [('d', 0), ('c', 1), ('d', 2)],
                 [normalize(r) for r in util.find_files(('e', 'd', 'c', 'a', 'b'), dirs)])
 def testMultiFind(self):
     normalize = lambda f: (os.path.basename(f), get_level(f))
     with scenario(a=(0, 1, 2), b=(0, 1, 2), c=(1, ), d=(0, 2),
                   e=()) as dirs:
         self.assertEqual(
             [('a', 0), ('a', 1), ('a', 2)],
             [normalize(r) for r in util.find_files(('a', 'b'), dirs)])
         self.assertEqual(
             [('b', 0), ('b', 1), ('b', 2)],
             [normalize(r) for r in util.find_files(('b', 'a'), dirs)])
         self.assertEqual(
             [('a', 0), ('c', 1), ('a', 2)],
             [normalize(r) for r in util.find_files(('c', 'a'), dirs)])
         self.assertEqual([('d', 0), ('c', 1), ('d', 2)], [
             normalize(r)
             for r in util.find_files(('e', 'd', 'c', 'a', 'b'), dirs)
         ])
 def testSingleFindOneMatch(self):
     with scenario(**{
             'a.txt': (0, 1, 2),
             'b.foo': (1, 2),
             'c.bar': (2, )
     }) as dirs:
         for name, level in {'a.txt': 0, 'b.foo': 1, 'c.bar': 2}.items():
             result = tuple(util.find_files(name, dirs, matches=1))
             self.assertEqual(1, len(result))
             self.assertEqual(level, get_level(result[0]))
 def testSingleFindMultiMatch(self):
     mapping = {
         '0.x': (0, ),
         'a.txt': (0, 1),
         'b.blah': (0, 1, 2),
         'c.pork': (1, 2),
         'd.plonk': (1, ),
         'e.sporks': (2, )
     }
     with scenario(**mapping) as dirs:
         for name, levels in mapping.items():
             got = tuple(get_level(r) for r in util.find_files(name, dirs))
             self.assertEqual(levels, got)
Esempio n. 5
0
def find_logging_configuration():
    """Returns the path to the logging configuration file.

    Searches the SEARCH_PATHS for a file of basename LOGGING_CONFIG_BASENAME.
    Customize these in your `Mandrel.py` bootstrap file to exercise control
    over this.

    Returns the first match found.

    Raises an UnknownConfigurationException if no config file is found.
    """
    for path in util.find_files(LOGGING_CONFIG_BASENAME, SEARCH_PATHS, matches=1):
        return path
    raise exception.UnknownConfigurationException, "Cannot find logging configuration file(s) '%s'" % LOGGING_CONFIG_BASENAME
Esempio n. 6
0
def find_logging_configuration():
    """Returns the path to the logging configuration file.

    Searches the SEARCH_PATHS for a file of basename LOGGING_CONFIG_BASENAME.
    Customize these in your `Mandrel.py` bootstrap file to exercise control
    over this.

    Returns the first match found.

    Raises an UnknownConfigurationException if no config file is found.
    """
    for path in util.find_files(LOGGING_CONFIG_BASENAME,
                                SEARCH_PATHS,
                                matches=1):
        return path
    raise exception.UnknownConfigurationException, "Cannot find logging configuration file(s) '%s'" % LOGGING_CONFIG_BASENAME
Esempio n. 7
0
def find_configuration_files(name):
    """Finds readable configuration files across config.bootstrap.SEARCH_PATHS for name.

    Using get_possible_basenames() to determine possible file basenames for name,
    looks across directories in config.bootstrap.SEARCH_PATHS and yields each
    highest-priority (according to extension order in LOADERS) existing config file
    within SEARCH_PATHS.

    Parameters:
        name: a string representing a configuration file basename, typically
            without an extension.

    Yields each existing best match across directories in SEARCH_PATHS.  The yielded paths
    are full, absolute paths.
    """
    return util.find_files(get_possible_basenames(name), _get_bootstrapper().SEARCH_PATHS)
 def testSingleFindTwoMatch(self):
     with scenario(**{
             '0.x': (0, ),
             'a.txt': (0, 1, 2),
             'b.foo': (1, 2),
             'c.bar': (2, )
     }) as dirs:
         for name, levels in {
                 '0.x': (0, ),
                 'a.txt': (0, 1),
                 'b.foo': (1, 2),
                 'c.bar': (2, )
         }.items():
             got = tuple(
                 get_level(r)
                 for r in util.find_files(name, dirs, matches=2))
             self.assertEqual(levels, got)
Esempio n. 9
0
def find_configuration_files(name):
    """Finds readable configuration files across config.bootstrap.SEARCH_PATHS for name.

    Using get_possible_basenames() to determine possible file basenames for name,
    looks across directories in config.bootstrap.SEARCH_PATHS and yields each
    highest-priority (according to extension order in LOADERS) existing config file
    within SEARCH_PATHS.

    Parameters:
        name: a string representing a configuration file basename, typically
            without an extension.

    Yields each existing best match across directories in SEARCH_PATHS.  The yielded paths
    are full, absolute paths.
    """
    return util.find_files(get_possible_basenames(name),
                           _get_bootstrapper().SEARCH_PATHS)
 def testSingleFindMultiMatch(self):
     mapping = {'0.x': (0,), 'a.txt': (0, 1), 'b.blah': (0, 1, 2), 'c.pork': (1, 2), 'd.plonk': (1,), 'e.sporks': (2,)}
     with scenario(**mapping) as dirs:
         for name, levels in mapping.items():
             got = tuple(get_level(r) for r in util.find_files(name, dirs))
             self.assertEqual(levels, got)
 def testSingleFindTwoMatch(self):
     with scenario(**{'0.x': (0,), 'a.txt': (0, 1, 2), 'b.foo': (1, 2), 'c.bar': (2,)}) as dirs:
         for name, levels in {'0.x': (0,), 'a.txt': (0, 1), 'b.foo': (1, 2), 'c.bar': (2,)}.items():
             got = tuple(get_level(r) for r in util.find_files(name, dirs, matches=2))
             self.assertEqual(levels, got)
 def testSingleFindOneMatch(self):
     with scenario(**{'a.txt': (0, 1, 2), 'b.foo': (1, 2), 'c.bar': (2,)}) as dirs:
         for name, level in {'a.txt': 0, 'b.foo': 1, 'c.bar': 2}.items():
             result = tuple(util.find_files(name, dirs, matches=1))
             self.assertEqual(1, len(result))
             self.assertEqual(level, get_level(result[0]))