diff utils.py @ 16:c21e96bb68c8

added clean-up after execution
author pieter.lukasse@wur.nl
date Fri, 23 Jan 2015 14:57:55 +0100
parents 8c20185752da
children a394029414c6
line wrap: on
line diff
--- a/utils.py	Fri Jan 23 14:27:04 2015 +0100
+++ b/utils.py	Fri Jan 23 14:57:55 2015 +0100
@@ -6,11 +6,25 @@
 import shutil
 import subprocess
 import csv
+import os
+import stat
 from collections import OrderedDict
     
 def copy_dir(src, dst):
     shutil.copytree(src, dst)
 
+def _del_rw(action, name, exc):
+    '''
+    ensures the read only files are set to read/write 
+    and then deletes them
+    '''
+    os.chmod(name, stat.S_IWRITE)
+    os.remove(name)
+
+def remove_dir(src):
+    shutil.rmtree(src, onerror=_del_rw)
+
+
 def log_message(log_file, log_message):
     with open(log_file, "a") as text_file:
         text_file.write(log_message + "\n")