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.
This commit is contained in:
Alex Haberlie 2016-06-02 14:30:21 -06:00
parent 254411e5e7
commit bb9f7214a8
2 changed files with 26 additions and 6 deletions

View file

@ -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

View file

@ -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