##// END OF EJS Templates
pure/osutil: add copyright and license header
Martin Geisler -
r8232:823f25b2 default
parent child Browse files
Show More
@@ -1,42 +1,49 b''
1 # osutil.py - pure Python version of osutil.c
2 #
3 # Copyright 2009 Matt Mackall <mpm@selenic.com> and others
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference.
7
1 8 import os
2 9 import stat as _stat
3 10
4 11 def _mode_to_kind(mode):
5 12 if _stat.S_ISREG(mode): return _stat.S_IFREG
6 13 if _stat.S_ISDIR(mode): return _stat.S_IFDIR
7 14 if _stat.S_ISLNK(mode): return _stat.S_IFLNK
8 15 if _stat.S_ISBLK(mode): return _stat.S_IFBLK
9 16 if _stat.S_ISCHR(mode): return _stat.S_IFCHR
10 17 if _stat.S_ISFIFO(mode): return _stat.S_IFIFO
11 18 if _stat.S_ISSOCK(mode): return _stat.S_IFSOCK
12 19 return mode
13 20
14 21 def listdir(path, stat=False, skip=None):
15 22 '''listdir(path, stat=False) -> list_of_tuples
16 23
17 24 Return a sorted list containing information about the entries
18 25 in the directory.
19 26
20 27 If stat is True, each element is a 3-tuple:
21 28
22 29 (name, type, stat object)
23 30
24 31 Otherwise, each element is a 2-tuple:
25 32
26 33 (name, type)
27 34 '''
28 35 result = []
29 36 prefix = path
30 37 if not prefix.endswith(os.sep):
31 38 prefix += os.sep
32 39 names = os.listdir(path)
33 40 names.sort()
34 41 for fn in names:
35 42 st = os.lstat(prefix + fn)
36 43 if fn == skip and _stat.S_ISDIR(st.st_mode):
37 44 return []
38 45 if stat:
39 46 result.append((fn, _mode_to_kind(st.st_mode), st))
40 47 else:
41 48 result.append((fn, _mode_to_kind(st.st_mode)))
42 49 return result
General Comments 0
You need to be logged in to leave comments. Login now