Mercurial > piecrust2
diff piecrust/osutil.py @ 526:9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 28 Jul 2015 21:36:59 -0700 |
parents | |
children | fa9eb8f866cd |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/piecrust/osutil.py Tue Jul 28 21:36:59 2015 -0700 @@ -0,0 +1,35 @@ +import os +import sys +import glob as _glob +import unicodedata + + +if sys.platform == 'darwin': + 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 = _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) + +else: + walk = sys.walk + listdir = sys.listdir + glob = _glob.glob +