Skip to content

Instantly share code, notes, and snippets.

@m87carlson
Last active May 12, 2022 21:56
Show Gist options
  • Save m87carlson/9fec746dd0cbac1c36fd to your computer and use it in GitHub Desktop.
Save m87carlson/9fec746dd0cbac1c36fd to your computer and use it in GitHub Desktop.
user-profiles.py
import os
import sys
import re
import platform
def user_profiles():
"""
local_users grain will list the contents of:
Unix:
/home
Windows:
7:
c:\Users\
XP:
c:\Documents and Settings\
"""
grains = {}
if platform.system() == 'Windows':
if platform.win32_ver()[1].startswith('5'):
profile_path = r'c:\Documents and Settings'
elif platform.win32_ver()[1].startswith('6'):
profile_path = r'c:\Users'
elif platform.system() == ('FreeBSD' or 'Linux'):
profile_path = '/home'
users = os.listdir(profile_path)
grains['user_profiles'] = users
return grains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment