From bb9f7214a87e6956a2e3790d0d8142baf3cf1b20 Mon Sep 17 00:00:00 2001 From: Alex Haberlie Date: Thu, 2 Jun 2016 14:30:21 -0600 Subject: [PATCH] Fixed issues with 'pwd' library on windows machines Python on windows does not have a pwd library. This causes an ImportError when trying to run python-awips on windows machines. All windows connections will instead appear as "GenericUsername" in server logs. --- .../com/raytheon/uf/common/message/WsId.py | 19 +++++++++++++++---- .../uf/common/plugin/nwsauth/user/UserId.py | 13 +++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/dynamicserialize/dstypes/com/raytheon/uf/common/message/WsId.py b/dynamicserialize/dstypes/com/raytheon/uf/common/message/WsId.py index 15930ea..a177e5f 100644 --- a/dynamicserialize/dstypes/com/raytheon/uf/common/message/WsId.py +++ b/dynamicserialize/dstypes/com/raytheon/uf/common/message/WsId.py @@ -30,8 +30,16 @@ import struct import socket import os -import pwd -import thread +try: + import pwd + pwd_error = False +except ImportError: + pwd_error = True + +try: + import thread +except ImportError: + import thread as _thread class WsId(object): @@ -42,7 +50,10 @@ class WsId(object): self.userName = userName if userName is None: - self.userName = pwd.getpwuid(os.getuid()).pw_name + if not pwd_error: + self.userName = pwd.getpwuid(os.getuid()).pw_name + else: + self.userName = "GenericUsername" self.progName = progName if progName is None: @@ -50,7 +61,7 @@ class WsId(object): self.pid = os.getpid() - self.threadId = long(thread.get_ident()) + self.threadId = int(_thread.get_ident()) def getNetworkId(self): return self.networkId diff --git a/dynamicserialize/dstypes/com/raytheon/uf/common/plugin/nwsauth/user/UserId.py b/dynamicserialize/dstypes/com/raytheon/uf/common/plugin/nwsauth/user/UserId.py index 29dcac8..0b02894 100644 --- a/dynamicserialize/dstypes/com/raytheon/uf/common/plugin/nwsauth/user/UserId.py +++ b/dynamicserialize/dstypes/com/raytheon/uf/common/plugin/nwsauth/user/UserId.py @@ -20,13 +20,22 @@ # File auto-generated against equivalent DynamicSerialize Java class -import os, pwd +import os + +try: + import pwd + pwd_error = False +except ImportError: + pwd_error = True class UserId(object): def __init__(self, id = None): if id is None: - self.id = pwd.getpwuid(os.getuid()).pw_name + if not pwd_error: + self.id = pwd.getpwuid(os.getuid()).pw_name + else: + self.id = "GenericUsername" else: self.id = id