comparison piecrust/osutil.py @ 527:fa9eb8f866cd

bug: Fix file-system wrappers for non-Mac systems.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 28 Jul 2015 21:50:57 -0700
parents 9b8b47fb1068
children 6f1f45fb7790
comparison
equal deleted inserted replaced
526:9b8b47fb1068 527:fa9eb8f866cd
1 import os 1 import os
2 import sys 2 import sys
3 import glob as _glob 3 import glob as _system_glob
4 import unicodedata 4 import unicodedata
5 5
6 6
7 walk = os.walk
8 listdir = os.listdir
9 glob = _system_glob.glob
10
11
7 if sys.platform == 'darwin': 12 if sys.platform == 'darwin':
8 def walk(top, **kwargs): 13 def _walk(top, **kwargs):
9 for dirpath, dirnames, filenames in os.walk(top, **kwargs): 14 for dirpath, dirnames, filenames in os.walk(top, **kwargs):
10 dirpath = _from_osx_fs(dirpath) 15 dirpath = _from_osx_fs(dirpath)
11 dirnames = list(map(_from_osx_fs, dirnames)) 16 dirnames = list(map(_from_osx_fs, dirnames))
12 filenames = list(map(_from_osx_fs, filenames)) 17 filenames = list(map(_from_osx_fs, filenames))
13 yield dirpath, dirnames, filenames 18 yield dirpath, dirnames, filenames
14 19
15 def listdir(path='.'): 20 def _listdir(path='.'):
16 for name in os.listdir(path): 21 for name in os.listdir(path):
17 name = _from_osx_fs(name) 22 name = _from_osx_fs(name)
18 yield name 23 yield name
19 24
20 def glob(pathname): 25 def _glob(pathname):
21 pathname = _to_osx_fs(pathname) 26 pathname = _to_osx_fs(pathname)
22 matches = _glob.glob(pathname) 27 matches = _glob.glob(pathname)
23 return list(map(_from_osx_fs, matches)) 28 return list(map(_from_osx_fs, matches))
24 29
25 def _from_osx_fs(s): 30 def _from_osx_fs(s):
26 return unicodedata.normalize('NFC', s) 31 return unicodedata.normalize('NFC', s)
27 32
28 def _to_osx_fs(s): 33 def _to_osx_fs(s):
29 return unicodedata.ucd_3_2_0.normalize('NFD', s) 34 return unicodedata.ucd_3_2_0.normalize('NFD', s)
30 35
31 else: 36 walk = _walk
32 walk = sys.walk 37 listdir = _listdir
33 listdir = sys.listdir 38 glob = _glob
34 glob = _glob.glob
35 39