-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use PATH to find tools primarily #257
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
from functools import partial | ||
from ipaddress import IPv4Address | ||
from shutil import which | ||
|
||
try: | ||
from ifupdown2.ifupdown.iface import * | ||
|
@@ -108,6 +109,7 @@ class utils(): | |
systemctl_cmd = '/bin/systemctl' | ||
dpkg_cmd = '/usr/bin/dpkg' | ||
|
||
|
||
logger.info("utils init command paths") | ||
for cmd in ['bridge', | ||
'ip', | ||
|
@@ -125,16 +127,29 @@ class utils(): | |
'systemctl', | ||
'dpkg' | ||
]: | ||
if os.path.exists(vars()[cmd + '_cmd']): | ||
# If we can find utilities in $PATH we take them. | ||
which_cmd = which(cmd) | ||
var_name = cmd + '_cmd' | ||
|
||
logger.setLevel(logging.DEBUG) | ||
if which(cmd): | ||
vars()[var_name] = which_cmd | ||
print('ASDF: %s is set to %s through PATH' % (var_name, which_cmd)) | ||
logger.debug('%s is set to %s through PATH', var_name, which_cmd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though I've set loglevel to debug on line 134 there's no output from line 138. There's output from line 137 which is just a print statement though. |
||
continue | ||
if os.path.exists(vars()[var_name]): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't be called again since the added continue above. |
||
continue | ||
for path in ['/bin/', | ||
'/sbin/', | ||
'/usr/bin/', | ||
'/usr/sbin/',]: | ||
if os.path.exists(path + cmd): | ||
vars()[cmd + '_cmd'] = path + cmd | ||
vars()[var_name] = path + cmd | ||
print('ASDF: %s is set to %s through common bin paths' % (var_name, path + cmd)) | ||
logger.debug('%s is set to %s through common bin paths', var_name, path + cmd) | ||
else: | ||
logger.debug('warning: path %s not found: %s won\'t be usable' % (path + cmd, cmd)) | ||
print('ASDF: warning: path %s not found: %s won\'t be usable' % (path + cmd, cmd)) | ||
logger.debug('warning: path %s not found: %s won\'t be usable', path + cmd, cmd) | ||
|
||
mac_translate_tab = str.maketrans(":.-,", " ") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for testing and discussion