Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
525:4a26f3dfb92b | 526:9b8b47fb1068 |
---|---|
1 import os | |
2 import sys | |
3 import glob as _glob | |
4 import unicodedata | |
5 | |
6 | |
7 if sys.platform == 'darwin': | |
8 def walk(top, **kwargs): | |
9 for dirpath, dirnames, filenames in os.walk(top, **kwargs): | |
10 dirpath = _from_osx_fs(dirpath) | |
11 dirnames = list(map(_from_osx_fs, dirnames)) | |
12 filenames = list(map(_from_osx_fs, filenames)) | |
13 yield dirpath, dirnames, filenames | |
14 | |
15 def listdir(path='.'): | |
16 for name in os.listdir(path): | |
17 name = _from_osx_fs(name) | |
18 yield name | |
19 | |
20 def glob(pathname): | |
21 pathname = _to_osx_fs(pathname) | |
22 matches = _glob.glob(pathname) | |
23 return list(map(_from_osx_fs, matches)) | |
24 | |
25 def _from_osx_fs(s): | |
26 return unicodedata.normalize('NFC', s) | |
27 | |
28 def _to_osx_fs(s): | |
29 return unicodedata.ucd_3_2_0.normalize('NFD', s) | |
30 | |
31 else: | |
32 walk = sys.walk | |
33 listdir = sys.listdir | |
34 glob = _glob.glob | |
35 |