Write bytes data to a file.
(self, path, data, *, _mode=0o666)
| 946 | return self.set_data(bytecode_path, data, _mode=mode) |
| 947 | |
| 948 | def set_data(self, path, data, *, _mode=0o666): |
| 949 | """Write bytes data to a file.""" |
| 950 | parent, filename = _path_split(path) |
| 951 | path_parts = [] |
| 952 | # Figure out what directories are missing. |
| 953 | while parent and not _path_isdir(parent): |
| 954 | parent, part = _path_split(parent) |
| 955 | path_parts.append(part) |
| 956 | # Create needed directories. |
| 957 | for part in reversed(path_parts): |
| 958 | parent = _path_join(parent, part) |
| 959 | try: |
| 960 | _os.mkdir(parent) |
| 961 | except FileExistsError: |
| 962 | # Probably another Python process already created the dir. |
| 963 | continue |
| 964 | except OSError as exc: |
| 965 | # Could be a permission error, read-only filesystem: just forget |
| 966 | # about writing the data. |
| 967 | _bootstrap._verbose_message('could not create {!r}: {!r}', |
| 968 | parent, exc) |
| 969 | return |
| 970 | try: |
| 971 | _write_atomic(path, data, _mode) |
| 972 | _bootstrap._verbose_message('created {!r}', path) |
| 973 | except OSError as exc: |
| 974 | # Same as above: just don't write the bytecode. |
| 975 | _bootstrap._verbose_message('could not create {!r}: {!r}', path, |
| 976 | exc) |
| 977 | |
| 978 | |
| 979 | class SourcelessFileLoader(FileLoader, _LoaderBasics): |
no test coverage detected