Last active
November 11, 2015 22:31
-
-
Save jgstew/9b0a5d94e19516515c9c to your computer and use it in GitHub Desktop.
A utility function to grab usernames and other identifying info from the current user to be used as potential identification options.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def getLoggedOnUserName(): | |
return os.getenv( "LOGNAME", os.getenv("USERNAME") ) | |
# another UNIX option: pwd.getpwuid(os.getuid())[0] | |
# http://stackoverflow.com/questions/12821946/how-can-i-remove-the-white-characters-from-configuration-file | |
def getStrippedFile(filename): | |
import StringIO | |
return StringIO.StringIO('\n'.join(line.strip() for line in open( filename ))) | |
def getGitUserName(): | |
import ConfigParser | |
config = ConfigParser.ConfigParser() | |
config.readfp( getStrippedFile( os.path.expanduser('~/.gitconfig') ) ) | |
return config.get('user','name') | |
def getConfigUserName( filename ): | |
import ConfigParser | |
config = ConfigParser.ConfigParser() | |
config.readfp( getStrippedFile( filename ) ) | |
return config.get('user','name') | |
def main(): | |
print getLoggedOnUserName() | |
print getGitUserName() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related to: homebysix/recipe-robot#63