Add salt.utils.get_user()

This commit is contained in:
Erik Johnson 2014-04-01 14:13:21 -05:00
parent 1bdb158900
commit 6e2807c5ec

View File

@ -34,6 +34,13 @@ import warnings
import yaml
from calendar import month_abbr as months
# Try to load pwd, fallback to getpass if unsuccessful
try:
import pwd
except ImportError:
import getpass
pwd = None
try:
import timelib
HAS_TIMELIB = True
@ -238,6 +245,16 @@ def get_context(template, line, num_lines=5, marker=None):
return '---\n{0}\n---'.format('\n'.join(buf))
def get_user():
'''
Get the current user
'''
if pwd is not None:
return pwd.getpwuid(os.geteuid()).pw_name
else:
return getpass.getuser()
def daemonize(redirect_out=True):
'''
Daemonize a process