Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions resources/lib/version_check/shell_handler_apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


try:
from subprocess import check_output
from subprocess import check_output, CalledProcessError
except ImportError:
def check_output(*args, **kwargs):
return
Expand Down Expand Up @@ -86,8 +86,12 @@ def _update_cache(self):
_cmd = 'apt-get update'
try:
if self.sudo:
_ = check_output('echo \'%s\' | sudo -S %s' %
(self._get_password(), _cmd), shell=True)
try:
_ = check_output('sudo -n %s' %
(_cmd), shell=True)
except CalledProcessError:
_ = check_output('echo \'%s\' | sudo -S %s' %
(self._get_password(), _cmd), shell=True)
else:
_ = check_output(_cmd.split())
except Exception as error: # pylint: disable=broad-except
Expand All @@ -107,8 +111,12 @@ def upgrade_package(self, package):
_cmd = 'apt-get install -y ' + package
try:
if self.sudo:
_ = check_output('echo \'%s\' | sudo -S %s' %
(self._get_password(), _cmd), shell=True)
try:
_ = check_output('sudo -n %s' %
(_cmd), shell=True)
except CalledProcessError:
_ = check_output('echo \'%s\' | sudo -S %s' %
(self._get_password(), _cmd), shell=True)
else:
_ = check_output(_cmd.split())
log('Upgrade successful')
Expand All @@ -128,8 +136,12 @@ def upgrade_system(self):
try:
log('Upgrading system')
if self.sudo:
_ = check_output('echo \'%s\' | sudo -S %s' %
(self._get_password(), _cmd), shell=True)
try:
_ = check_output('sudo -n %s' %
(_cmd), shell=True)
except CalledProcessError:
_ = check_output('echo \'%s\' | sudo -S %s' %
(self._get_password(), _cmd), shell=True)
else:
_ = check_output(_cmd.split())
except Exception as error: # pylint: disable=broad-except
Expand Down