Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Lillecarl
Copy link

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.

Carl Hjerpe added 3 commits April 5, 2023 18:33
Benefits are that the PATH is user configureable, and it works across
all distributions and packaging mechanisms.
ifupdown2/ifupdown/utils.py Outdated Show resolved Hide resolved
Copy link
Author

@Lillecarl Lillecarl left a 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)
Copy link
Author

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)
Copy link
Author

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]):
Copy link
Author

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.

@Lillecarl
Copy link
Author

Once I've figured out the logging problem I'll clean the git history force push so we have a clean history in master.

@sohorx
Copy link
Contributor

sohorx commented Apr 28, 2023

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

@julienfortin
Copy link
Contributor

@sohorx I like this idea, feel free to submit a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants