diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 506: Replace all usage of shutil.rmtree with a shell call to `rm -rf`

Message ID 20121218210213.14683.32686.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Antonio Terceiro Dec. 18, 2012, 9:02 p.m. UTC
------------------------------------------------------------
revno: 506
fixes bug: https://launchpad.net/bugs/1091811
committer: Antonio Terceiro <antonio.terceiro@linaro.org>
branch nick: reliable-rmtree
timestamp: Tue 2012-12-18 16:50:48 -0300
message:
  Replace all usage of shutil.rmtree with a shell call to `rm -rf`
modified:
  lava_dispatcher/context.py
  lava_dispatcher/device/master.py
  lava_dispatcher/downloader.py
  lava_dispatcher/signals/shellhooks.py
  lava_dispatcher/utils.py


--
lp:lava-dispatcher
https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk

You are subscribed to branch lp:lava-dispatcher.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_dispatcher/context.py'
--- lava_dispatcher/context.py	2012-10-08 22:19:31 +0000
+++ lava_dispatcher/context.py	2012-12-18 19:50:48 +0000
@@ -26,6 +26,7 @@ 
 from lava_dispatcher.config import get_device_config
 from lava_dispatcher.client.targetdevice import TargetBasedClient
 from lava_dispatcher.test_data import LavaTestData
+from lava_dispatcher.utils import rmtree
 
 
 class LavaContext(object):
@@ -53,7 +54,7 @@ 
     def host_result_dir(self):
         if self._host_result_dir is None:
             self._host_result_dir = tempfile.mkdtemp()
-            atexit.register(shutil.rmtree, self._host_result_dir)
+            atexit.register(rmtree, self._host_result_dir)
         return self._host_result_dir
 
     def get_device_version(self):

=== modified file 'lava_dispatcher/device/master.py'
--- lava_dispatcher/device/master.py	2012-12-14 16:37:42 +0000
+++ lava_dispatcher/device/master.py	2012-12-18 19:50:48 +0000
@@ -23,7 +23,6 @@ 
 import contextlib
 import logging
 import os
-import shutil
 import time
 import traceback
 
@@ -52,6 +51,7 @@ 
     logging_system,
     mk_targz,
     string_to_list,
+    rmtree,
 )
 from lava_dispatcher.client.lmc_utils import (
     generate_image,
@@ -291,7 +291,7 @@ 
                 finally:
                     tf = os.path.join(self.scratch_dir, 'fs.tgz')
                     mk_targz(tf, tfdir)
-                    shutil.rmtree(tfdir)
+                    rmtree(tfdir)
 
                     self.proc.sendcontrol('c')  # kill SimpleHTTPServer
 

=== modified file 'lava_dispatcher/downloader.py'
--- lava_dispatcher/downloader.py	2012-11-20 21:25:42 +0000
+++ lava_dispatcher/downloader.py	2012-12-18 19:50:48 +0000
@@ -33,6 +33,7 @@ 
 import zlib
 
 from tempfile import mkdtemp
+from lava_dispatcher.utils import rmtree
 
 
 @contextlib.contextmanager
@@ -145,7 +146,7 @@ 
     if not imgdir:
         imgdir = mkdtemp(dir=context.config.lava_image_tmpdir)
         if delete_on_exit:
-            atexit.register(shutil.rmtree, imgdir)
+            atexit.register(rmtree, imgdir)
 
     url = _url_mapping(url, context)
 

=== modified file 'lava_dispatcher/signals/shellhooks.py'
--- lava_dispatcher/signals/shellhooks.py	2012-12-05 00:24:13 +0000
+++ lava_dispatcher/signals/shellhooks.py	2012-12-18 19:50:48 +0000
@@ -11,7 +11,7 @@ 
     _result_from_dir)
 from lava_dispatcher.signals import SignalHandler
 from lava_dispatcher.test_data import create_attachment
-from lava_dispatcher.utils import mkdtemp
+from lava_dispatcher.utils import mkdtemp, rmtree
 
 class ShellHooks(SignalHandler):
 
@@ -75,7 +75,7 @@ 
             test_result.clear()
             test_result.update(_result_from_dir(result_dir))
         finally:
-            shutil.rmtree(scratch_dir)
+            rmtree(scratch_dir)
         for key in 'start_testcase_output', 'end_testcase_output', \
           'postprocess_test_result_output':
           path = case_data.get(key)

=== modified file 'lava_dispatcher/utils.py'
--- lava_dispatcher/utils.py	2012-12-14 16:37:42 +0000
+++ lava_dispatcher/utils.py	2012-12-18 19:50:48 +0000
@@ -56,13 +56,15 @@ 
         os.makedirs(dir)
     shutil.copy(src, dest)
 
+def rmtree(directory):
+    subprocess.call(['rm', '-rf', directory])
 
 def mkdtemp(basedir='/tmp'):
     """ returns a temporary directory that's deleted when the process exits
     """
 
     d = tempfile.mkdtemp(dir=basedir)
-    atexit.register(shutil.rmtree, d)
+    atexit.register(rmtree, d)
     os.chmod(d, 0755)
     return d
 
@@ -111,7 +113,7 @@ 
     The directory contents if needed.
     """
     if os.path.exists(path):
-        shutil.rmtree(path)
+        rmtree(path)
     os.mkdir(path)