Пример #1
0
def get_files(config):
    """ Walk the `source_dir` and return a Files collection. """
    files = []
    exclude = ['.*', '/templates']

    for source_dir, dirnames, filenames in os.walk(config['source_dir'],
                                                   followlinks=True):
        relative_dir = os.path.relpath(source_dir, config['source_dir'])
        for dirname in list(dirnames):
            path = os.path.normpath(os.path.join(relative_dir, dirname))
            # Skip any excluded directories
            if _filter_paths(basename=dirname,
                             path=path,
                             is_dir=True,
                             exclude=exclude):
                dirnames.remove(dirname)
        dirnames.sort()

        for filename in _sort_files(filenames):
            path = os.path.normpath(os.path.join(relative_dir, filename))
            # Skip any excluded files
            if _filter_paths(basename=filename,
                             path=path,
                             is_dir=False,
                             exclude=exclude):
                continue
            # Skip README.md is an index file also exists in dir
            if filename.lower() == 'readme.md' and 'index.md' in filenames:
                continue
            files.append(
                File(path, config['source_dir'], config['site_dir'],
                     config['use_directory_urls']))

    return Files(files)
Пример #2
0
    def test_sort_files(self):
        self.assertEqual(
            _sort_files(['b.md', 'bb.md', 'a.md', 'index.md', 'aa.md']),
            ['index.md', 'a.md', 'aa.md', 'b.md', 'bb.md'])

        self.assertEqual(
            _sort_files(['b.md', 'index.html', 'a.md', 'index.md']),
            ['index.html', 'index.md', 'a.md', 'b.md'])

        self.assertEqual(
            _sort_files(['a.md', 'index.md', 'b.md', 'index.html']),
            ['index.md', 'index.html', 'a.md', 'b.md'])

        self.assertEqual(
            _sort_files(['.md', '_.md', 'a.md', 'index.md', '1.md']),
            ['index.md', '.md', '1.md', '_.md', 'a.md'])

        self.assertEqual(_sort_files(['a.md', 'b.md', 'a.md']),
                         ['a.md', 'a.md', 'b.md'])
Пример #3
0
    def test_sort_files(self):
        self.assertEqual(
            _sort_files(['b.md', 'bb.md', 'a.md', 'index.md', 'aa.md']),
            ['index.md', 'a.md', 'aa.md', 'b.md', 'bb.md']
        )

        self.assertEqual(
            _sort_files(['b.md', 'index.html', 'a.md', 'index.md']),
            ['index.html', 'index.md', 'a.md', 'b.md']
        )

        self.assertEqual(
            _sort_files(['a.md', 'index.md', 'b.md', 'index.html']),
            ['index.md', 'index.html', 'a.md', 'b.md']
        )

        self.assertEqual(
            _sort_files(['.md', '_.md', 'a.md', 'index.md', '1.md']),
            ['index.md', '.md', '1.md', '_.md', 'a.md']
        )

        self.assertEqual(
            _sort_files(['a.md', 'b.md', 'a.md']),
            ['a.md', 'a.md', 'b.md']
        )

        self.assertEqual(
            _sort_files(['A.md', 'B.md', 'README.md']),
            ['README.md', 'A.md', 'B.md']
        )
Пример #4
0
def get_files(base_dir, config, site):
    files = []
    exclude = ['.*', '/templates']

    base = os.path.relpath(base_dir, config['docs_dir'])
    for source_dir, dirnames, filenames in os.walk(base_dir, followlinks=True):
        relative_dir = os.path.relpath(source_dir, config['docs_dir'])

        for dirname in list(dirnames):
            path = os.path.normpath(os.path.join(relative_dir, dirname))
            # Skip any excluded directories
            if _filter_paths(basename=dirname,
                             path=path,
                             is_dir=True,
                             exclude=exclude):
                dirnames.remove(dirname)
        dirnames.sort()

        for filename in _sort_files(filenames):
            path = os.path.normpath(os.path.join(relative_dir, filename))
            # Skip any excluded files
            if _filter_paths(basename=filename,
                             path=path,
                             is_dir=False,
                             exclude=exclude):
                continue
            f = File(path, config['docs_dir'], config['site_dir'],
                     config['use_directory_urls'])
            f.dest_path = f.dest_path.replace(base + '/', '')
            f.abs_dest_path = os.path.normpath(
                os.path.join(config['site_dir'], f.dest_path))
            f.url = f.url.replace(base + '/', '')
            if f.url == '':
                # Skip docs/index.md, use the one from root repo
                continue
            files.append(f)

    return (files, {file.src_path: file for file in files})