60 else: |
60 else: |
61 # no change |
61 # no change |
62 return name |
62 return name |
63 |
63 |
64 |
64 |
65 def isVisible(name): |
65 def isVisible(name, showHidden): |
66 """ |
66 """ |
67 Function to check, if a filesystem entry is a hidden file or directory. |
67 Function to check, if a filesystem entry is a hidden file or directory. |
68 |
68 |
69 @param name name to be checked |
69 @param name name to be checked |
70 @type str |
70 @type str |
|
71 @param showHidden flag indicating to show hidden files as well |
|
72 @type bool |
71 @return flag indicating a visible filesystem entry |
73 @return flag indicating a visible filesystem entry |
72 @rtype bool |
74 @rtype bool |
73 """ |
75 """ |
74 return not name.startswith(".") and not name.endswith("~") |
76 return ( |
|
77 showHidden or |
|
78 (not name.startswith(".") and not name.endswith("~")) |
|
79 ) |
75 |
80 |
76 |
81 |
77 def fstat(filename): |
82 def fstat(filename): |
78 """ |
83 """ |
79 Function to get the stat() of file. |
84 Function to get the stat() of file. |
88 except Exception: |
93 except Exception: |
89 rstat = os.stat(filename) |
94 rstat = os.stat(filename) |
90 return tuple(rstat) |
95 return tuple(rstat) |
91 |
96 |
92 |
97 |
93 def listdirStat(dirname): |
98 def listdirStat(dirname, showHidden=False): |
94 """ |
99 """ |
95 Function to get a list of directory entries and associated stat() tuples. |
100 Function to get a list of directory entries and associated stat() tuples. |
96 |
101 |
97 @param dirname name of the directory to list |
102 @param dirname name of the directory to list |
98 @type str |
103 @type str |
|
104 @param showHidden flag indicating to show hidden files as well |
|
105 @type bool |
99 @return list of tuples containing the entry name and the associated |
106 @return list of tuples containing the entry name and the associated |
100 stat() tuple |
107 stat() tuple |
101 @rtype list of tuple of (str, tuple) |
108 @rtype list of tuple of (str, tuple) |
102 """ |
109 """ |
103 try: |
110 try: |
107 files = os.listdir() |
114 files = os.listdir() |
108 except OSError: |
115 except OSError: |
109 return [] |
116 return [] |
110 |
117 |
111 if dirname in ('', '/'): |
118 if dirname in ('', '/'): |
112 return [(f, fstat(f)) for f in files if isVisible(f)] |
119 return [(f, fstat(f)) for f in files if isVisible(f, showHidden)] |
113 |
120 |
114 return [(f, fstat(os.path.join(dirname, f))) for f in files |
121 return [(f, fstat(os.path.join(dirname, f))) for f in files |
115 if isVisible(f)] |
122 if isVisible(f, showHidden)] |