mirror of
https://github.com/Unidata/python-awips.git
synced 2025-02-23 22:57:56 -05:00
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:
parent
254411e5e7
commit
bb9f7214a8
2 changed files with 26 additions and 6 deletions
|
@ -30,8 +30,16 @@
|
||||||
import struct
|
import struct
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
import pwd
|
try:
|
||||||
import thread
|
import pwd
|
||||||
|
pwd_error = False
|
||||||
|
except ImportError:
|
||||||
|
pwd_error = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
import thread
|
||||||
|
except ImportError:
|
||||||
|
import thread as _thread
|
||||||
|
|
||||||
class WsId(object):
|
class WsId(object):
|
||||||
|
|
||||||
|
@ -42,7 +50,10 @@ class WsId(object):
|
||||||
|
|
||||||
self.userName = userName
|
self.userName = userName
|
||||||
if userName is None:
|
if userName is None:
|
||||||
|
if not pwd_error:
|
||||||
self.userName = pwd.getpwuid(os.getuid()).pw_name
|
self.userName = pwd.getpwuid(os.getuid()).pw_name
|
||||||
|
else:
|
||||||
|
self.userName = "GenericUsername"
|
||||||
|
|
||||||
self.progName = progName
|
self.progName = progName
|
||||||
if progName is None:
|
if progName is None:
|
||||||
|
@ -50,7 +61,7 @@ class WsId(object):
|
||||||
|
|
||||||
self.pid = os.getpid()
|
self.pid = os.getpid()
|
||||||
|
|
||||||
self.threadId = long(thread.get_ident())
|
self.threadId = int(_thread.get_ident())
|
||||||
|
|
||||||
def getNetworkId(self):
|
def getNetworkId(self):
|
||||||
return self.networkId
|
return self.networkId
|
||||||
|
|
|
@ -20,13 +20,22 @@
|
||||||
|
|
||||||
# File auto-generated against equivalent DynamicSerialize Java class
|
# 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):
|
class UserId(object):
|
||||||
|
|
||||||
def __init__(self, id = None):
|
def __init__(self, id = None):
|
||||||
if id is None:
|
if id is None:
|
||||||
|
if not pwd_error:
|
||||||
self.id = pwd.getpwuid(os.getuid()).pw_name
|
self.id = pwd.getpwuid(os.getuid()).pw_name
|
||||||
|
else:
|
||||||
|
self.id = "GenericUsername"
|
||||||
else:
|
else:
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue