Mercurial > piecrust2
annotate piecrust/osutil.py @ 535:03c3a77fda60 2.0.0b2
prepare: More help about scaffolding.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 29 Jul 2015 09:13:54 -0700 |
parents | 6f1f45fb7790 |
children | 6ef89b31ddda |
rev | line source |
---|---|
526
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import os |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import sys |
527
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
3 import glob as _system_glob |
526
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 import unicodedata |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
527
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
7 walk = os.walk |
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
8 listdir = os.listdir |
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
9 glob = _system_glob.glob |
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
10 |
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
11 |
526
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 if sys.platform == 'darwin': |
527
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
13 def _walk(top, **kwargs): |
526
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 for dirpath, dirnames, filenames in os.walk(top, **kwargs): |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 dirpath = _from_osx_fs(dirpath) |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 dirnames = list(map(_from_osx_fs, dirnames)) |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 filenames = list(map(_from_osx_fs, filenames)) |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 yield dirpath, dirnames, filenames |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 |
527
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
20 def _listdir(path='.'): |
526
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 for name in os.listdir(path): |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 name = _from_osx_fs(name) |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 yield name |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 |
527
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
25 def _glob(pathname): |
526
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 pathname = _to_osx_fs(pathname) |
529
6f1f45fb7790
cm: Re-fix Mac file-system wrappers.
Ludovic Chabant <ludovic@chabant.com>
parents:
527
diff
changeset
|
27 matches = _system_glob.glob(pathname) |
526
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 return list(map(_from_osx_fs, matches)) |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 def _from_osx_fs(s): |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 return unicodedata.normalize('NFC', s) |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 def _to_osx_fs(s): |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 return unicodedata.ucd_3_2_0.normalize('NFD', s) |
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 |
529
6f1f45fb7790
cm: Re-fix Mac file-system wrappers.
Ludovic Chabant <ludovic@chabant.com>
parents:
527
diff
changeset
|
36 global walk, listdir, glob |
6f1f45fb7790
cm: Re-fix Mac file-system wrappers.
Ludovic Chabant <ludovic@chabant.com>
parents:
527
diff
changeset
|
37 |
527
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
38 walk = _walk |
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
39 listdir = _listdir |
fa9eb8f866cd
bug: Fix file-system wrappers for non-Mac systems.
Ludovic Chabant <ludovic@chabant.com>
parents:
526
diff
changeset
|
40 glob = _glob |
526
9b8b47fb1068
bug: Forgot to add a new file like a big n00b.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
41 |