Mercurial > hg > mercurial-source
comparison mercurial/pure/osutil.py @ 7704:30d1d313370b
move mercurial.osutil to mercurial.pure.osutil
author | Martin Geisler <mg@daimi.au.dk> |
---|---|
date | Sat, 24 Jan 2009 00:13:49 +0100 |
parents | |
children | 823f25b25dea |
comparison
equal
deleted
inserted
replaced
7703:9044d3567f6d | 7704:30d1d313370b |
---|---|
1 import os | |
2 import stat as _stat | |
3 | |
4 def _mode_to_kind(mode): | |
5 if _stat.S_ISREG(mode): return _stat.S_IFREG | |
6 if _stat.S_ISDIR(mode): return _stat.S_IFDIR | |
7 if _stat.S_ISLNK(mode): return _stat.S_IFLNK | |
8 if _stat.S_ISBLK(mode): return _stat.S_IFBLK | |
9 if _stat.S_ISCHR(mode): return _stat.S_IFCHR | |
10 if _stat.S_ISFIFO(mode): return _stat.S_IFIFO | |
11 if _stat.S_ISSOCK(mode): return _stat.S_IFSOCK | |
12 return mode | |
13 | |
14 def listdir(path, stat=False, skip=None): | |
15 '''listdir(path, stat=False) -> list_of_tuples | |
16 | |
17 Return a sorted list containing information about the entries | |
18 in the directory. | |
19 | |
20 If stat is True, each element is a 3-tuple: | |
21 | |
22 (name, type, stat object) | |
23 | |
24 Otherwise, each element is a 2-tuple: | |
25 | |
26 (name, type) | |
27 ''' | |
28 result = [] | |
29 prefix = path | |
30 if not prefix.endswith(os.sep): | |
31 prefix += os.sep | |
32 names = os.listdir(path) | |
33 names.sort() | |
34 for fn in names: | |
35 st = os.lstat(prefix + fn) | |
36 if fn == skip and _stat.S_ISDIR(st.st_mode): | |
37 return [] | |
38 if stat: | |
39 result.append((fn, _mode_to_kind(st.st_mode), st)) | |
40 else: | |
41 result.append((fn, _mode_to_kind(st.st_mode))) | |
42 return result |