From 0ac464c8461b23f53a54c71da07be75cd00fdc85 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Fri, 30 Mar 2012 10:38:36 +0400 Subject: [PATCH] Fix detect utils without path. Fix using ifconfig. --- pym/cl_utils.py | 2 +- pym/utils/ip.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pym/cl_utils.py b/pym/cl_utils.py index 7ae5015..93580e8 100644 --- a/pym/cl_utils.py +++ b/pym/cl_utils.py @@ -934,7 +934,7 @@ def getProgPath(progname): env = {"LANG":"C"} env.update(os.environ.items() + [("PATH",getpathenv())] +\ env.items()) - res = runOsCommand("which %s"%progname,env_dict=env) + res = runOsCommand("which %s"%baseprogname,env_dict=env) if res[0] == 0: return res[1][0].strip() elif path.isabs(progname) and path.exists(progname): diff --git a/pym/utils/ip.py b/pym/utils/ip.py index 37ba88f..8425cda 100644 --- a/pym/utils/ip.py +++ b/pym/utils/ip.py @@ -84,8 +84,10 @@ def checkMask(mask): def getIpAndMask(interface="eth0"): """Get ip and mask from interface""" - ifconfig = process('/sbin/ifconfig',interface) - res = re.search(r"inet addr:(\S+)\s.*Mask:(\S+)",ifconfig.read(),re.S) + ipconfigProg = checkUtils('/sbin/ifconfig') + ifconfig = process(ipconfigProg,interface) + res = re.search(r"inet(?: addr:| )(\S+)\s.*(?:Mask:|netmask )(\S+)", + ifconfig.read(),re.S) if res: return res.groups() else: @@ -139,7 +141,7 @@ def receiveMac(interface="eth0"): """Get MAC from interface""" ipconfigProg = checkUtils('/sbin/ifconfig') ifconfig = process(ipconfigProg,interface) - res = re.search(r"HWaddr\s(\S+)",ifconfig.read(),re.S) + res = re.search(r"(?:HWaddr|ether)\s(\S+)",ifconfig.read(),re.S) if res: return res.group(1) else: @@ -149,7 +151,8 @@ def receiveIpAndMask(interface="eth0"): """Get ip and mask from interface""" ipconfigProg = checkUtils('/sbin/ifconfig') ifconfig = process(ipconfigProg,interface) - res = re.search(r"inet addr:(\S+)\s.*Mask:(\S+)",ifconfig.read(),re.S) + res = re.search(r"inet(?: addr:| )(\S+)\s.*(?:Mask:|netmask )(\S+)", + ifconfig.read(),re.S) if res: return res.groups() else: