2
# Terminator by Chris Jones <cmsj@tenshu.net>
4
"""cwd.py - function necessary to get the cwd for a given pid on various OSes
6
>>> cwd = get_default_cwd()
7
>>> cwd.__class__.__name__
9
>>> func = get_pid_cwd()
10
>>> func.__class__.__name__
20
def get_default_cwd():
21
"""Determine a reasonable default cwd"""
23
if not os.path.exists(cwd) or not os.path.isdir(cwd):
24
cwd = pwd.getpwuid(os.getuid())[5]
29
"""Determine an appropriate cwd function for the OS we are running on"""
31
func = lambda pid: None
32
system = platform.system()
35
dbg('Using Linux get_pid_cwd')
36
func = lambda pid: os.path.realpath('/proc/%s/cwd' % pid)
37
elif system == 'FreeBSD':
40
func = freebsd.get_process_cwd
41
dbg('Using FreeBSD get_pid_cwd')
42
except (OSError, NotImplementedError, ImportError):
43
dbg('FreeBSD version too old for get_pid_cwd')
44
elif system == 'SunOS':
45
dbg('Using SunOS get_pid_cwd')
46
func = lambda pid: os.path.realpath('/proc/%s/path/cwd' % pid)
48
dbg('Unable to determine a get_pid_cwd for OS: %s' % system)
52
# vim: set expandtab ts=4 sw=4: