未验证 提交 75e5dce6 编写于 作者: O openharmony_ci 提交者: Gitee

!141 修复mac os上无法识别设备的bug

Merge pull request !141 from liguangjie/master
......@@ -101,7 +101,7 @@ def is_proc_running(pid, name=None):
proc = subprocess.Popen(["C:\\Windows\\System32\\findstr", "%s" % pid],
stdin=proc_sub.stdout,
stdout=subprocess.PIPE, shell=False)
else:
elif platform.system() == "Linux":
# /bin/ps -ef | /bin/grep -v grep | /bin/grep -w pid
proc_sub = subprocess.Popen(["/bin/ps", "-ef"],
stdout=subprocess.PIPE,
......@@ -113,6 +113,20 @@ def is_proc_running(pid, name=None):
proc = subprocess.Popen(["/bin/grep", "-w", "%s" % pid],
stdin=proc_v_sub.stdout,
stdout=subprocess.PIPE, shell=False)
elif platform.system() == "Darwin":
# /bin/ps -ef | /bin/grep -v grep | /bin/grep -w pid
proc_sub = subprocess.Popen(["/bin/ps", "-ef"],
stdout=subprocess.PIPE,
shell=False)
proc_v_sub = subprocess.Popen(["/usr/bin/grep", "-v", "grep"],
stdin=proc_sub.stdout,
stdout=subprocess.PIPE,
shell=False)
proc = subprocess.Popen(["/usr/bin/grep", "-w", "%s" % pid],
stdin=proc_v_sub.stdout,
stdout=subprocess.PIPE, shell=False)
else:
raise Exception("Unknown system environment.")
(out, _) = proc.communicate()
out = get_decode(out).strip()
LOG.debug("check %s proc running output: %s", pid, out)
......
......@@ -30,9 +30,9 @@ python -c "import sys; exit(1) if sys.version_info.major < 3 or sys.version_info
goto:eof
)
python -c "import easy_install"
python -c "import pip"
@if errorlevel 1 (
@echo "Please install setuptools first!"
@echo "Please install pip first!"
goto:eof
)
......@@ -42,13 +42,13 @@ if not exist %TOOLS% (
)
for %%a in (%TOOLS%/*.egg) do (
python -m easy_install --user %TOOLS%/%%a
python -m pip install --user %TOOLS%/%%a
@if errorlevel 1 (
@echo "Error occurs to install %%a!"
)
)
for %%a in (%TOOLS%/*.tar.gz) do (
python -m easy_install --user %TOOLS%/%%a
python -m pip install --user %TOOLS%/%%a
@if errorlevel 1 (
@echo "Error occurs to install %%a!"
)
......
......@@ -32,7 +32,7 @@ fi
$PYTHON -c 'import sys; exit(1) if sys.version_info.major < 3 or sys.version_info.minor < 7 else exit(0)' || \
error "Python3.7 or higher version required!"
cd $(dirname "$0") || error "Failure to change directory!"
$PYTHON -c "import easy_install" || error "Please install setuptools first!"
$PYTHON -c "import pip" || error "Please install pip first!"
if [ ! -d "$TOOLS" ]; then
error "$TOOLS directory not exists"
......@@ -43,7 +43,7 @@ do
if [ ! -e "$f" ]; then
error "Can not find xdevice package!"
fi
$PYTHON -m easy_install --user "$f" || echo "Error occurs to install $f!"
$PYTHON -m pip install --user "$f" || echo "Error occurs to install $f!"
done
for f in "$TOOLS"/*.tar.gz
......@@ -51,7 +51,7 @@ do
if [ ! -e "$f" ]; then
error "Can not find xdevice package!"
fi
$PYTHON -m easy_install --user "$f" || echo "Error occurs to install $f!"
$PYTHON -m pip install --user "$f" || echo "Error occurs to install $f!"
done
$PYTHON -m xdevice "$@"
......
......@@ -117,6 +117,9 @@ def is_proc_running(pid, name=None):
if platform.system() == "Windows":
list_command = ["C:\\Windows\\System32\\tasklist"]
find_command = ["C:\\Windows\\System32\\findstr", "%s" % pid]
elif platform.system() == "Darwin":
list_command = ["/bin/ps", "-ef"]
find_command = ["/usr/bin/grep", "%s" % pid]
else:
list_command = ["/bin/ps", "-ef"]
find_command = ["/bin/grep", "%s" % pid]
......@@ -537,37 +540,41 @@ def check_path_legal(path):
def get_local_ip():
sys_type = platform.system()
if sys_type == "Windows":
_list = socket.gethostbyname_ex(socket.gethostname())
_list = _list[2]
for ip_add in _list:
if ip_add.startswith("10."):
return ip_add
return socket.gethostbyname(socket.getfqdn(socket.gethostname()))
elif sys_type == "Darwin":
hostname = socket.getfqdn(socket.gethostname())
return socket.gethostbyname(hostname)
elif sys_type == "Linux":
real_ip = "/%s/%s" % ("hostip", "realip")
if os.path.exists(real_ip):
srw = None
try:
import codecs
srw = codecs.open(real_ip, "r", "utf-8")
lines = srw.readlines()
local_ip = str(lines[0]).strip()
except (IOError, ValueError) as error_message:
LOG.error(error_message)
try:
sys_type = platform.system()
if sys_type == "Windows":
_list = socket.gethostbyname_ex(socket.gethostname())
_list = _list[2]
for ip_add in _list:
if ip_add.startswith("10."):
return ip_add
return socket.gethostbyname(socket.getfqdn(socket.gethostname()))
elif sys_type == "Darwin":
hostname = socket.getfqdn(socket.gethostname())
return socket.gethostbyname(hostname)
elif sys_type == "Linux":
real_ip = "/%s/%s" % ("hostip", "realip")
if os.path.exists(real_ip):
srw = None
try:
import codecs
srw = codecs.open(real_ip, "r", "utf-8")
lines = srw.readlines()
local_ip = str(lines[0]).strip()
except (IOError, ValueError) as error_message:
LOG.error(error_message)
local_ip = "127.0.0.1"
finally:
if srw is not None:
srw.close()
else:
local_ip = "127.0.0.1"
finally:
if srw is not None:
srw.close()
return local_ip
else:
local_ip = "127.0.0.1"
return local_ip
else:
return "127.0.0.1"
except Exception as error:
LOG.debug("Get local ip error: %s, skip!" % error)
return "127.0.0.1"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册