diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-06-27 10:12:06 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-07-01 08:49:37 +0100 |
| commit | 58b0a65ada340fda3bc04fa9fcb648eb43246402 (patch) | |
| tree | 982cfef481827b0f46d5bc753730604bb71323d8 /bitbake/lib/bb | |
| parent | c02b7accd54ea657da9d771814b3dc92d0591127 (diff) | |
| download | poky-58b0a65ada340fda3bc04fa9fcb648eb43246402.tar.gz | |
bitbake: utils: Refactor filemode variable conversion to a function
We have other places in the code where we need to take filemode/mask
information from a bitbake variable and turn it into a real python
number. Turn this internal code into public API in bb.utils and
add some tests for it.
(Bitbake rev: d89e30fb2fb15b09f2cb95c4e5aa9f749ca257ea)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb')
| -rw-r--r-- | bitbake/lib/bb/tests/utils.py | 11 | ||||
| -rw-r--r-- | bitbake/lib/bb/utils.py | 17 |
2 files changed, 28 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/utils.py b/bitbake/lib/bb/tests/utils.py index 48e61dfcea..52b7bf85bf 100644 --- a/bitbake/lib/bb/tests/utils.py +++ b/bitbake/lib/bb/tests/utils.py | |||
| @@ -692,3 +692,14 @@ class EnvironmentTests(unittest.TestCase): | |||
| 692 | self.assertIn("A", os.environ) | 692 | self.assertIn("A", os.environ) |
| 693 | self.assertEqual(os.environ["A"], "this is A") | 693 | self.assertEqual(os.environ["A"], "this is A") |
| 694 | self.assertNotIn("B", os.environ) | 694 | self.assertNotIn("B", os.environ) |
| 695 | |||
| 696 | class FilemodeTests(unittest.TestCase): | ||
| 697 | def test_filemode_convert(self): | ||
| 698 | self.assertEqual(0o775, bb.utils.to_filemode("0o775")) | ||
| 699 | self.assertEqual(0o775, bb.utils.to_filemode(0o775)) | ||
| 700 | self.assertEqual(0o775, bb.utils.to_filemode("775")) | ||
| 701 | with self.assertRaises(ValueError): | ||
| 702 | bb.utils.to_filemode("xyz") | ||
| 703 | with self.assertRaises(ValueError): | ||
| 704 | bb.utils.to_filemode("999") | ||
| 705 | |||
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index a2806fd360..1cc74ed546 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
| @@ -1211,6 +1211,23 @@ def which(path, item, direction = 0, history = False, executable=False): | |||
| 1211 | return "", hist | 1211 | return "", hist |
| 1212 | return "" | 1212 | return "" |
| 1213 | 1213 | ||
| 1214 | def to_filemode(input): | ||
| 1215 | """ | ||
| 1216 | Take a bitbake variable contents defining a file mode and return | ||
| 1217 | the proper python representation of the number | ||
| 1218 | |||
| 1219 | Arguments: | ||
| 1220 | |||
| 1221 | - ``input``: a string or number to convert, e.g. a bitbake variable | ||
| 1222 | string, assumed to be an octal representation | ||
| 1223 | |||
| 1224 | Returns the python file mode as a number | ||
| 1225 | """ | ||
| 1226 | # umask might come in as a number or text string.. | ||
| 1227 | if type(input) is int: | ||
| 1228 | return input | ||
| 1229 | return int(input, 8) | ||
| 1230 | |||
| 1214 | @contextmanager | 1231 | @contextmanager |
| 1215 | def umask(new_mask): | 1232 | def umask(new_mask): |
| 1216 | """ | 1233 | """ |
