summaryrefslogtreecommitdiff
path: root/buildscripts/util
diff options
context:
space:
mode:
authorDavid Bradford <david.bradford@mongodb.com>2020-04-02 13:19:48 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-04-06 17:55:12 +0000
commit4d82d10588dbeca498e46d51a36b6efdf8379af1 (patch)
tree683e7c7a1ac54e6049f0152d5ad362e7f83993a5 /buildscripts/util
parent1fa4585c079fe392650258f0654df64d29678af4 (diff)
downloadmongo-4d82d10588dbeca498e46d51a36b6efdf8379af1.tar.gz
SERVER-47274: Refactor task generation in evergreen
Diffstat (limited to 'buildscripts/util')
-rw-r--r--buildscripts/util/fileops.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/buildscripts/util/fileops.py b/buildscripts/util/fileops.py
index e56348d8548..e26e67c6593 100644
--- a/buildscripts/util/fileops.py
+++ b/buildscripts/util/fileops.py
@@ -25,3 +25,30 @@ def get_file_handle(path, append_file=False):
"""Open 'path', truncate it if 'append_file' is False, and return file handle."""
mode = "a+" if append_file else "w"
return open(path, mode)
+
+
+def write_file(path: str, contents: str) -> None:
+ """
+ Write the contents provided to the file in the specified path.
+
+ :param path: Path of file to write.
+ :param contents: Contents to write to file.
+ """
+ with open(path, "w") as file_handle:
+ file_handle.write(contents)
+
+
+def write_file_to_dir(directory: str, file: str, contents: str) -> None:
+ """
+ Write the contents provided to the file in the given directory.
+
+ The directory will be created if it does not exist.
+
+ :param directory: Directory to write to.
+ :param file: Name of file to write.
+ :param contents: Contents to write to file.
+ """
+ if not os.path.exists(directory):
+ os.makedirs(directory)
+
+ write_file(os.path.join(directory, file), contents)