diff options
| author | Ross Burton <ross@burtonini.com> | 2020-09-28 17:18:58 +0100 |
|---|---|---|
| committer | Steve Sakoman <steve@sakoman.com> | 2023-12-10 05:55:55 -1000 |
| commit | 658a3832def72d6fd904d89e368b13942b477cbd (patch) | |
| tree | 3d948d69b2c754182fc97a6fe8024f44d43cb306 /bitbake | |
| parent | 0b105ed7c8fd087913454b365a068ec5ed791072 (diff) | |
| download | poky-658a3832def72d6fd904d89e368b13942b477cbd.tar.gz | |
bitbake: utils: add umask changing context manager
Add a umask context manager which can be used to temporarily change the
umask in a 'with' block.
(Bitbake rev: 6ca998054e422da72c7906d3ec4f204d88c32ee0)
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'bitbake')
| -rw-r--r-- | bitbake/lib/bb/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 1a5a0aae6c..34fa0b7a67 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
| @@ -969,6 +969,17 @@ def which(path, item, direction = 0, history = False, executable=False): | |||
| 969 | return "", hist | 969 | return "", hist |
| 970 | return "" | 970 | return "" |
| 971 | 971 | ||
| 972 | @contextmanager | ||
| 973 | def umask(new_mask): | ||
| 974 | """ | ||
| 975 | Context manager to set the umask to a specific mask, and restore it afterwards. | ||
| 976 | """ | ||
| 977 | current_mask = os.umask(new_mask) | ||
| 978 | try: | ||
| 979 | yield | ||
| 980 | finally: | ||
| 981 | os.umask(current_mask) | ||
| 982 | |||
| 972 | def to_boolean(string, default=None): | 983 | def to_boolean(string, default=None): |
| 973 | if not string: | 984 | if not string: |
| 974 | return default | 985 | return default |
