From 733ee95aa3a23cc3c19c10f8bd876a24a0578535 Mon Sep 17 00:00:00 2001 From: cemrealpsoy Date: Tue, 9 Aug 2016 15:00:17 +0300 Subject: [PATCH] return values added to install_with_apt_get and uninstall_with_apt_get methods because of method doesnt give any error even if its return code is unsuccessfull for install/uninstall process --- opt/ahenk/base/util/util.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/opt/ahenk/base/util/util.py b/opt/ahenk/base/util/util.py index eb2f9a2..96efda3 100644 --- a/opt/ahenk/base/util/util.py +++ b/opt/ahenk/base/util/util.py @@ -123,7 +123,8 @@ class Util: try: if as_user is not None: command = 'su - {0} -c "{1}"'.format(as_user, command) - process = subprocess.Popen(command, stdin=stdin, env=env, cwd=cwd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=shell) + process = subprocess.Popen(command, stdin=stdin, env=env, cwd=cwd, stderr=subprocess.PIPE, + stdout=subprocess.PIPE, shell=shell) if result is True: result_code = process.wait() @@ -202,27 +203,23 @@ class Util: @staticmethod def install_with_apt_get(package_name, package_version=None): - try: - if package_version is not None: - process = subprocess.Popen('apt-get install --yes --force-yes {0}={1}'.format(package_name, package_version), shell=True) - process.wait() - else: - process = subprocess.Popen('apt-get install --yes --force-yes {0}'.format(package_name), shell=True) - process.wait() - except: - raise + + if package_version is not None: + command = 'apt-get install --yes --force-yes {0}={1}'.format(package_name, package_version) + else: + command = 'apt-get install --yes --force-yes {0}'.format(package_name) + + return Util.execute(command) @staticmethod def uninstall_package(package_name, package_version=None): - try: - if package_version is not None: - process = subprocess.Popen('apt-get purge --yes --force-yes {0}={1}'.format(package_name, package_version), shell=True) - process.wait() - else: - process = subprocess.Popen('apt-get purge --yes --force-yes {0}'.format(package_name), shell=True) - process.wait() - except: - raise + + if package_version is not None: + command = 'apt-get purge --yes --force-yes {0}={1}'.format(package_name, package_version) + else: + command = 'apt-get purge --yes --force-yes {0}'.format(package_name) + + return Util.execute(command) @staticmethod def is_installed(package_name):