1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Avoid duplicate paths in qemu binary list

Fix #204
This commit is contained in:
Julien Duponchelle 2015-06-02 15:35:14 +02:00
parent 887f9b298e
commit a2e51ac090

View File

@ -47,13 +47,13 @@ class Qemu(BaseManager):
"""
qemus = []
paths = []
paths = set()
try:
paths.append(os.getcwd())
paths.add(os.getcwd())
except FileNotFoundError:
log.warning("The current working directory doesn't exist")
if "PATH" in os.environ:
paths.extend(os.environ["PATH"].split(os.pathsep))
paths.update(os.environ["PATH"].split(os.pathsep))
else:
log.warning("The PATH environment variable doesn't exist")
# look for Qemu binaries in the current working directory and $PATH
@ -64,21 +64,21 @@ class Qemu(BaseManager):
exec_dir = os.path.dirname(os.path.abspath(sys.executable))
for f in os.listdir(exec_dir):
if f.lower().startswith("qemu"):
paths.append(os.path.join(exec_dir, f))
paths.add(os.path.join(exec_dir, f))
if "PROGRAMFILES(X86)" in os.environ and os.path.exists(os.environ["PROGRAMFILES(X86)"]):
paths.append(os.path.join(os.environ["PROGRAMFILES(X86)"], "qemu"))
paths.add(os.path.join(os.environ["PROGRAMFILES(X86)"], "qemu"))
if "PROGRAMFILES" in os.environ and os.path.exists(os.environ["PROGRAMFILES"]):
paths.append(os.path.join(os.environ["PROGRAMFILES"], "qemu"))
paths.add(os.path.join(os.environ["PROGRAMFILES"], "qemu"))
elif sys.platform.startswith("darwin"):
# add specific locations on Mac OS X regardless of what's in $PATH
paths.extend(["/usr/local/bin", "/opt/local/bin"])
paths.update(["/usr/local/bin", "/opt/local/bin"])
if hasattr(sys, "frozen"):
try:
paths.append(os.path.abspath(os.path.join(os.getcwd(), "../../../qemu/bin/")))
paths.add(os.path.abspath(os.path.join(os.getcwd(), "../../../qemu/bin/")))
# If the user run the server by hand from outside
except FileNotFoundError:
paths.append(["/Applications/GNS3.app/Contents/Resources/qemu/bin"])
paths.add("/Applications/GNS3.app/Contents/Resources/qemu/bin")
for path in paths:
try:
for f in os.listdir(path):