[egenix-users] mx packages under mac os x
M.-A. Lemburg
mal at lemburg.com
Wed Jan 8 11:41:44 CET 2003
Dirk Holtwick wrote:
> just for information, the mxBase and parts of the mxExperimental
> packages compile quite good under apples mac os x.
>
> but there's a problem in mxUID, where the package tries to get the
> hostname and ip and this fails if you don't have a connection to the
> net. this should be captured by a try/except clause.
Could you try this code in mx/UID/mxUID/__init__.py:
### Python part of module initialization
# Set IDs
def _init():
global _hostid
import os,string,time
try:
# Try to use the IP address as host id
import socket
try:
ip = socket.gethostbyname(socket.gethostname())
except socket.error:
raise ImportError, 'no network connection'
ip = map(int, string.split(ip, '.'))
_hostid = reduce(lambda x,y: (x+y) % 65536, ip)
except ImportError:
try:
# Use the data from the root stat as host id
_hostid = reduce(lambda x,y: (x+y) % 65536, os.stat(os.sep))
except os.error:
# Fallback to a constant
_hostid = 0x2003
setids(_hostid, os.getpid(), 0xdeadbeef & long(time.time() / 1000))
_init()
This should work in all situations.
BTW, does anyone know how to get at the MAC address of the
network card on the various platforms ?
--
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
_______________________________________________________________________
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting: http://www.egenix.com/
Python Software: http://www.egenix.com/files/python/
More information about the egenix-users
mailing list