MCPcopy Create free account
hub / github.com/StackStorm/st2 / _write_data_file

Method _write_data_file

st2api/st2api/controllers/v1/actions.py:511–530  ·  view source on GitHub ↗

Write data file on disk.

(self, pack_ref, file_path, content)

Source from the content-addressed store, hash-verified

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"]

Callers 1

Calls 2

get_pack_base_pathFunction · 0.90
writeMethod · 0.80

Tested by

no test coverage detected