mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
LocalConnection: Implement connected_as_root
parameter
As of commit 5601fdb1085af2eccf16a84b48c9995699bb8489 the `connected_as_root` status is tracked in the connection. Add missing implementation to `LocalConnection`.
This commit is contained in:
parent
5d4315c5d2
commit
ed135febde
@ -38,9 +38,21 @@ class LocalConnection(object):
|
|||||||
|
|
||||||
name = 'local'
|
name = 'local'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def connected_as_root(self):
|
||||||
|
if self._connected_as_root is None:
|
||||||
|
result = self.execute('id', as_root=False)
|
||||||
|
self._connected_as_root = 'uid=0(' in result
|
||||||
|
return self._connected_as_root
|
||||||
|
|
||||||
|
@connected_as_root.setter
|
||||||
|
def connected_as_root(self, state):
|
||||||
|
self._connected_as_root = state
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def __init__(self, platform=None, keep_password=True, unrooted=False,
|
def __init__(self, platform=None, keep_password=True, unrooted=False,
|
||||||
password=None, timeout=None):
|
password=None, timeout=None):
|
||||||
|
self._connected_as_root = None
|
||||||
self.logger = logging.getLogger('local_connection')
|
self.logger = logging.getLogger('local_connection')
|
||||||
self.keep_password = keep_password
|
self.keep_password = keep_password
|
||||||
self.unrooted = unrooted
|
self.unrooted = unrooted
|
||||||
@ -67,7 +79,7 @@ class LocalConnection(object):
|
|||||||
def execute(self, command, timeout=None, check_exit_code=True,
|
def execute(self, command, timeout=None, check_exit_code=True,
|
||||||
as_root=False, strip_colors=True, will_succeed=False):
|
as_root=False, strip_colors=True, will_succeed=False):
|
||||||
self.logger.debug(command)
|
self.logger.debug(command)
|
||||||
if as_root:
|
if as_root and not self.connected_as_root:
|
||||||
if self.unrooted:
|
if self.unrooted:
|
||||||
raise TargetStableError('unrooted')
|
raise TargetStableError('unrooted')
|
||||||
password = self._get_password()
|
password = self._get_password()
|
||||||
@ -84,7 +96,7 @@ class LocalConnection(object):
|
|||||||
raise TargetStableError(message)
|
raise TargetStableError(message)
|
||||||
|
|
||||||
def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False):
|
def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False):
|
||||||
if as_root:
|
if as_root and not self.connected_as_root:
|
||||||
if self.unrooted:
|
if self.unrooted:
|
||||||
raise TargetStableError('unrooted')
|
raise TargetStableError('unrooted')
|
||||||
password = self._get_password()
|
password = self._get_password()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user