From a6a1859029a95f7cce616070a165a481a83c72bc Mon Sep 17 00:00:00 2001 From: David Sauve Date: Wed, 5 Aug 2009 16:44:12 -0400 Subject: [PATCH] Minor tweak to cleanup. Using shutil instead of iterating file objects --- tests/xapian_backend.py | 10 +++------- xapian_backend.py | 6 ++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tests/xapian_backend.py b/tests/xapian_backend.py index 79484c5..f5cb9d0 100644 --- a/tests/xapian_backend.py +++ b/tests/xapian_backend.py @@ -17,6 +17,7 @@ import cPickle as pickle import datetime import os +import shutil import xapian from django.conf import settings @@ -70,13 +71,8 @@ class XapianSearchBackendTestCase(TestCase): def tearDown(self): if os.path.exists(settings.HAYSTACK_XAPIAN_PATH): - index_files = os.listdir(settings.HAYSTACK_XAPIAN_PATH) - - for index_file in index_files: - os.remove(os.path.join(settings.HAYSTACK_XAPIAN_PATH, index_file)) - - os.removedirs(settings.HAYSTACK_XAPIAN_PATH) - + shutil.rmtree(settings.HAYSTACK_XAPIAN_PATH) + settings.HAYSTACK_XAPIAN_PATH = self.old_xapian_path super(XapianSearchBackendTestCase, self).tearDown() diff --git a/xapian_backend.py b/xapian_backend.py index 549c89f..89d805a 100644 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -18,6 +18,7 @@ import datetime import cPickle as pickle import os import re +import shutil import warnings from django.conf import settings @@ -350,10 +351,7 @@ class SearchBackend(BaseSearchBackend): This removes all indexes files and the `HAYSTACK_XAPIAN_PATH` folder. """ if os.path.exists(settings.HAYSTACK_XAPIAN_PATH): - index_files = os.listdir(settings.HAYSTACK_XAPIAN_PATH) - for index_file in index_files: - os.remove(os.path.join(settings.HAYSTACK_XAPIAN_PATH, index_file)) - os.removedirs(settings.HAYSTACK_XAPIAN_PATH) + shutil.rmtree(settings.HAYSTACK_XAPIAN_PATH) def document_count(self): """