view piecrust/osutil.py @ 853:f070a4fc033c

core: Continue PieCrust3 refactor, simplify pages. The asset pipeline is still the only function pipeline at this point. * No more `QualifiedPage`, and several other pieces of code deleted. * Data providers are simpler and more focused. For instance, the page iterator doesn't try to support other types of items. * Route parameters are proper known source metadata to remove the confusion between the two. * Make the baker and pipeline more correctly manage records and record histories. * Add support for record collapsing and deleting stale outputs in the asset pipeline.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 21 May 2017 00:06:59 -0700
parents a4ac464a45b3
children ea6cbd6d2af5
line wrap: on
line source

import os
import sys
import glob as _system_glob
import unicodedata


walk = os.walk
listdir = os.listdir
glob = _system_glob.glob


def _wrap_fs_funcs():
    global walk
    global listdir
    global glob

    def _walk(top, **kwargs):
        for dirpath, dirnames, filenames in os.walk(top, **kwargs):
            dirpath = _from_osx_fs(dirpath)
            dirnames[:] = list(map(_from_osx_fs, dirnames))
            filenames[:] = list(map(_from_osx_fs, filenames))
            yield dirpath, dirnames, filenames

    def _listdir(path='.'):
        for name in os.listdir(path):
            name = _from_osx_fs(name)
            yield name

    def _glob(pathname):
        pathname = _to_osx_fs(pathname)
        matches = _system_glob.glob(pathname)
        return list(map(_from_osx_fs, matches))

    def _from_osx_fs(s):
        return unicodedata.normalize('NFC', s)

    def _to_osx_fs(s):
        return unicodedata.ucd_3_2_0.normalize('NFD', s)

    walk = _walk
    listdir = _listdir
    glob = _glob


if sys.platform == 'darwin':
    _wrap_fs_funcs()