2009-08-11 22:36:37 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
2010-01-14 23:33:06 +00:00
|
|
|
"""cwd.py - function necessary to get the cwd for a given pid on various OSes
|
|
|
|
|
|
|
|
>>> cwd = get_default_cwd()
|
|
|
|
>>> cwd.__class__.__name__
|
|
|
|
'str'
|
|
|
|
|
|
|
|
"""
|
2009-08-11 22:36:37 +00:00
|
|
|
|
|
|
|
import platform
|
|
|
|
import os
|
2009-08-11 22:48:19 +00:00
|
|
|
import pwd
|
2010-07-27 12:03:55 +00:00
|
|
|
from util import dbg, err
|
2009-08-11 22:36:37 +00:00
|
|
|
|
2009-08-11 22:48:19 +00:00
|
|
|
def get_default_cwd():
|
|
|
|
"""Determine a reasonable default cwd"""
|
|
|
|
cwd = os.getcwd()
|
|
|
|
if not os.path.exists(cwd) or not os.path.isdir(cwd):
|
2011-05-03 16:49:00 +00:00
|
|
|
try:
|
|
|
|
cwd = pwd.getpwuid(os.getuid())[5]
|
|
|
|
except KeyError:
|
|
|
|
cwd = '/'
|
2009-08-18 11:59:06 +00:00
|
|
|
|
|
|
|
return(cwd)
|
2009-08-11 22:48:19 +00:00
|
|
|
|
2009-08-11 22:36:37 +00:00
|
|
|
# vim: set expandtab ts=4 sw=4:
|