summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index b690d517..3701f42d 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -18,6 +18,7 @@
import yaml
import os
import os.path
+import shutil
import errno
import subprocess
from Cheetah.Template import Template
@@ -127,6 +128,19 @@ def mergedict(src, cand):
src[k] = mergedict(src[k], v)
return src
+def delete_dir_contents(dirname):
+ """
+ Deletes all contents of a directory without deleting the directory itself.
+
+ @param dirname: The directory whose contents should be deleted.
+ """
+ for node in os.listdir(dirname):
+ node_fullpath = os.path.join(dirname, node)
+ if os.path.isdir(node_fullpath):
+ shutil.rmtree(node_fullpath)
+ else:
+ os.unlink(node_fullpath)
+
def write_file(filepath, content, mode=0644, omode="wb"):
"""
Writes a file with the given content and sets the file mode as specified.