Mercurial > repos > pieterlukasse > nist_wrapper
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 15:76d6d8a5fa29 | 16:c21e96bb68c8 |
|---|---|
| 4 @author: lukas007 | 4 @author: lukas007 |
| 5 ''' | 5 ''' |
| 6 import shutil | 6 import shutil |
| 7 import subprocess | 7 import subprocess |
| 8 import csv | 8 import csv |
| 9 import os | |
| 10 import stat | |
| 9 from collections import OrderedDict | 11 from collections import OrderedDict |
| 10 | 12 |
| 11 def copy_dir(src, dst): | 13 def copy_dir(src, dst): |
| 12 shutil.copytree(src, dst) | 14 shutil.copytree(src, dst) |
| 15 | |
| 16 def _del_rw(action, name, exc): | |
| 17 ''' | |
| 18 ensures the read only files are set to read/write | |
| 19 and then deletes them | |
| 20 ''' | |
| 21 os.chmod(name, stat.S_IWRITE) | |
| 22 os.remove(name) | |
| 23 | |
| 24 def remove_dir(src): | |
| 25 shutil.rmtree(src, onerror=_del_rw) | |
| 26 | |
| 13 | 27 |
| 14 def log_message(log_file, log_message): | 28 def log_message(log_file, log_message): |
| 15 with open(log_file, "a") as text_file: | 29 with open(log_file, "a") as text_file: |
| 16 text_file.write(log_message + "\n") | 30 text_file.write(log_message + "\n") |
| 17 | 31 |
