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?
Conversation
Benefits are that the PATH is user configureable, and it works across all distributions and packaging mechanisms.
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.
@julienfortin Other than the issues related to logging (which are not really related to this PR) and that there's debug code left in I'd say it's a straight shooter.
if os.path.exists(vars()[cmd + '_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 comment
The 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.
which_cmd = which(cmd) | ||
var_name = cmd + '_cmd' | ||
|
||
logger.setLevel(logging.DEBUG) |
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
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) | ||
continue | ||
if os.path.exists(vars()[var_name]): |
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 won't be called again since the added continue above.
Once I've figured out the logging problem I'll clean the git history force push so we have a clean history in master. |
Why not just making a metaclass for this ? I mean, having handling in the class definition for assigning attributes that should be considereed constants seems odd to me in the first place. here an example: from shutil import which
import os
class __MetaUtil__(type):
def __init__(cls, name, bases, dct):
progs = (
'bridge', 'ip', 'brctl', 'pidof', 'service', 'sysctl',
'modprobe', 'pstree', 'ss', 'vrrpd', 'ifplugd', 'mstpctl',
'ethtool', 'systemctl', 'dpkg'
)
for prog in progs:
path = which(prog)
setattr(cls, f'{prog}_cmd', path or "/bin/false")
class utils(metaclass=__MetaUtil__):
pass |
@sohorx I like this idea, feel free to submit a PR |
This increases flexibility for administrators being able to select their utilities themselves.
This also enables us to package ifupdown2 with Nix, which means we can deploy ifupdown2 very easily on any distribution.
Also fixed some exceptions in log calls related to the utils class.