diff --git a/devlib/target.py b/devlib/target.py index 7d17fe2..f50ae02 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -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( diff --git a/doc/target.rst b/doc/target.rst index ad641b1..cb51f82 100644 --- a/doc/target.rst +++ b/doc/target.rst @@ -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.