From d158c8ad7a1a3211a69b78ed261e6034557c9a01 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Tue, 26 Mar 2024 13:49:56 +0100 Subject: [PATCH] Windows: Fix 'pwd' import. --- src/tools.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/tools.py b/src/tools.py index ae8da822..b8a4c0b3 100644 --- a/src/tools.py +++ b/src/tools.py @@ -17,7 +17,6 @@ # -*- coding: utf-8 -*- import os -import pwd import time import logging import traceback @@ -33,6 +32,13 @@ from functools import ( reduce, partial, wraps ) +try: + import pwd + with_pwd = True +except Exception as e: + print("Module 'pwd' is not available") + with_pwd = False + ########### # LOGGING # ########### @@ -273,7 +279,7 @@ def timestamp_to_old_pamhyr_date(time: int): def get_user_name(): - if posix: + if with_pwd: return pwd.getpwuid(os.getuid()).pw_gecos else: return "Me" -- GitLab