Write data file on disk.
(self, pack_ref, file_path, content)
| 509 | return pack_db |
| 510 | |
| 511 | def _write_data_file(self, pack_ref, file_path, content): |
| 512 | """ |
| 513 | Write data file on disk. |
| 514 | """ |
| 515 | # Throw if pack directory doesn't exist |
| 516 | pack_base_path = get_pack_base_path(pack_name=pack_ref) |
| 517 | if not os.path.isdir(pack_base_path): |
| 518 | raise ValueError('Directory for pack "%s" doesn\'t exist' % (pack_ref)) |
| 519 | |
| 520 | # Create pack sub-directory tree if it doesn't exist |
| 521 | directory = os.path.dirname(file_path) |
| 522 | |
| 523 | if not os.path.isdir(directory): |
| 524 | # NOTE: We apply same permission bits as we do on pack install. If we don't do that, |
| 525 | # st2api won't be able to write to pack sub-directory |
| 526 | mode = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH |
| 527 | os.makedirs(directory, mode) |
| 528 | |
| 529 | with open(file_path, "w") as fp: |
| 530 | fp.write(content) |
| 531 | |
| 532 | def _dispatch_trigger_for_written_data_files(self, action_db, written_data_files): |
| 533 | trigger = ACTION_FILE_WRITTEN_TRIGGER["name"] |
no test coverage detected