terminator/terminatorlib/cwd.py

35 lines
745 B
Python
Raw Normal View History

2009-08-11 22:36:37 +00:00
# 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'
>>> func = get_pid_cwd()
2020-05-15 16:45:15 +00:00
>>> cwd.__class__.__name__
'str'
2010-01-14 23:33:06 +00:00
"""
2009-08-11 22:36:37 +00:00
import platform
import os
import pwd
2020-05-15 15:27:36 +00:00
import psutil
from .util import dbg, err
2009-08-11 22:36:37 +00:00
def get_default_cwd():
"""Determine a reasonable default cwd"""
try:
cwd = os.getcwd()
except (FileNotFoundError,OSError):
err("unable to set current working directory, does not exist")
cwd = '/'
return(cwd)
def get_pid_cwd():
"""Determine the cwd of the current process"""
2020-05-15 15:27:36 +00:00
return psutil.Process().as_dict()['cwd']
2009-08-11 22:36:37 +00:00
# vim: set expandtab ts=4 sw=4: