OILS / pylib / path_stat.py View on Github | oilshell.org

27 lines, 14 significant
1"""
2path_stat.py - Functions from os.path that import 'stat'.
3
4We want to keep bin/osh_parse free of I/O. It's a pure stdin/stdout filter.
5"""
6import posix_ as posix
7import stat
8
9
10def exists(path):
11 # type: (str) -> bool
12 """Test whether a path exists. Returns False for broken symbolic links"""
13 try:
14 posix.stat(path)
15 except posix.error:
16 return False
17 return True
18
19
20def isdir(s):
21 # type: (str) -> bool
22 """Return true if the pathname refers to an existing directory."""
23 try:
24 st = posix.stat(s)
25 except posix.error:
26 return False
27 return stat.S_ISDIR(st.st_mode)