mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Add salt.utils.get_user()
This commit is contained in:
parent
1bdb158900
commit
6e2807c5ec
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user