1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-30 17:50:46 +00:00

target: Customize as_root parameter of *write_value()

Not all command executions (or write operations in this specific case)
requires being root. So, allow write_value() and dependent
revertable_write_value() to support non-root executions by introducing
'as_root' optional parameter whose default is True to preserve current
behavior of the aforementioned methods.

Meanwhile, update the copyright year of the touched file, too.

Signed-off-by: Metin Kaya <metin.kaya@arm.com>
This commit is contained in:
Metin Kaya 2024-01-11 14:29:54 +00:00 committed by Marc Bonnici
parent 38d8053f2f
commit e334f8816c
2 changed files with 9 additions and 7 deletions

View File

@ -1015,19 +1015,19 @@ class Target(object):
return await self.read_value.asyn(path, kind=boolean)
@asyn.asynccontextmanager
async def revertable_write_value(self, path, value, verify=True):
async def revertable_write_value(self, path, value, verify=True, as_root=True):
orig_value = self.read_value(path)
try:
await self.write_value.asyn(path, value, verify)
await self.write_value.asyn(path, value, verify=verify, as_root=as_root)
yield
finally:
await self.write_value.asyn(path, orig_value, verify)
await self.write_value.asyn(path, orig_value, verify=verify, as_root=as_root)
def batch_revertable_write_value(self, kwargs_list):
return batch_contextmanager(self.revertable_write_value, kwargs_list)
@asyn.asyncf
async def write_value(self, path, value, verify=True):
async def write_value(self, path, value, verify=True, as_root=True):
self.async_manager.track_access(
asyn.PathAccess(namespace='target', path=path, mode='w')
)
@ -1059,7 +1059,7 @@ fi
cmd = cmd.format(busybox=quote(self.busybox), path=quote(path), value=quote(value))
try:
await self.execute.asyn(cmd, check_exit_code=True, as_root=True)
await self.execute.asyn(cmd, check_exit_code=True, as_root=as_root)
except TargetCalledProcessError as e:
if e.returncode == 10:
raise TargetStableError('Could not write "{value}" to {path}: {e.output}'.format(

View File

@ -386,7 +386,7 @@ Target
Equivalent to ``Target.read_value(path, kind=devlib.utils.types.boolean)``
.. method:: Target.write_value(path, value [, verify])
.. method:: Target.write_value(path, value [, verify, as_root])
Write the value to the specified path on the target. This is primarily
intended for sysfs/procfs/debugfs etc.
@ -397,8 +397,10 @@ Target
it is written to make sure it has been written successfully. This due to
some sysfs entries silently failing to set the written value without
returning an error code.
:param as_root: specifies if writing requires being root. Its default value
is ``True``.
.. method:: Target.revertable_write_value(path, value [, verify])
.. method:: Target.revertable_write_value(path, value [, verify, as_root])
Same as :meth:`Target.write_value`, but as a context manager that will write
back the previous value on exit.