diff --git a/swupd/__init__.py b/swupd/__init__.py index af0ce23..a91a91a 100755 --- a/swupd/__init__.py +++ b/swupd/__init__.py @@ -49,6 +49,13 @@ def get_installed_bundles(): return p +def _get_swupd_base_command(command): + """ Return the base part of the command based on the EUID """ + if os.geteuid() != 0: + return ['sudo', 'swupd', command] + return ['swupd', command] + + def install_bundles(bundle_list, F=None, url=None): latest_version = get_latest_version() installed_bundles = get_installed_bundles() @@ -66,7 +73,7 @@ def install_bundles(bundle_list, F=None, url=None): err = "" exit_status = 1 else: - cmd = ['sudo', 'swupd', 'bundle-add'] + cmd = _get_swupd_base_command('bundle-add') if bundle in bundle_universe: cmd += [bundle] if F is not None: @@ -98,7 +105,9 @@ def remove_bundles(bundle_list): err_ = "" for bundle in bundle_list: if(bundle in installed_bundles): - p = subprocess.Popen(['sudo', 'swupd', 'bundle-remove', bundle], + cmd = _get_swupd_base_command('bundle-remove') + cmd.append(bundle) + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) o, e = p.communicate() @@ -117,7 +126,8 @@ def update(): exit_status = 0 out = "" err = "" - p = subprocess.Popen(['sudo', 'swupd', 'update'], + cmd = _get_swupd_base_command('update') + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate()