def get_data_files(path=None, patterns=None, exclude_files=None): """ Procesess a list of patterns to get a list of files that should be put in a directory. This function helps the Tribus Maintainer to define a list of files to be installed in a certain system directory. For example, generated documentation (everything under ``tribus/data/docs/html`` after executing ``make build_sphinx``) should be put in ``/usr/share/doc/tribus/``. The maintainer should add a pattern like the following so that everything from ``tribus/data/docs/html`` gets copied to ``/usr/share/doc/tribus/`` when the package is installed (``python setup.py install``) or a binary distribution is created (``python setup.py bdist``). :param path: the path where the files reside. Generally the top level directory of the project. Patterns will be expanded in this directory. :param patterns: this is a list of strings in the form of:: ['relative/path/inside/project *.some.*regex* /dest', 'another/path/inside/project *.foo.*regex* /dest2', 'path/ *.* dest/'] which means, *Put every file from this folder matching the regex inside this other folder*. :param exclude_files: this is a list of file patterns to exclude from the results. :return: a list of pairs ``('directory', [file-list])`` ready for use in ``setup(data_files=...)`` from Setuptools/Distutils. :rtype: ``list`` .. versionadded:: 0.1 """ assert path is not None assert patterns is not None path = os.path.normpath(path) d = [] for l in patterns: src, rgx, dest = l.split() for subdir in find_dirs(path=get_path([path, src])): f = [] for files in list_files(path=subdir): f.append(files) for exclude in exclude_files: if fnmatch.fnmatch(files, exclude) and files in f: f.remove(files) d.append((dest + subdir.replace(os.path.join(path, src), ''), f)) return d
def get_sphinx_pot_list(self): return filter(None, list_files(get_path([DOCDIR, 'rst', 'i18n', 'pot'])))
def test_list_files_is_file(self): from tribus.common.utils import list_files self.assertTrue(os.path.isfile( sorted(list_files(path=self.tmpdir))[1]))
def test_list_files(self): from tribus.common.utils import list_files self.assertEqual(sorted(list_files(path=self.tmpdir)), sorted(['/tmp/test_io/5.log', '/tmp/test_io/6.py']))