##// END OF EJS Templates
move mercurial.osutil to mercurial.pure.osutil
Martin Geisler -
r7704:30d1d313 default
parent child Browse files
Show More
@@ -0,0 +1,42 b''
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
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now