forked from ungleich-public/cdist
use os.path.realpath instead, because it eliminates any symbolic links encountered in the path
This commit is contained in:
parent
54d83a6211
commit
d20fb74324
1 changed files with 7 additions and 7 deletions
14
bin/cdist
14
bin/cdist
|
@ -25,16 +25,16 @@ import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# try to import cdist and if that fails, then add this file's parent dir to
|
# try to import cdist and if that fails,
|
||||||
# module search path and try again. additionally check if this file is
|
# then add this file's parent dir to
|
||||||
# symlinked, so user can symlink this file to, for example, ~/.local/bin.
|
# module search path and try again.
|
||||||
try:
|
try:
|
||||||
import cdist
|
import cdist
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
cdist_bin = __file__
|
cdist_dir = os.path.realpath(
|
||||||
if os.path.islink(cdist_bin):
|
os.path.join(
|
||||||
cdist_bin = os.readlink(cdist_bin)
|
os.path.dirname(os.path.realpath(__file__)),
|
||||||
cdist_dir = os.path.abspath(os.path.join(os.path.dirname(cdist_bin), os.pardir))
|
os.pardir))
|
||||||
sys.path.insert(0, cdist_dir)
|
sys.path.insert(0, cdist_dir)
|
||||||
import cdist
|
import cdist
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue