From 72d93a61cf9aff5996952d55e56981eb5a22d989 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Wed, 31 May 2017 18:00:48 +0200 Subject: [refactor] factor out installer function --- src/leap/bitmask/vpn/privilege.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/leap/bitmask/vpn/privilege.py') diff --git a/src/leap/bitmask/vpn/privilege.py b/src/leap/bitmask/vpn/privilege.py index d918a30d..c7cf1199 100644 --- a/src/leap/bitmask/vpn/privilege.py +++ b/src/leap/bitmask/vpn/privilege.py @@ -41,31 +41,27 @@ log = Logger() # TODO wrap the install/uninstall helper functions around the policychecker # classes below. + def install_helpers(): - if IS_LINUX: - cmd = 'bitmask_helpers install' - if STANDALONE: - binary_path = os.path.join(here(), "bitmask") - cmd = "%s %s" % (binary_path, cmd) - if os.getuid() != 0: - cmd = 'pkexec ' + cmd - retcode, _ = commands.getstatusoutput(cmd) - if retcode != 0: - raise Exception('Could not install helpers') - else: - raise Exception('No install mechanism for this platform') + _helper_installer('install') def uninstall_helpers(): + _helper_installer('uninstall') + + +def _helper_installer(action): + if action not in ('install', 'uninstall'): + raise Exception('Wrong action: %s' % action) + if IS_LINUX: - cmd = 'bitmask_helpers uninstall' + cmd = 'bitmask_helpers ' + action if STANDALONE: binary_path = os.path.join(here(), "bitmask") cmd = "%s %s" % (binary_path, cmd) if os.getuid() != 0: cmd = 'pkexec ' + cmd retcode, _ = commands.getstatusoutput(cmd) - commands.getoutput('pkexec ' + cmd) if retcode != 0: raise Exception('Could not uninstall helpers') else: -- cgit v1.2.3