Skip to content

Commit

Permalink
Fix default user (os.getlogin -> getpass.getuser)
Browse files Browse the repository at this point in the history
This is a more reliable way to get the current username. For example,
os.getlogin did not work locally on my Linux Mint machine.

See https://docs.python.org/3/library/getpass.html#getpass.getuser which
says 'In general, this function should be preferred over os.getlogin().'
  • Loading branch information
KvGeijer committed Apr 11, 2024
1 parent d10c267 commit d6aa775
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions resman.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
import time
import getpass

LOG_FILE = "/etc/res_log"
LOCK_FILE = "/etc/res_lock"
Expand Down Expand Up @@ -195,8 +196,8 @@ def main():
parser.add_argument(
"-u",
"--user",
help=f"who is using the server during the reservation? Default is {os.getlogin()}.",
default=os.getlogin(),
help=f"who is using the server during the reservation? Default is {getpass.getuser()}.",
default=getpass.getuser(),
)

args = parser.parse_args()
Expand Down

0 comments on commit d6aa775

Please sign in to comment.