Write bytes data to a file.
(self, path, data, *, _mode=0o666)
| 974 | return self.set_data(bytecode_path, data, _mode=mode) |
| 975 | |
| 976 | def set_data(self, path, data, *, _mode=0o666): |
| 977 | """Write bytes data to a file.""" |
| 978 | parent, filename = _path_split(path) |
| 979 | path_parts = [] |
| 980 | # Figure out what directories are missing. |
| 981 | while parent and not _path_isdir(parent): |
| 982 | parent, part = _path_split(parent) |
| 983 | path_parts.append(part) |
| 984 | # Create needed directories. |
| 985 | for part in reversed(path_parts): |
| 986 | parent = _path_join(parent, part) |
| 987 | try: |
| 988 | _os.mkdir(parent) |
| 989 | except FileExistsError: |
| 990 | # Probably another Python process already created the dir. |
| 991 | continue |
| 992 | except OSError as exc: |
| 993 | # Could be a permission error, read-only filesystem: just forget |
| 994 | # about writing the data. |
| 995 | _bootstrap._verbose_message('could not create {!r}: {!r}', |
| 996 | parent, exc) |
| 997 | return |
| 998 | try: |
| 999 | _write_atomic(path, data, _mode) |
| 1000 | _bootstrap._verbose_message('created {!r}', path) |
| 1001 | except OSError as exc: |
| 1002 | # Same as above: just don't write the bytecode. |
| 1003 | _bootstrap._verbose_message('could not create {!r}: {!r}', path, |
| 1004 | exc) |
| 1005 | |
| 1006 | |
| 1007 | class SourcelessFileLoader(FileLoader, _LoaderBasics): |
no test coverage detected