--- a/configurationengine/source/testautomation/testautomation/utils.py Fri Mar 12 08:30:17 2010 +0200
+++ b/configurationengine/source/testautomation/testautomation/utils.py Tue Aug 10 14:29:28 2010 +0300
@@ -13,6 +13,8 @@
#
# Description:
#
+import os
+import shutil
def hex_to_bindata(hexdata):
hexdata = hexdata.replace(' ', '').replace('\r', '').replace('\n', '').replace('\t', '')
@@ -27,4 +29,18 @@
start = i * 2
end = start + 2
temp.append(chr(int(hexdata[start:end], 16)))
- return ''.join(temp)
\ No newline at end of file
+ return ''.join(temp)
+
+def remove_if_exists(path_or_paths):
+ """Remove files or directories if they exist.
+ @param path_or_paths: The path to remove. Can also be a list of paths."""
+ if isinstance(path_or_paths, list):
+ paths = path_or_paths
+ else:
+ paths = [path_or_paths]
+
+ for path in paths:
+ if os.path.isdir(path):
+ shutil.rmtree(path)
+ elif os.path.isfile(path):
+ os.remove(path)
\ No newline at end of file