More robust host IP detection when building calibre

This commit is contained in:
Kovid Goyal 2014-06-05 22:18:00 +05:30
parent 4d2ed78698
commit 309668f077

View File

@ -11,7 +11,7 @@ from distutils.spawn import find_executable
from PyQt4 import pyqtconfig from PyQt4 import pyqtconfig
from setup import isosx, iswindows, islinux, is64bit from setup import isosx, iswindows, is64bit
is64bit is64bit
OSX_SDK = '/Developer/SDKs/MacOSX10.5.sdk' OSX_SDK = '/Developer/SDKs/MacOSX10.5.sdk'
@ -189,19 +189,19 @@ def get_ip_address(ifname):
struct.pack('256s', ifname[:15]) struct.pack('256s', ifname[:15])
)[20:24]) )[20:24])
try:
if islinux:
HOST=get_ip_address('eth0')
else:
HOST='192.168.1.2' HOST='192.168.1.2'
except:
try: try:
HOST=get_ip_address('wlan0') import netifaces
except: for iface in netifaces.interfaces():
try: addrs = netifaces.ifaddresses(iface).get(netifaces.AF_INET, [])
HOST=get_ip_address('ppp0') if len(addrs) > 0 and 'addr' in addrs[0]:
except: q = addrs[0]['addr']
HOST='192.168.1.2' if q.startswith('192.168.1.'):
HOST = q
break
except (Exception, ImportError) as e:
print ('Failed to detect host ip address with error: %s' % e)
PROJECT=os.path.basename(os.path.abspath('.')) PROJECT=os.path.basename(os.path.abspath('.'))