-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support symlink of current unix username to steamuser
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from os import getuid | ||
from pathlib import Path | ||
from pwd import struct_passwd, getpwuid | ||
|
||
|
||
class UnixUser: | ||
"""Represents the User of the system as determined by the password database rather than environment variables or file system paths.""" | ||
|
||
def __init__(self): | ||
"""Immutable properties of the user determined by the password database that's derived from the real user id.""" | ||
uid: int = getuid() | ||
entry: struct_passwd = getpwuid(uid) | ||
# Immutable properties, hence no setters | ||
self.name: str = entry.pw_name | ||
self.puid: str = entry.pw_uid # Should be equivalent to the value from getuid | ||
self.dir: str = entry.pw_dir | ||
self.is_user: bool = self.puid == uid | ||
|
||
def get_home_dir(self) -> Path: | ||
"""User home directory as determined by the password database that's derived from the current process's real user id.""" | ||
return Path(self.dir).as_posix() | ||
|
||
def get_user(self) -> str: | ||
"""User (login name) as determined by the password database that's derived from the current process's real user id.""" | ||
return self.name | ||
|
||
def get_puid(self) -> int: | ||
"""Numerical user ID as determined by the password database that's derived from the current process's real user id.""" | ||
return self.puid | ||
|
||
def is_user(self, uid: int) -> bool: | ||
"""Compare the UID passed in to this instance.""" | ||
return uid == self.puid |